#include "zxLogInstance.h" #include "ZxBaHelper.h" #include "ZxResolutionHelper.h" #include "zxSysUtils.h" #include "ZxPtyDock.h" #include "iDockBaseWx.h" #include "ZxMainWindow.h" #include "ZxSubAxisX.h" #include "ZxSubAxisY.h" #include "ZxPlot.h" #include "ZxObjCurve.h" #include "ZxSubTitle.h" #include "tCurvePlotScene.h" #include "tCurvePlotView.h" #include "ZxTableView.h" #include "ZxTableModel.h" #include "mModuleDefines.h" #include "ZxDataWell.h" #include "ZxDataProject.h" #include "ZxRstJobWnd.h" #ifdef QT_DEBUG #include "ZxDataGaugeP.h" #endif #ifdef QT_DEBUG #include "nmXmlHelper.h" #endif #include "nmGuiPlot.h" #include "nmWxParaProperty.h" #include "nmSubWndDemo.h" #include "nmDataLogFile.h" nmSubWndDemo::nmSubWndDemo(QWidget *parent, QString sExt) : iSubWndBaseAF(parent, sExt) { m_pWxPlot = NULL; m_pWxDockParas = NULL; m_pWxParas = NULL; m_pWxDockData1 = NULL; m_pTableView1 = NULL; m_pWxDockData2 = NULL; m_pTableView2 = NULL; #ifdef QT_DEBUG m_pWxDockTemp = NULL; m_pListWxTemp = NULL; #endif // 为了后续支持多井提供方便 if (m_pDataWell == NULL) { m_pDataWell = zxCurWell; } m_sMdiWndType = s_MdiType_DataNum; setWindowTitle(tr("nmSubWndDemo")); } nmSubWndDemo::~nmSubWndDemo() { #ifdef QT_DEBUG // 坚持谁创建谁析构原则,删除(首先需要去除绑定) if (NULL != m_pWxDockTemp) { //QObject* pParent = m_pWxDockTemp->parent(); //ZxMainWindow* p = dynamic_cast(pParent); ZxMainWindow* p = m_pMainWindow; if (NULL != p) { p->detachOuterDockWx(m_pWxDockTemp); } delete m_pWxDockTemp; m_pWxDockTemp = NULL; } #endif } void nmSubWndDemo::configWnd() { iSubWndBaseAF::configWnd(); if (NULL != m_pMainWindow) { disconnect(this, SIGNAL(sigAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea)), \ m_pMainWindow, SLOT(slotAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea))); connect(this, SIGNAL(sigAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea)), \ m_pMainWindow, SLOT(slotAppendDock2Main(iDockBaseWx*, Qt::DockWidgetArea))); } initUI(); } void nmSubWndDemo::initUI() { // iSubWndBaseAF::initUI(); #ifdef QT_DEBUG // 示例:演示增加Dock并且追加至程序主窗口 initUiTop(); #endif // 主布局:定义 initUiMain(); // 外围布局,DockWx { initUiDockWxs(); initUiDockPtys(); } #ifdef QT_DEBUG // 示例:如何加载xml文件 if (_nmXmlHelper->loadXmlDefines()) { foreach (nmXmlData* pData, *(_nmXmlHelper->getVecNmXmlDataPtrs())) { Q_ASSERT (NULL != pData); zxLogRunD(QString("%1: %2").arg(pData->m_sName).arg(pData->m_sAlias)); } } #endif } QWidget* nmSubWndDemo::initUiMainWx() { QSplitter* pSplitter = new QSplitter(Qt::Vertical); Q_ASSERT (NULL != pSplitter); nmGuiPlot* pWxPlot = new nmGuiPlot(); m_pWxPlot = pWxPlot; { // 建立信号,以便在此处增加新的工具 connect(pWxPlot, SIGNAL(sigToolbarBuilt(QToolBar*)), this, SLOT(slotToolbarBuilt(QToolBar*))); QSize sz = QSize(265, 203); pWxPlot->initUI("TestGui", sz); bindChartSignals(pWxPlot); pSplitter->addWidget(pWxPlot); } return pSplitter; } void nmSubWndDemo::initUiDockWxs() { // TODO,本Dock的操作 // 基础参数Dock // { // m_pWxDockParas = new iDockBaseWx(tr("Parameters")); // Q_ASSERT (NULL != m_pWxDockParas); // addDockWidget(Qt::LeftDockWidgetArea, m_pWxDockParas); // m_pWxParas = new nmWxParaProperty(); // Q_ASSERT (NULL != m_pWxParas); // m_pWxParas->initUI(); // m_pWxDockParas->setWidget(m_pWxParas); // m_pWxDockParas->setMinimumWidth(_resoSizeW(200)); // } // 表格数据Dock { QStringList listTitles; listTitles << tr("Name1"); iDockBaseWx* pDockWx1 = new iDockBaseWx(tr("Data1")); Q_ASSERT (NULL != pDockWx1); { addDockWidget(Qt::RightDockWidgetArea, pDockWx1); m_pWxDockData1 = pDockWx1; ZxTableView* pTableView = new ZxTableView(); Q_ASSERT (NULL != pTableView); { ZxTableModel* pTableModel = new ZxTableModel(1, 1, listTitles); Q_ASSERT (NULL != pTableModel); pTableView->setModel(pTableModel); pTableView->setMenuMode(ZxTableView::MTM_Edit_Without_Col); pTableView->setSelectionBehavior(ZxTableView::SelectRows); pTableView->fuzzyUiOfQt5(); } pDockWx1->setWidget(pTableView); m_pTableView1 = pTableView; } iDockBaseWx* pDockWx2 = new iDockBaseWx(tr("Data2")); Q_ASSERT (NULL != pDockWx2); { addDockWidget(Qt::RightDockWidgetArea, pDockWx2); tabifyDockWidget(pDockWx1, pDockWx2); m_pWxDockData2 = pDockWx2; ZxTableView* pTableView = new ZxTableView(); Q_ASSERT (NULL != pTableView); { ZxTableModel* pTableModel = new ZxTableModel(1, 1, listTitles); Q_ASSERT (NULL != pTableModel); pTableView->setModel(pTableModel); pTableView->setMenuMode(ZxTableView::MTM_Readonly); pTableView->fuzzyUiOfQt5(); } pDockWx2->setWidget(pTableView); m_pTableView2 = pTableView; } } } void nmSubWndDemo::initUiDockPtys() { iSubWndBaseAF::initUiDockPtys(); // 属性Dock { Q_ASSERT (NULL != m_pDockPty); m_pDockPty->setMinimumWidth(_resoSizeW(200)); } } #ifdef QT_DEBUG // 示例:演示增加Dock并且追加至程序主窗口 void nmSubWndDemo::initUiTop() { // TODO,不创建新的Dock return; // 基础参数Dock { iDockBaseWx* pDockWx = new iDockBaseWx(tr("TODO:Demo")); Q_ASSERT (NULL != pDockWx); QListWidget* pListWx = new QListWidget(); Q_ASSERT (NULL != pListWx); pDockWx->setWidget(pListWx); m_pListWxTemp = pListWx; pDockWx->setMinimumWidth(_resoSizeW(200)); emit sigAppendDock2Main(pDockWx, Qt::LeftDockWidgetArea); m_pWxDockTemp = pDockWx; } } #endif void nmSubWndDemo::bindChartSignals(iGuiPlot* pWxPlot) { nmGuiPlot* p = dynamic_cast(pWxPlot); if (NULL != p) { connect(p, SIGNAL(sigObjSelChanged(ZxObjBase*, bool)), \ this, SLOT(slotObjSelChanged(ZxObjBase*, bool))); connect(p, SIGNAL(sigObjPtsChanged(ZxObjBase*)), this, SLOT(slotObjPtsChanged(ZxObjBase*))); } iSubWndBaseAF::bindChartSignals(pWxPlot); } bool nmSubWndDemo::runActionOf(QString sAction) { if (iSubWnd::runActionOf(sAction)) { return true; } // 数据加载 QString s = sAction; if (_isSame(s, "LoadP")) { return true; } return false; } bool nmSubWndDemo::runCmdBy(QString sName, QString sID) { QString s = sName; // 地质图导入 if (sID.toInt() == 5302) { this->geologicalMapImport(); return true; } if (_isSame(s, "RunGrid")) { if (NULL != m_pWxPlot) { //m_pWxPlot->refreshGrid(true); } return true; } return false; } bool nmSubWndDemo::checkCmdEnable(bool &b, \ QString sName, int nID, \ bool bLicensed) { bool b1 = (NULL != zxCurProject); bool b2 = (NULL != m_pDataWell); if (nID == 5102 || (nID >= 5301 && nID <= 5311)) { //RunGrid b = (b1 && b2 && bLicensed && !isReadonly() && NULL != m_pWxPlot); return true; } return iSubWndBaseAF::checkCmdEnable(b, sName, nID, bLicensed); } void nmSubWndDemo::reAdjustToolbar(QToolBar* pToolBar) { iSubWndBaseAF::reAdjustToolbar(pToolBar); } void nmSubWndDemo::firstLoadAndUpdate() { iSubWndBaseAF::firstLoadAndUpdate(); } void nmSubWndDemo::finalDeals() { iSubWndBaseAF::finalDeals(); #ifdef QT_DEBUG updatePlots(); updateDockWxs(); if (m_pWxDockData1 != NULL) { Q_ASSERT (NULL != m_pWxDockData1); m_pWxDockData1->raise(); } #endif } void nmSubWndDemo::onActivated() { #ifdef QT_DEBUG // TODO,主程序的Dock操作 // 获取所有 Dock 视图 QList dockWidgets = m_pMainWindow->findChildren(); // TODO,遍历所有 Dock 视图并移除位于左侧的 foreach (QDockWidget* dock, dockWidgets) { dock->hide(); } // 当前窗体激活时,可以做些事情,比如把隐藏的Dock显示出来 if (NULL != m_pWxDockTemp) { if (!m_pWxDockTemp->isVisible()) { m_pWxDockTemp->setVisible(true); } } #endif } #ifdef QT_DEBUG void nmSubWndDemo::updatePlots() { // 说明:以从当前井获取一条压力数据进行绘图为例 QString sType = iDataModelType::sTypeDataGaugeP; QString sCodeP = ""; //如果已知压力数据Code,可以直接引用 ZxDataGaugeP* pDataObjP = dynamic_cast(getDataObjOf(sType, sCodeP)); if (NULL == pDataObjP) { zxLogRunW(tr("Failed to get data of type '%1'").arg(sType)); return; } VecFloat vecX, vecY; QByteArray ba = pDataObjP->getGaugeDataOf(0); if (!ZxBaHelper::convertBa2VecXY(vecX, vecY, ba)) { zxLogRunW(tr("Failed to get x-y data of dataobj '%1'").arg(pDataObjP->getCode())); return; } nmGuiPlot* pWxPlot = m_pWxPlot; Q_ASSERT (NULL != pWxPlot); QString sName = tr("CurveName"); ZxObjBase* pObj = pWxPlot->updatePlotObjBy(sName, vecX, vecY, true); if (NULL != pObj) { pObj->setLockPos(true); //可以调整属性 // pObj->setReadOnly(true); pWxPlot->freshAxisScales(true);//刷新坐标轴刻度 // 设置标题+坐标轴等 pWxPlot->setAxisX(tr("Time"), "hr"); pWxPlot->setAxisY(tr("Pressure"), "MPa"); pWxPlot->setAxisXYLog(false, 0); pWxPlot->setAxisXYLog(false, 1); pWxPlot->m_pPlot->setLegendVisible(false); pWxPlot->m_pPlot->getTitle()->setName(tr("Demo")); } } ZxDataObject* nmSubWndDemo::getDataObjOf(QString sType, QString sCode /*= ""*/) { ZxDataWell* pDataWell = zxCurWell; Q_ASSERT (NULL != pDataWell); ZxDataObject* pDataObj = NULL; if (!sCode.isEmpty()) { pDataObj = pDataWell->getChild(sType, sCode); } else { ZxDataObjectList vecObjs = pDataWell->getChildren(sType); if (!vecObjs.isEmpty()) { pDataObj = vecObjs[0]; } } return pDataObj; } void nmSubWndDemo::updateDockWxs() { // TODO,刷新Dock内容 return; // 左侧参数窗体 Q_ASSERT (NULL != m_pWxParas); QStringList listParas; listParas << "K" << "S" << "rw" << "Miuo" << "Bo" << "phi"; m_pWxParas->refreshUIs(listParas); // 表格数据1 Q_ASSERT (NULL != m_pTableView1); ZxTableModel* pTableModel = m_pTableView1->getModel(); Q_ASSERT (NULL != pTableModel); QStringList listTitles; listTitles << tr("Col1") << tr("Col2\n(MPa)"); VVecDouble vvec; { VecDouble vec; vec << 0.2 << 3.4; vvec << vec; } { VecDouble vec; vec << 5.6 << 0.456; vvec << vec; } pTableModel->setTitles(listTitles); pTableModel->setData(vvec); if (NULL != m_pListWxTemp) { m_pListWxTemp->clear(); for (int i = 0; i < 10; i++) { QString sItem = tr("Demo Item %1").arg(i + 1); QListWidgetItem* pItem = new QListWidgetItem(sItem); Q_ASSERT (NULL != pItem); pItem->setIcon(zxLoadIcon("Open")); m_pListWxTemp->addItem(pItem); } } } void nmSubWndDemo::updateTableByCurve(ZxObjCurve* pObjCurve, ZxTableView* pTableView) { Q_ASSERT (NULL != pObjCurve); Q_ASSERT (NULL != pTableView); // 刷新表格标题 { QString sNameX = pObjCurve->getAxisX()->getName(); QString sUnit = pObjCurve->getAxisX()->getUnit(); if (!sUnit.isEmpty()) { sNameX += QString("\n(%1)").arg(sUnit); } QString sNameY = pObjCurve->getAxisY()->getName(); sUnit = pObjCurve->getAxisY()->getUnit(); if (!sUnit.isEmpty()) { sNameY += QString("\n(%1)").arg(sUnit); } QStringList listTitles; listTitles << sNameX << sNameY; pTableView->getModel()->setTitles(listTitles); } // 刷新表格数据 { VVecDouble vvec; QVector vecValues = pObjCurve->getAllValues(); for (int i = 0; i < vecValues.count(); i++) { VecDouble vec; vec << vecValues.at(i).x() * 1.0; vec << vecValues.at(i).y() * 1.0; vvec << vec; } pTableView->getModel()->setData(vvec); } } #endif void nmSubWndDemo::slotObjSelChanged(ZxObjBase* p, bool b) { #ifdef QT_DEBUG // 如果选中了一条曲线,则把其数据显示在数据表格2中 ZxObjCurve* pObjCurve = dynamic_cast(p); if (NULL != pObjCurve && b) { Q_ASSERT (NULL != m_pWxDockData2); m_pWxDockData2->raise(); updateTableByCurve(pObjCurve, m_pTableView2); } #endif } void nmSubWndDemo::slotObjPtsChanged(ZxObjBase* p) { } void nmSubWndDemo::onSerialize(ZxSerializer* ser) { iSubWndBaseAF::onSerialize(ser); if (NULL != m_pWxPlot) { m_pWxPlot->setModified(false); } } void nmSubWndDemo::onDeserialize(ZxSerializer* ser) { iSubWndBaseAF::onDeserialize(ser); if (NULL != m_pWxPlot) { m_pWxPlot->setModified(false); } } void nmSubWndDemo::onDeserialized() { if (NULL != m_pWxPlot) { m_pWxPlot->resetAfterDeserialized(); } } bool nmSubWndDemo::loadRss() { ZxRstJobWnd* pRstWnd = getRstJobWnd(); Q_ASSERT (NULL != pRstWnd); // 基础信息 { QByteArray v = pRstWnd->getDataInfo(); IxSerDes* pSerObj = this; if (!loadRstInfoFromArr(v, pSerObj)) { return false; } } // 图形 if (NULL != m_pWxPlot) { QByteArray v = pRstWnd->getDataInfo1(); ZxPlot* pPlot = NULL; loadOnePlot(pPlot, v); if (NULL != pPlot) { m_pWxPlot->m_pPlotScene->freshToPlot(pPlot, m_pWxPlot->m_pPlotView); m_pWxPlot->m_pPlot = m_pWxPlot->m_pPlotScene->m_pPlot; pPlot->resetTools(m_pWxPlot->m_pPlotView); m_pWxPlot->resetAfterDeserialized(); } m_pWxPlot->runUpdate(); } return true; } bool nmSubWndDemo::saveRss() { ZxRstJobWnd* pRstWnd = getRstJobWnd(); if (NULL == pRstWnd) { return false; } // 基础信息 { QByteArray v; IxSerDes* pSerObj = this; if (!saveRstInfoToArr(v, pSerObj)) { return false; } pRstWnd->setDataInfo(v); } // 图形 if (NULL != m_pWxPlot) { ZxPlot* pPlot = m_pWxPlot->m_pPlot; { QByteArray v1; if (saveOnePlot(pPlot, v1)) { pRstWnd->setDataInfo1(v1); } } } return pRstWnd->save(); } bool nmSubWndDemo::slotSaveAll() { ZxRstJobWnd* pRstWnd = getRstJobWnd(); Q_ASSERT (NULL != pRstWnd); return saveRss(); } // 地质图导入 void nmSubWndDemo::geologicalMapImport() { // 打开图片选择弹框 // 打开文件对话框选择图片文件 QString filePath = QFileDialog::getOpenFileName(nullptr, "选择图片文件", "", "Images (*.png *.xpm *.jpg)"); if (!filePath.isEmpty()) { // 加载图片 QPixmap pixmap(filePath); // if (!pixmap.isNull()) { // // 创建标签并显示图片 // QLabel label; // label.setPixmap(pixmap); // label.show(); // } m_pWxPlot->setBackgroundImg(pixmap); nmDataLogFile::getInstance()->writeLog(filePath); } } bool nmSubWndDemo::onConfirmClosing() { return iSubWndBaseAF::onConfirmClosing(); }