|
|
|
|
//#include <QMenu>
|
|
|
|
|
//#include <QFileDialog>
|
|
|
|
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
#include "zxLogInstance.h"
|
|
|
|
|
|
|
|
|
|
#include "ZxPaintParam.h"
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
|
|
#include "ZxSubAxisY.h"
|
|
|
|
|
|
|
|
|
|
#include "nmPlotScene.h"
|
|
|
|
|
#include "nmPlotView.h"
|
|
|
|
|
|
|
|
|
|
ZX_DEFINE_DYNAMIC(mPlotView, nmPlotView)
|
|
|
|
|
|
|
|
|
|
nmPlotView::nmPlotView()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmPlotView::onPrepareContextMenu(QMenu* pMenu,
|
|
|
|
|
const QPointF& pos)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
nmPlotScene* pScene = dynamic_cast<nmPlotScene*>(getScene());
|
|
|
|
|
if (NULL != pScene && NULL != pScene->m_pPlot)
|
|
|
|
|
{
|
|
|
|
|
ZxPlot* pPlot = pScene->m_pPlot;
|
|
|
|
|
pPlot->onPrepareContextMenu(pMenu, pos);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QAction* pAction = pMenu->addAction(zxLoadIcon("Undo"), tr("Undo"));
|
|
|
|
|
connect(pAction, SIGNAL(triggered()), this, SLOT(slotUndo()));
|
|
|
|
|
pAction->setEnabled(pPlot->canUndo());
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
QAction* pAction = pMenu->addAction(zxLoadIcon("Redo"), tr("Redo"));
|
|
|
|
|
connect(pAction, SIGNAL(triggered()), this, SLOT(slotRedo()));
|
|
|
|
|
pAction->setEnabled(pPlot->canRedo());
|
|
|
|
|
}
|
|
|
|
|
pMenu->addSeparator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pMenu->addSeparator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__super::onPrepareContextMenu(pMenu, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 拖拽支持
|
|
|
|
|
void nmPlotView::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
|
{
|
|
|
|
|
m_bDraging = false;
|
|
|
|
|
emit sigCheckDragAccepted(event, m_bDraging);
|
|
|
|
|
if (m_bDraging)
|
|
|
|
|
{
|
|
|
|
|
event->accept();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmPlotView::dropEvent(QDropEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (m_bDraging)
|
|
|
|
|
{
|
|
|
|
|
m_bDraging = false;
|
|
|
|
|
emit sigDealwithDrop(event);
|
|
|
|
|
event->accept();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void nmPlotView::mouseMoveEvent(QMouseEvent* e)
|
|
|
|
|
{
|
|
|
|
|
ZxRenderView::mouseMoveEvent(e);
|
|
|
|
|
|
|
|
|
|
nmPlotScene* pScene = dynamic_cast<nmPlotScene*>(ZxRenderView::getScene());
|
|
|
|
|
if (NULL == pScene || NULL == pScene->m_pPlot)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF pos = mapToScene(QPoint(e->x(), e->y()));
|
|
|
|
|
|
|
|
|
|
ZxTempLayer* pTempLayer = pScene->getTempLayer();
|
|
|
|
|
if (NULL != pTempLayer)
|
|
|
|
|
{
|
|
|
|
|
// 范围
|
|
|
|
|
QRectF rt = pScene->m_pPlot->getInnerRectF();
|
|
|
|
|
pTempLayer->setCrossLineRect(rt);
|
|
|
|
|
|
|
|
|
|
// 位置
|
|
|
|
|
pTempLayer->setCrossLinePos(pos);
|
|
|
|
|
|
|
|
|
|
// 文字
|
|
|
|
|
{
|
|
|
|
|
ZxSubAxisBase* pX = dynamic_cast<ZxSubAxisBase*>(pScene->m_pPlot->getMainAxisX());
|
|
|
|
|
ZxSubAxisBase* pY = dynamic_cast<ZxSubAxisBase*>(pScene->m_pPlot->getMainAxisY());
|
|
|
|
|
ZxSubAxisBase* pY2 = pScene->m_pPlot->getSysAxisY(AP_Right);
|
|
|
|
|
if (NULL != pY2) //加入双Y轴的考虑
|
|
|
|
|
{
|
|
|
|
|
if (!pY2->isVisible() || pY2->isMinimizeAxis() || pY2 == pY)
|
|
|
|
|
pY2 = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float fX = pX->getValueForPos(pos.x());
|
|
|
|
|
float fY = pY->getValueForPos(pos.y());
|
|
|
|
|
|
|
|
|
|
QString sValueX = ZxBaseUtil::getValidStr(fX, 3);
|
|
|
|
|
QString sValueY = ZxBaseUtil::getValidStr(fY, 3);
|
|
|
|
|
|
|
|
|
|
QString sValueY2 = "";
|
|
|
|
|
if (NULL != pY2)//加入双Y轴的考虑
|
|
|
|
|
{
|
|
|
|
|
float fY2 = pY2->getValueForPos(pos.y());
|
|
|
|
|
sValueY2 = ZxBaseUtil::getValidStr(fY2, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString sTipsEx = "";
|
|
|
|
|
emit sigGetTipsExOfPos(sTipsEx, fX, fY); //此处不考虑双Y轴,TODO
|
|
|
|
|
|
|
|
|
|
// tips
|
|
|
|
|
QString s = QString("%1:%2 %3").arg(pX->getName()).arg(sValueX).arg(pX->getUnit());
|
|
|
|
|
s += ";";
|
|
|
|
|
if (!sTipsEx.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QPen pen = QPen(QColor(128, 128, 128));
|
|
|
|
|
pTempLayer->setCrossLinePen(pen);
|
|
|
|
|
pen.setWidthF(.1f);
|
|
|
|
|
s += sTipsEx;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pTempLayer->setCrossLinePen(QPen(QColor(192, 192, 192)));
|
|
|
|
|
s += QString("%1:%2 %3").arg(pY->getName()).arg(sValueY).arg(pY->getUnit());
|
|
|
|
|
|
|
|
|
|
if (!sValueY2.isEmpty() && NULL != pY2)
|
|
|
|
|
s += QString(";%1:%2 %3").arg(pY2->getName()).arg(sValueY2).arg(pY2->getUnit());
|
|
|
|
|
}
|
|
|
|
|
pTempLayer->setTips(s);
|
|
|
|
|
|
|
|
|
|
// 状态栏
|
|
|
|
|
if (rt.contains(pos))
|
|
|
|
|
{
|
|
|
|
|
s = tr(" Current Pos:%1-%2").arg(sValueX).arg(sValueY);
|
|
|
|
|
if (!sValueY2.isEmpty())
|
|
|
|
|
s += QString("-%1").arg(sValueY2);
|
|
|
|
|
if (!sTipsEx.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
s += " ";
|
|
|
|
|
s += sTipsEx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s = "";
|
|
|
|
|
}
|
|
|
|
|
emit sigFresh2Status(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmPlotView::focusOutEvent(QFocusEvent *e)
|
|
|
|
|
{
|
|
|
|
|
ZxRenderView::focusOutEvent(e);
|
|
|
|
|
|
|
|
|
|
nmPlotScene* pScene = dynamic_cast<nmPlotScene*>(ZxRenderView::getScene());
|
|
|
|
|
if (NULL != pScene)
|
|
|
|
|
{
|
|
|
|
|
ZxTempLayer* pTempLayer = pScene->getTempLayer();
|
|
|
|
|
if (NULL != pTempLayer)
|
|
|
|
|
{
|
|
|
|
|
pTempLayer->clearLineAndTips();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmPlotView::leaveEvent(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
ZxRenderView::leaveEvent(e);
|
|
|
|
|
|
|
|
|
|
nmPlotScene* pScene = dynamic_cast<nmPlotScene*>(ZxRenderView::getScene());
|
|
|
|
|
if (NULL != pScene)
|
|
|
|
|
{
|
|
|
|
|
ZxTempLayer* pTempLayer = pScene->getTempLayer();
|
|
|
|
|
if (NULL != pTempLayer)
|
|
|
|
|
{
|
|
|
|
|
pTempLayer->clearLineAndTips();
|
|
|
|
|
// return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString s = "";
|
|
|
|
|
emit sigFresh2Status(s);
|
|
|
|
|
}
|