#include "ZxBaseUtil.h" #include "zxLogInstance.h" #include "ZxSubAxisX.h" #include "ZxSubAxisY.h" #include "ZxSubTitle.h" #include "ZxPlot.h" #include "ZxObjCurve.h" #include "tCurvePlotScene.h" #include "tCurvePlotView.h" #include "nmObjPoint.h" #include "nmObjLine.h" #include "nmObjPolygon.h" #include "nmGuiPlotCmdHelper.h" #include "nmGuiPlot.h" nmGuiPlot::nmGuiPlot(bool bUseBtns, QWidget *parent) : iGuiPlot(bUseBtns, parent) { m_bUseBtns = bUseBtns; if (NULL != m_pCmdHelper) { delete m_pCmdHelper; m_pCmdHelper = NULL; } m_pCmdHelper = new nmGuiPlotCmdHelper(this); Q_ASSERT (NULL != m_pCmdHelper); m_sChartCmdType = "NmDemo2DType"; setWindowTitle(tr("nmGuiPlot")); } nmGuiPlot::~nmGuiPlot() { } void nmGuiPlot::initUI(QString sTitle, QSize szDefault /*= QSize(265, 203)*/) { iGuiPlot::initUI(sTitle, szDefault); } void nmGuiPlot::initSheets() { // iGuiPlot::initSheets(); } void nmGuiPlot::initMainLayout() { iGuiPlot::initMainLayout(); } QWidget* nmGuiPlot::initChartLayout(QString sTitle, QSize szDefault) { return iGuiPlot::initChartLayout(sTitle, szDefault); } void nmGuiPlot::runUpdate() { // iGuiPlot::updatePlots(); if (NULL != m_pPlot) { } } bool nmGuiPlot::runAction(QString sAction) { Q_ASSERT (NULL != m_pCmdHelper); return m_pCmdHelper->runAction(sAction); } nmObjBase* nmGuiPlot::appendOneObj(NM_Obj_Type o, QString& sName, QVector& vec) { nmObjBase* pObj = _createOneObj(o, sName); if (NULL == pObj) { return NULL; } pObj->setAllPos(vec); pObj->select(true); pObj->dealSelChanged(true); // pObj->update(); // emit sigObjCompleted(p); setModified(true); return pObj; } nmObjBase* nmGuiPlot::_createOneObj(NM_Obj_Type o, QString& sName) { Q_ASSERT (NULL != m_pPlot); // 确保名称不重复 QStringList listOlds; for (int i = 0; i < m_pPlot->getObjCount(); i++) { listOlds << m_pPlot->getObjByIndex(i)->getName(); } sName = ZxBaseUtil::getNextOneName(listOlds, sName); // 创建,此处代码为了简洁,作了非规范性书写 nmObjBase* pObj = NULL; if (o == NOT_Point) pObj = new nmObjPoint(sName, NULL, NULL); else if (o == NOT_Line) pObj = new nmObjLine(sName, NULL, NULL); else if (o == NOT_Polygon) pObj = new nmObjPolygon(sName, NULL, NULL); else { zxLogRunW(tr("Type '%1' not supported.").arg((int)o)); return NULL; } Q_ASSERT (NULL != pObj); bindObjSignals(pObj); m_pPlot->addOneObj(pObj); return pObj; } void nmGuiPlot::bindObjSignals(ZxObjBase* pObj) { Q_ASSERT (NULL != pObj); disconnect(pObj, SIGNAL(sigObjSelectionChanged(bool)), \ this, SLOT(slotObjSelChanged(bool))); disconnect(pObj, SIGNAL(sigPtsChanged()), \ this, SLOT(slotObjPtsChanged())); connect(pObj, SIGNAL(sigObjSelectionChanged(bool)), \ this, SLOT(slotObjSelChanged(bool))); connect(pObj, SIGNAL(sigPtsChanged()), \ this, SLOT(slotObjPtsChanged())); } // Obj选择状态改变 void nmGuiPlot::slotObjSelChanged(bool b) { ZxObjBase* p = dynamic_cast(sender()); if (NULL != p) { emit sigObjSelChanged(p, b); } } // Obj数据发生了改变 void nmGuiPlot::slotObjPtsChanged() { ZxObjBase* p = dynamic_cast(sender()); if (NULL != p) { emit sigObjPtsChanged(p); } } void nmGuiPlot::onSerialize(ZxSerializer* ser) { iGuiPlot::onSerialize(ser); } void nmGuiPlot::onDeserialize(ZxSerializer* ser) { iGuiPlot::onDeserialize(ser); } void nmGuiPlot::resetAfterDeserialized() { iGuiPlot::resetAfterDeserialized(); if (NULL == m_pPlot) { return; } connectSignals(); slotChangeSizeWithChangedXY(); setModified(false); for (int i = 0; i < m_pPlot->getObjCount(); i++) { nmObjBase* pObj = (nmObjBase*)m_pPlot->getObjByIndex(i); if (NULL != pObj) { // 建立信号 bindObjSignals(pObj); } } } void nmGuiPlot::paintEvent(QPaintEvent* e) { iGuiPlot::paintEvent(e); } #ifdef QT_DEBUG ZxObjBase* nmGuiPlot::updatePlotObjBy(QString sName, \ VecFloat& vecX, VecFloat& vecY, \ bool bPressureLike /*= true*/, \ bool bUseY2 /*= false*/, \ bool bClearAll /*= false*/) { if (vecX.count() < 2 || vecX.count() != vecY.count()) { return NULL; } ZxPlot* pPlot = m_pPlot; Q_ASSERT (NULL != pPlot); // 移除先前图上已经有的曲线 int n = pPlot->getObjCount(); for (int i = n - 1; i >= 0; i--) { ZxObjBase* pObj = pPlot->getObjByIndex(i); if (NULL == pObj) { continue; } if (bClearAll) { pPlot->removeObjByIndex(i); } else if (_isSame(sName, pObj->getName())) { pPlot->removeObjByIndex(i); break; } } ZxObjCurve* pObj = NULL; if (bPressureLike) { pObj = appendSeriesP(vecX, vecY, sName, bUseY2); } else { pObj = appendSeriesF(vecX, vecY, sName, bUseY2); } if (NULL != pObj) { setPenAndDot(pObj, !bPressureLike); bindObjSignals(pObj); } return pObj; } #endif