#include "ZxBaseUtil.h" #include "zxLogInstance.h" #include "ZxSubAxisX.h" #include "ZxSubAxisY.h" #include "ZxSubTitle.h" #include "ZxPlot.h" #include "ZxObjCurve.h" #include "nmPlotScene.h" #include "nmPlotView.h" #include "nmObjPoint.h" #include "nmObjLine.h" #include "nmObjPolygon.h" #include "nmObjPolygonOutline.h" #include "nmObjLineCrack.h" #include "nmObjLineFault.h" #include "nmObjPointWell.h" #include "nmGuiPlotCmdHelper.h" #include "nmGuiPlot.h" #include "nmDataLogFile.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::initChartView(QString sTitle, QSize szDefault) { // iGuiPlot::initChartView(sTitle, szDefault); m_pPlotView = new nmPlotView(); Q_ASSERT (NULL != m_pPlotView); m_pPlotScene = new nmPlotScene(); Q_ASSERT (NULL != m_pPlotScene); m_pPlotView->setScene(m_pPlotScene); m_pPlotScene->init(m_pPlotView, sTitle, szDefault); //m_pPlotView->setSimpleMode(true); m_pPlot = m_pPlotScene->m_pPlot; m_pPlotView->setMargins(0, 0, 0, 0); m_pPlotView->setZoomMode(ZxRenderView::eZoomFitWindow, true); connectSignals(); } void nmGuiPlot::connectSignals() { iGuiPlot::connectSignals(); // your owns if (NULL != m_pPlot) { // disconnect(m_pPlot, SIGNAL(sigUpdate()), \ // m_pPlotView->viewport(), SLOT(update())); // connect(m_pPlot, SIGNAL(sigUpdate()), \ // m_pPlotView->viewport(), SLOT(update())); } } 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); nmDataLogFile::getInstance()->writeLog(sName + " ------ " + QString::number(o)); // 创建,此处代码为了简洁,作了非规范性书写 nmObjBase* pObj = NULL; if (o == NOT_Point) { pObj = new nmObjPoint(sName, NULL, NULL); } else if (o == NOT_Point_Well) { pObj = new nmObjPointWell(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 if (o == NOT_PolygonOutline) { pObj = new nmObjPolygonOutline(sName, NULL, NULL); } else if (o == NOT_Line_Crack) { pObj = new nmObjLineCrack(sName, NULL, NULL); } else if (o == NOT_Line_Fault) { pObj = new nmObjLineFault(sName, NULL, NULL); } else { zxLogRunW(tr("Type '%1' not supported.").arg((int)o)); nmDataLogFile::getInstance()->writeLog(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