diff --git a/Include/nmNum/nmSubWnd/nmSubWndMain.h b/Include/nmNum/nmSubWnd/nmSubWndMain.h index 36f26593..4c106ff2 100644 --- a/Include/nmNum/nmSubWnd/nmSubWndMain.h +++ b/Include/nmNum/nmSubWnd/nmSubWndMain.h @@ -203,6 +203,8 @@ class NM_SUB_WND_EXPORT nmSubWndMain : public iSubWndBaseFit { void onGenerateButtonClicked(); void onDialogCmdDestroyed(QObject*); + // 测量动作触发时,为当前地图打开结果窗口。 + void showMeasureDialog(); private: // 更新添加的井(从之前创建的井中选择) @@ -250,26 +252,21 @@ class NM_SUB_WND_EXPORT nmSubWndMain : public iSubWndBaseFit { void generateDFN(); // Show void displaySetting(); - // 测量 - void drawMeasure(); // Geo模型 void drawGeoRef(); // 模型位置 void drawPointerPos(); - // 显示测量对话框 - QWidget* showMeasureDialog(); // 显示模型位置对话框 QWidget* showPointerPosDialog(); // 显示属性插值对话框 QWidget* showPropertyInterpolationDialog(); void bindDialogCmdDestroyed(QWidget* dialog, int nId); - void bindMeasureDialog(QWidget* measureDlg); bool isDialogCmdOpened(int nId) const; void markDialogCmdOpened(int nId); void markDialogCmdClosed(int nId); - // 从菜单点击绘制,除非ToolBar上的点击 - void triggerToolBarAction(int index); + // 顶部菜单按命令名触发地图工具栏上的对应动作。 + void triggerToolBarAction(const char* command); // 合并数据到流量端分析窗口 bool mergeAnaResultToFitting(); // 填充已经存在的数值三维和结果参数页面。 @@ -372,6 +369,5 @@ private: QListWidget* m_pListWxTemp; #endif - // QDSZ - QToolBar* m_pPlotToolBar; + QToolBar* m_pPlotToolBar; ///< 当前地图的右侧工具栏,由地图管理。 }; diff --git a/Src/nmNum/nmSubWnd/nmSubWndMain.cpp b/Src/nmNum/nmSubWnd/nmSubWndMain.cpp index 203480b2..e4b5259c 100644 --- a/Src/nmNum/nmSubWnd/nmSubWndMain.cpp +++ b/Src/nmNum/nmSubWnd/nmSubWndMain.cpp @@ -76,6 +76,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -806,10 +809,7 @@ bool nmSubWndMain::runCmdBy(QString sName, QString sID) return true; */ case 5129: - if(isDialogCmdOpened(5129)) { - return true; - } - this->drawMeasure(); + this->triggerToolBarAction("nmInsertObjLineMeasure"); return true; case 5127: @@ -899,15 +899,83 @@ void nmSubWndMain::reAdjustToolbar(QToolBar* pToolBar) { iSubWndBaseAF::reAdjustToolbar(pToolBar); m_pPlotToolBar = pToolBar; - // 获取所有动作的列表 - // QList actions = m_pPlotToolBar->actions(); - // // 隐藏第1个和第2个动作 - // if (actions.size() > 0) { - // actions[0]->setVisible(false); // 隐藏第1个动作 - // } - // if (actions.size() > 1) { - // actions[1]->setVisible(false); // 隐藏第2个动作 - // } + if (pToolBar == nullptr) return; + + // 每行是一组,顺序对应右侧工具栏从上到下的排列。 + const QStringList groups = QStringList() + // 选择与编辑 + << QLatin1String("Select nmDeleteOneObj Undo Redo") + // 绘制,三种边界放在一起 + << QLatin1String("nmInsertObjLineCrack nmInsertObjLineFault nmInsertObjRegion nmInsertRegionMark " + "nmInsertObjPolygonOutline nmInsertObjRectOutline nmInsertObjRoundOutline") + // 测量与标定 + << QLatin1String("nmInsertObjLineMeasure nmInsertObjLineMeasuringScale") + // 视图 + << QLatin1String("ZoomRectIn ZoomRectInV ZoomRectInH ZoomIn ZoomOut ZoomReset " + "ShowCrossLine ShowValue ShowProperty RefreshGraph") + // 输出与帮助 + << QLatin1String("Print print_Preview SaveAsImg Help"); + + QList separators; + QHash actionsByCommand; + foreach (QAction* action, pToolBar->actions()) { + if (action->isSeparator()) { + separators.append(action); + continue; + } + + const QString command = action->objectName(); + // 样例图元和插入井不在数值试井地图工具栏上显示。 + if (command == QLatin1String("nmInsertObjPoint") || + command == QLatin1String("nmInsertObjPointWell") || + command == QLatin1String("nmInsertObjLine") || + command == QLatin1String("nmInsertObjPolygon") || + command == QLatin1String("nmInsertObjRect") || + command == QLatin1String("nmInsertObjRound")) { + action->setVisible(false); + } else { + actionsByCommand.insert(command, action); + } + } + + // 顶部菜单复用同一个动作,两个入口共用测量窗口。 + if (QAction* measureAction = actionsByCommand.value(QLatin1String("nmInsertObjLineMeasure"))) { + connect(measureAction, SIGNAL(triggered(bool)), this, SLOT(showMeasureDialog()), + Qt::UniqueConnection); + } + + QList orderedActions; + foreach (const QString& group, groups) { + QList groupActions; + foreach (const QString& command, group.split(QLatin1Char(' '))) { + if (QAction* action = actionsByCommand.value(command)) { + groupActions.append(action); + } + } + + if (groupActions.isEmpty()) continue; + if (!orderedActions.isEmpty()) { + orderedActions.append(separators.isEmpty() ? pToolBar->addSeparator() + : separators.takeFirst()); + } + orderedActions += groupActions; + } + + if (orderedActions.isEmpty()) return; + foreach (QAction* separator, separators) { + pToolBar->removeAction(separator); + } + if (pToolBar->actions().mid(0, orderedActions.size()) == orderedActions) return; + + // 从后往前将原动作移到最前,未分组的动作留在末尾并保持相对顺序。 + QAction* firstAction = pToolBar->actions().first(); + for (int i = orderedActions.size() - 1; i >= 0; --i) { + QAction* action = orderedActions.at(i); + if (action != firstAction) { + pToolBar->insertAction(firstAction, action); + firstAction = action; + } + } } void nmSubWndMain::firstLoadAndUpdate() @@ -1417,7 +1485,7 @@ void nmSubWndMain::geologicalMapImport() void nmSubWndMain::drawMeasuringScale() { - this->triggerToolBarAction(NMOT_Line_MeasuringScale); + this->triggerToolBarAction("nmInsertObjLineMeasuringScale"); } void nmSubWndMain::geologicalMapHide() @@ -1441,31 +1509,22 @@ void nmSubWndMain::setTopDocksVisible(bool visible) void nmSubWndMain::drawPolygonOutline() { - // 获取多边形边界的绘制,并模拟触发点击操作 - // 目前多边形边界绘制是工具栏的第4个,所以用 3 - // QList actions = m_pPlotToolBar->actions(); - // if (!actions.isEmpty()) { - // QAction *action = actions[3]; - // action->trigger(); - // } - this->triggerToolBarAction(NMOT_PolygonOutline); + this->triggerToolBarAction("nmInsertObjPolygonOutline"); } void nmSubWndMain::drawSquareOutline() { - // 获取矩形边界的绘制,并模拟触发点击操作 - this->triggerToolBarAction(NMOT_RectOutline); + this->triggerToolBarAction("nmInsertObjRectOutline"); } void nmSubWndMain::drawRoundOutline() { - // 获取矩形边界的绘制,并模拟触发点击操作 - this->triggerToolBarAction(NMOT_RoundOutline); + this->triggerToolBarAction("nmInsertObjRoundOutline"); } void nmSubWndMain::drawFault() { - this->triggerToolBarAction(NMOT_Line_Fault); + this->triggerToolBarAction("nmInsertObjLineFault"); } void nmSubWndMain::selectWell() @@ -1535,36 +1594,23 @@ void nmSubWndMain::selectWell() // 新建井菜单暂时停用。 // void nmSubWndMain::drawWell() // { -// this->triggerToolBarAction(NMOT_Point_Well); +// this->triggerToolBarAction("nmInsertObjPointWell"); // nmDataLogFile::getInstance()->writeLog(" in drawWell "); // } void nmSubWndMain::drawCrack() { - this->triggerToolBarAction(NMOT_Line_Fracture); + this->triggerToolBarAction("nmInsertObjLineCrack"); } void nmSubWndMain::drawRegion() { - this->triggerToolBarAction(NMOT_Region); + this->triggerToolBarAction("nmInsertObjRegion"); } void nmSubWndMain::drawRegionMark() { - this->triggerToolBarAction(NMOT_RegionMark); -} - -void nmSubWndMain::drawMeasure() -{ - nmGuiPlot* plot = dynamic_cast(m_pWxPlot); - QWidget* measureDlg = showMeasureDialog(); - - if(plot == nullptr || measureDlg == nullptr) { - return; - } - - bindMeasureDialog(measureDlg); - this->triggerToolBarAction(NMOT_Line_Measure); + this->triggerToolBarAction("nmInsertRegionMark"); } void nmSubWndMain::drawGeoRef() @@ -1634,52 +1680,38 @@ void nmSubWndMain::bindDialogCmdDestroyed(QWidget* dialog, int nId) connect(dialog, SIGNAL(destroyed(QObject*)), this, SLOT(onDialogCmdDestroyed(QObject*))); } -void nmSubWndMain::bindMeasureDialog(QWidget* measureDlg) +void nmSubWndMain::showMeasureDialog() { - nmGuiPlot* plot = dynamic_cast(m_pWxPlot); - - if(plot == nullptr || measureDlg == nullptr) { + if(isDialogCmdOpened(5129)) { return; } - disconnect(plot, SIGNAL(sigMeasureCommitted()), measureDlg, SLOT(resetButtons())); - connect(plot, SIGNAL(sigMeasureCommitted()), measureDlg, SLOT(resetButtons())); - - disconnect(measureDlg, SIGNAL(needDeleteMeasureObj()), plot, SLOT(finishMeasure())); - connect(measureDlg, SIGNAL(needDeleteMeasureObj()), plot, SLOT(finishMeasure())); -} - -QWidget* nmSubWndMain::showMeasureDialog() -{ - nmGuiPlot* plot = dynamic_cast(m_pWxPlot); - - if(plot == nullptr || plot->boundDataManager() == nullptr) { - return nullptr; - } - - nmPlotDialogContextProvider* pDialogProvider = nmPlotDialogContext::provider(); - - if(pDialogProvider == nullptr) { - return nullptr; + nmGuiPlot* plot = dynamic_cast(m_pWxPlot); + if(plot == nullptr) { + return; } - - QWidget* measureDlg = pDialogProvider->createMeasureDialog(plot); + nmDataAnalyzeManager* manager = plot->boundDataManager(); + nmPlotDialogContextProvider* provider = nmPlotDialogContext::provider(); + QWidget* measureDlg = manager && provider ? provider->createMeasureDialog(plot) : nullptr; if(measureDlg == nullptr) { - return nullptr; + // 窗口无法打开时退出已激活的测量模式,恢复图元编辑。 + plot->cancelActiveTools(); + return; } markDialogCmdOpened(5129); measureDlg->setObjectName("nmMeasureDialog"); measureDlg->setAttribute(Qt::WA_DeleteOnClose, true); bindDialogCmdDestroyed(measureDlg, 5129); + connect(plot, SIGNAL(sigMeasureCommitted()), measureDlg, SLOT(resetButtons())); + connect(measureDlg, SIGNAL(needDeleteMeasureObj()), plot, SLOT(finishMeasure())); // 与对话框及图元绑定器共用本 Map 的测量数据,避免连接到其他分析。 - nmDataMeasure* measureData = plot->boundDataManager()->getMeasureData(); + nmDataMeasure* measureData = manager->getMeasureData(); if(measureData != nullptr) { connect(measureData, SIGNAL(sigMeasureDataChanged()), measureDlg, SLOT(updateDisplay())); } measureDlg->show(); - return measureDlg; } QWidget* nmSubWndMain::showPointerPosDialog() @@ -2969,16 +3001,16 @@ void nmSubWndMain::onPebiGridGenerationFinished( } } -void nmSubWndMain::triggerToolBarAction(int index) +void nmSubWndMain::triggerToolBarAction(const char* command) { - // 获取多边形边界的绘制,并模拟触发点击操作 - // 目前多边形边界绘制是工具栏的第4个,所以用 3 if (m_pPlotToolBar == nullptr) return; - QList actions = m_pPlotToolBar->actions(); - if(!actions.isEmpty() && index >= 0 && index < actions.count()) { - QAction *action = actions[index]; - action->trigger(); + const QLatin1String actionName(command); + foreach (QAction* action, m_pPlotToolBar->actions()) { + if (action->objectName() == actionName) { + action->trigger(); + return; + } } } @@ -3508,7 +3540,7 @@ void nmSubWndMain::on_solverTaskFinished(bool isSuccessed) void nmSubWndMain::deleteOneObj() { - this->triggerToolBarAction(NMOT_Delete); + this->triggerToolBarAction("nmDeleteOneObj"); } void nmSubWndMain::setLocked()