diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index 31be6d7..31c6cb0 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -739,6 +739,7 @@ void MainWindowCurve::initMainToolBar() ui->mainToolBar->setStyleSheet("QToolButton:checked { background-color: rgb(188,216,239); }"); QIcon selectWellIcon(::GetImagePath()+"icon/SelectWells.png"); + QIcon hvIcon(::GetImagePath() + "icon/rotatewellsection.png"); QIcon fixwellsectionHeaderIcon(::GetImagePath()+"icon/fixwellsectionHeader.png"); QIcon templateIcon(::GetImagePath()+"WellInterp/导出模板.png"); QIcon opentemplateIcon(::GetImagePath()+"icon/currtemplite.png"); @@ -767,6 +768,7 @@ void MainWindowCurve::initMainToolBar() //Main工具栏 m_selectWellAc = new QAction(selectWellIcon, "设置井", this); + m_hvDraw = new QAction(hvIcon, "横竖", this); m_fixwellsectionHeaderAc = new QAction(fixwellsectionHeaderIcon, "锁头", this); m_opentemplateAc = new QAction(opentemplateIcon, "加载图文件", this); m_saveastemplateAc = new QAction(saveastemplateIcon, "另存为图文件", this); @@ -825,7 +827,8 @@ void MainWindowCurve::initMainToolBar() //add QAction to Widget. ui->mainToolBar->addAction(m_selectWellAc); - ui->mainToolBar->addAction(m_fixwellsectionHeaderAc); //锁头 + ui->mainToolBar->addAction(m_hvDraw); + ui->mainToolBar->addAction(m_fixwellsectionHeaderAc); //锁头 ui->mainToolBar->addAction(templateAction); //图文件菜单 // ui->mainToolBar->addAction(m_opentemplateAc); //加载图文件 // ui->mainToolBar->addAction(m_saveastemplateAc); //另存为图文件 @@ -858,6 +861,8 @@ void MainWindowCurve::initMainToolBar() // 设置为可选中 m_fixwellsectionHeaderAc->setCheckable(true); //锁头 m_fixwellsectionHeaderAc->setChecked(true); //默认选中-锁头 + m_hvDraw->setCheckable(true); //横竖 + m_hvDraw->setChecked(true); //默认选中-竖 m_zoomAc->setCheckable(true); //缩放 m_blackAc->setCheckable(true); //黑白图 m_doubleHeadAc->setCheckable(true); //单曲线头 @@ -868,6 +873,7 @@ void MainWindowCurve::initMainToolBar() m_PreviewPrintAc->setCheckable(true); //预览图 connect(m_selectWellAc, &QAction::triggered, this, &MainWindowCurve::s_selectWell); + connect(m_hvDraw, &QAction::triggered, this, &MainWindowCurve::s_hvDraw); connect(m_fixwellsectionHeaderAc, &QAction::triggered, this, &MainWindowCurve::s_showHeadTable); connect(m_opentemplateAc, &QAction::triggered, this, &MainWindowCurve::s_Open); connect(m_saveastemplateAc, &QAction::triggered, this, &MainWindowCurve::s_Save); @@ -3451,8 +3457,6 @@ void MainWindowCurve::s_ModuleOpen() SetWorkflowConsole(m_pModuleConsole); m_pModuleDlg->setFixedSize(600,800); m_pModuleDlg->show(); - - //rotateCentralWidget90(); //m_pParentWin->setModuleOpenOrClose(); } @@ -4446,6 +4450,18 @@ void MainWindowCurve::s_selectWell() } } +void MainWindowCurve::s_hvDraw() +{ + if (!m_bHVDisplay) + { + rotateCentralWidget90(); + } + else + { + restoreOriginalCentralWidget(); + } +} + //显示/隐藏图头 void MainWindowCurve::s_showHeadTable() { @@ -7232,12 +7248,13 @@ void MainWindowCurve::wheelEvent(QWheelEvent *e) } void MainWindowCurve::rotateCentralWidget90() { - QWidget *oldCentral = takeCentralWidget(); - QObject* obj = oldCentral->parent(); if (m_pGraphicsScene == NULL) { // 获取当前的centralWidget QWidget *oldCentral = takeCentralWidget(); + ui->centralwidget; + QObject* obj = ui->centralwidget->parent(); + QObject* obj1 = oldCentral->parent(); if (!oldCentral) return; m_pTakeWidget = oldCentral; @@ -7252,6 +7269,7 @@ void MainWindowCurve::rotateCentralWidget90() { m_view->setGraphicsProxyWidget(m_pGraphicsProxy); // 将view设置为主窗口的centralWidget setCentralWidget(m_view); + m_pGraphicsScene->setSceneRect(0, 0, oldSize.width(), oldSize.height()-3); // 将旋转原点设置为代理部件的中心点 m_pGraphicsProxy->setTransformOriginPoint(m_pGraphicsProxy->boundingRect().center()); @@ -7269,40 +7287,40 @@ void MainWindowCurve::rotateCentralWidget90() { m_bHVDisplay = true; } - else - { - m_bHVDisplay = !m_bHVDisplay; +} - if (m_bHVDisplay) - { - int nrot = 0; - QRectF RTF = m_pGraphicsScene->sceneRect(); - int nw = RTF.width(); - int nh = RTF.height(); - nrot = -90; - nw = RTF.height(); - nh = RTF.width(); +void MainWindowCurve::restoreOriginalCentralWidget() +{ + // 1. 检查当前中央部件是否为旋转视图 + if (!m_view || centralWidget() != m_view) + return; - QRect gt = m_pTakeWidget->geometry(); - gt.setWidth(nw); - gt.setHeight(nh); - m_pTakeWidget->setGeometry(gt); - m_pGraphicsProxy->setRotation(nrot); // 旋转90度 + // 2. 从场景中获取代理控件,进而获取原始控件 + if (!m_pGraphicsScene || !m_pGraphicsProxy) + return; - QRectF sceneRect = m_pGraphicsProxy->sceneBoundingRect(); - // 移动 proxy,使得 sceneBoundingRect 的左上角位于 (0, 0) - m_pGraphicsProxy->setPos(m_pGraphicsProxy->pos() - sceneRect.topLeft()); + // 1. 从场景中取出原始部件 + if (m_pGraphicsScene && m_pGraphicsProxy) { + QWidget *original = m_pGraphicsProxy->widget(); + if (original) { + // 从 proxy 中取出,设置父对象为 nullptr 或 this + m_pGraphicsProxy->setWidget(nullptr); + original->setParent(nullptr); + // 恢复几何尺寸(宽高换回) + QSize rotSize = original->size(); + original->setGeometry(0, 0, rotSize.height(), rotSize.width()); + // 重新设置为中央部件 + setCentralWidget(original); + m_pTakeWidget = original; // 更新记录 } - else - { - setCentralWidget(m_pTakeWidget); - - m_pGraphicsScene->deleteLater(); - m_pGraphicsScene = nullptr; - m_view->deleteLater(); - m_view = nullptr; - } - } + // 2. 删除视图和场景 + delete m_view; + delete m_pGraphicsScene; + m_view = nullptr; + m_pGraphicsScene = nullptr; + m_pGraphicsProxy = nullptr; + m_bHVDisplay = false; + return; } diff --git a/logPlus/mainwindowcurve.h b/logPlus/mainwindowcurve.h index d248634..f10a696 100644 --- a/logPlus/mainwindowcurve.h +++ b/logPlus/mainwindowcurve.h @@ -46,7 +46,7 @@ protected: void wheelEvent(QWheelEvent *e) override; //滚轮事件 void rotateCentralWidget90(); - + void restoreOriginalCentralWidget(); public: void resizeItem(QString strWellName, double tempWidth, double tempHight); void getTableSize_Head(int &iHight); @@ -255,6 +255,7 @@ public slots: public: QAction* m_selectWellAc = nullptr; //选择井 + QAction* m_hvDraw = nullptr; //横竖 QAction* m_fixwellsectionHeaderAc = nullptr; //锁头 QAction* m_opentemplateAc = nullptr; //加载图文件 QAction* m_saveastemplateAc = nullptr; //另存为图文件 @@ -357,6 +358,7 @@ public slots: // void s_selectWell(); //选择井 + void s_hvDraw(); //横竖绘制 void s_showHeadTable(); //显示/隐藏图头 void s_Open(); //加载图文件 void s_Save(); //保存图文件