From 427293bc76963e1d12737c9b4abd24906a6f9229 Mon Sep 17 00:00:00 2001 From: jiayulong Date: Tue, 27 Jan 2026 17:55:08 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=94=AF=E6=8C=81=E5=8F=B3=E9=94=AE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E3=80=81=E6=B8=85=E9=99=A4=E5=88=86=E6=AE=B5=E7=BA=BF?= =?UTF-8?q?=E3=80=822.=E5=88=86=E6=AE=B5=E7=BA=BF=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8B=96=E6=8B=89=E4=BF=AE=E6=94=B9=E5=9D=90=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CallManage/CallManage.h | 11 ++ logPlus/TransparentDraggableLine.cpp | 221 +++++++++++++++++++++++++++ logPlus/TransparentDraggableLine.h | 70 +++++++++ logPlus/logPlus.pro | 2 + logPlus/mainwindowcurve.cpp | 73 ++++++++- logPlus/mainwindowcurve.h | 5 + logPlus/qmycustomplot.cpp | 99 +++++++++++- logPlus/qmycustomplot.h | 16 ++ 8 files changed, 491 insertions(+), 6 deletions(-) create mode 100644 logPlus/TransparentDraggableLine.cpp create mode 100644 logPlus/TransparentDraggableLine.h diff --git a/CallManage/CallManage.h b/CallManage/CallManage.h index 862935c..aeaa1ca 100644 --- a/CallManage/CallManage.h +++ b/CallManage/CallManage.h @@ -142,6 +142,17 @@ signals: //改变道宽 void sig_changeWidth(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, int iCurrentCol, int iNewWidth); + + //右键--添加分段线 + void sig_AddShiftLine(QString strUuid, double left_Low, double right_Hight); + //校深线段 + void sig_AddShifLineToPlot(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double left_Low, double right_Hight); + + //右键--清除全部分段线 + void sig_DelAllShiftLine(QString strUuid); + //清除全部分段线 + void sig_DelAllShiftLineFromPlot(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName); + // //void sig_addImageToPlot(QMyCustomPlot* customPlot, double left_Low, double right_Hight, QString imagePath); diff --git a/logPlus/TransparentDraggableLine.cpp b/logPlus/TransparentDraggableLine.cpp new file mode 100644 index 0000000..d962347 --- /dev/null +++ b/logPlus/TransparentDraggableLine.cpp @@ -0,0 +1,221 @@ +#include "TransparentDraggableLine.h" + +extern double g_dPixelPerCm;//每厘米像素数 +//static GeoIndicatorGenerator m_drawGeo; + +TransparentDraggableLine::TransparentDraggableLine(QMyCustomPlot *parentPlot, QString strUuid, double minWidth, QString strTitle) + : QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth) +{ + m_strUuid = strUuid; + // + initRect(); +} + +TransparentDraggableLine::~TransparentDraggableLine() +{ + if(mPlot) + { + } +} + +//设置最小宽度 +void TransparentDraggableLine::setMinWidth(double minWidth) +{ + mMinWidth = minWidth; +} + +//设置标题 +void TransparentDraggableLine::setTitle(QString strTitle) +{ + mstrTitle = strTitle; + //mPlot->replot(); +} + +// 设置矩形范围 +void TransparentDraggableLine::setRange(double left_Low, double right_Hight) +{ + double lY1 = mPlot->yAxis->range().lower;//+10 + double lY2 = mPlot->yAxis->range().upper; + + for(int i =0; im_x.size(); i++) + { + if(abs(mPlot->m_x[i]-left_Low) < 0.1) + { + lY1 = mPlot->m_y[i]; + break; + } + } + m_lY1 = lY1; + + qcpItemLine->start->setCoords(left_Low, lY1);//圆心位置 + qcpItemLine->end->setCoords(right_Hight, lY2);//圆心位置 + + //updateHandles(); + mPlot->replot(); +} + +// 获取当前范围 +void TransparentDraggableLine::getRange() +{ + m_left_Low = qcpItemLine->start->coords().x(); + m_right_Hight = qcpItemLine->end->coords().x(); +} + +// 设置矩形颜色 +void TransparentDraggableLine::setColor(const QColor &color) +{ +} + +// 删除框图 +void TransparentDraggableLine::deleteRect() +{ + if(mPlot) { + mPlot->m_mapDraggable_Line.remove(m_strUuid); + + mPlot->removeItem(qcpItemLine); + + mPlot->replot(); + this->deleteLater(); + } +} + + +void TransparentDraggableLine::initRect() +{ + // 连接鼠标事件 + connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableLine::onMousePress); + connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableLine::onMouseMove); + connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableLine::onMouseRelease); + + qcpItemLine = new QCPItemLine(mPlot); + qcpItemLine->setPen(QPen(Qt::blue)); + qcpItemLine->setLayer("overlay"); // 确保在最上层 + + //上下边界 + updateHandles(); +} + +void TransparentDraggableLine::updateHandles() +{ + +} + +void TransparentDraggableLine::onDelRect() +{ + //mDragMode = DragNone; + //删除框图 + deleteRect(); +} + + +void TransparentDraggableLine::onMousePress(QMouseEvent *event) +{ + if(event->button() != Qt::LeftButton)//右键 + { +// QMenu menu(nullptr); +// QAction *delAction = menu.addAction("删除框图"); +// connect(delAction, &QAction::triggered, this, &TransparentDraggableLine::onDelRect); + +// menu.exec(event->globalPos()); +// return; + } + + event->accept(); + + // 检查点击了哪个部分 + double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度 + double x = mPlot->yAxis->pixelToCoord(event->pos().x()); + //double lY1 = mPlot->yAxis->range().lower;//+10 + double lY2 = mPlot->yAxis->range().upper; + + if(qcpItemLine->selectTest(event->pos(), false) < 5) + { + if(mPlot->m_SelectShiftLine) + { + //之前的选中线段,恢复黑色 + TransparentDraggableLine *tmpLine = (TransparentDraggableLine*)mPlot->m_SelectShiftLine; + tmpLine->qcpItemLine->setPen(QPen(Qt::blue)); + } + + //重新设置选中线段 + mPlot->m_SelectShiftLine = this; + qcpItemLine->setPen(QPen(Qt::red)); + + double delta = (m_lY1+lY2)/10.0; + if(x < m_lY1+delta) + { + mDragMode = DragLeft; + } + else if(x > lY2-delta) + { + mDragMode = DragRight; + } + else + { + mDragMode = DragRect; + } + } + else { + mDragMode = DragNone; + return; + } + + getRange(); + + mDragStartY = y; +} + +void TransparentDraggableLine::onMouseMove(QMouseEvent *event) +{ + if(mDragMode == DragNone) return; + + event->accept(); + + //double x = mPlot->xAxis->pixelToCoord(event->pos().x()); + //double dx = x - mDragStartX; + + double y = mPlot->xAxis->pixelToCoord(event->pos().y()); + double dy = y - mDragStartY; + mDragStartY = y; + + switch(mDragMode) { + case DragLeft: { + m_left_Low = m_left_Low + dy; + break; + } + case DragRight: { + m_right_Hight = m_right_Hight + dy; + break; + } + case DragRect: { + m_left_Low = m_left_Low + dy; + m_right_Hight = m_right_Hight + dy; + break; + } + default: + break; + } + + setRange(m_left_Low, m_right_Hight); +} + +void TransparentDraggableLine::onMouseRelease(QMouseEvent *event) +{ + if(event->button() == Qt::LeftButton && mDragMode != DragNone) { + event->accept(); + //避免二次绘制框图 + mPlot->m_bDrawRect = false; + //emit rangeChanged(getRange()); + mDragMode = DragNone; + //取消选中状态 +// QCPDataSelection emptySelection; +// mPlot->graph(0)->setSelection(emptySelection); +// mPlot->replot(); + + //取消选中框 + mPlot->selectionRect()->cancel(); + mPlot->replot(); + mPlot->selectionRect()->mActive=true; + } +} + diff --git a/logPlus/TransparentDraggableLine.h b/logPlus/TransparentDraggableLine.h new file mode 100644 index 0000000..b610282 --- /dev/null +++ b/logPlus/TransparentDraggableLine.h @@ -0,0 +1,70 @@ +#ifndef TRANSPARENTDRAGGABLELINE_H +#define TRANSPARENTDRAGGABLELINE_H + +#include +#include "qmycustomplot.h" +#include +#include + +#pragma execution_character_set("utf-8") // 强制指定执行字符集为 UTF-8 + +//曲线校深--线段 +class TransparentDraggableLine : public QObject +{ + Q_OBJECT +public: + explicit TransparentDraggableLine(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = ""); + + + ~TransparentDraggableLine(); + + //设置最小宽度 + void setMinWidth(double minWidth); + //设置标题 + void setTitle(QString strTitle); + + // 设置矩形范围 + void setRange(double left_Low, double right_Hight); + // 获取当前范围 + void getRange(); + + // 设置矩形颜色 + void setColor(const QColor &color); + + // 删除框图 + void deleteRect(); + +signals: + void rangeChanged(QCPRange newRange); + +private: + void initRect(); + void updateHandles() ; + +private slots: + void onDelRect(); + void onMousePress(QMouseEvent *event); + void onMouseMove(QMouseEvent *event); + void onMouseRelease(QMouseEvent *event); + +private: + QMyCustomPlot *mPlot; + + QCPItemLine *qcpItemLine; + QString mstrTitle=""; + QString m_strUuid = ""; + + enum DragMode { DragNone, DragLeft, DragRight, DragRect }; + DragMode mDragMode = DragNone; + //double mDragStartX = 0; + double mDragStartY = 0; + + double m_left_Low = 0; + double m_right_Hight = 0; + double m_lY1 = 0; + + // 添加最小宽度成员变量 + double mMinWidth; +}; + +#endif // TRANSPARENTDRAGGABLELINE_H diff --git a/logPlus/logPlus.pro b/logPlus/logPlus.pro index 9d7564f..0f92768 100644 --- a/logPlus/logPlus.pro +++ b/logPlus/logPlus.pro @@ -51,6 +51,7 @@ SOURCES += \ TransparentDraggableGeoLith.cpp \ TransparentDraggableGujing.cpp \ TransparentDraggableJiegutext.cpp \ + TransparentDraggableLine.cpp \ TransparentDraggableMFac.cpp \ TransparentDraggablePhase.cpp \ TransparentDraggableRect.cpp \ @@ -110,6 +111,7 @@ HEADERS += \ TransparentDraggableGeoLith.h \ TransparentDraggableGujing.h \ TransparentDraggableJiegutext.h \ + TransparentDraggableLine.h \ TransparentDraggableMFac.h \ TransparentDraggablePhase.h \ TransparentDraggableRect.h \ diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index 12de932..d541b6c 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -116,6 +116,10 @@ MainWindowCurve::MainWindowCurve(QWidget *parent) : connect(CallManage::getInstance(), SIGNAL(sig_changeWidth(QString, QString, QString, QString, int, int)), this, SLOT(s_changeWidth(QString, QString, QString, QString, int, int))); //曲线选中,置顶 connect(CallManage::getInstance(), SIGNAL(sig_Raise(QString, QString, QString, QString, QString, int, QString)), this, SLOT(s_Raise(QString, QString, QString, QString, QString, int, QString))); + //右键--添加分段线 + connect(CallManage::getInstance(), SIGNAL(sig_AddShiftLine(QString, double, double)), this, SLOT(s_AddShiftLine(QString, double, double))); + //右键--清除全部分段线 + connect(CallManage::getInstance(), SIGNAL(sig_DelAllShiftLine(QString)), this, SLOT(s_DelAllShiftLine(QString))); //图头 m_dock1=new QDockWidget(tr(""),this); @@ -417,7 +421,7 @@ void MainWindowCurve::initToolBar() //初始化工具栏 void MainWindowCurve::initToolBar_2() { - QSize toolIconSize(18, 18); + QSize toolIconSize(26, 26); ui->toolBar_2->setIconSize(toolIconSize); //设置工具栏图标大小 QIcon ShiftIcon(::GetImagePath()+"icon/Shift.png"); @@ -1027,6 +1031,70 @@ void qsort(QVector&datx,int left,int right,int idx) if(isig_AddShifLineToPlot(m_strUuid, m_LeftCurve.m_strSlfName, m_LeftCurve.m_strWellName, m_LeftCurve.m_strTrackName, m_LeftCurve.m_strLineName, left_Low, right_Hight); +} + +//右键--清除全部分段线 +void MainWindowCurve::s_DelAllShiftLine(QString strUuid) +{ + if(strUuid != m_strUuid) + { + return; + } + + //当前有标准曲线 + if(m_LeftCurve.m_iTableType==3 && m_LeftCurve.m_strFormInfoType=="curveObject") + { + } + else + { + QMessageBox::warning(this, "提示", "请先选择标准曲线!"); + return; + } + +// //当前有主校曲线 +// if(m_RightCurve.m_iTableType==3 && m_RightCurve.m_strFormInfoType=="curveObject") +// { +// } +// else +// { +// QMessageBox::warning(this, "提示", "请先选择校正曲线!"); +// return; +// } + + //通知界面,增加一条校深线段 + emit CallManage::getInstance()->sig_DelAllShiftLineFromPlot(m_strUuid, m_LeftCurve.m_strSlfName, m_LeftCurve.m_strWellName, m_LeftCurve.m_strTrackName, m_LeftCurve.m_strLineName); +} + //自动对比 void MainWindowCurve::s_autocor() { @@ -1156,6 +1224,9 @@ void MainWindowCurve::s_autocor() float edep=m_mergeLineList[i]->GetRightDepth(); szBuffer1.Format("%g %g\r\n",sdep,edep); szBuffer+=szBuffer1; + + //通知界面,增加一条校深线段 + emit CallManage::getInstance()->sig_AddShifLineToPlot(m_strUuid, m_LeftCurve.m_strSlfName, m_LeftCurve.m_strWellName, m_LeftCurve.m_strTrackName, m_LeftCurve.m_strLineName, -edep, -sdep); } CMemRdWt mem; if(mem.Open(m_RightCurve.m_strSlfName.toStdString().c_str())) diff --git a/logPlus/mainwindowcurve.h b/logPlus/mainwindowcurve.h index 78bd1da..b8479d9 100644 --- a/logPlus/mainwindowcurve.h +++ b/logPlus/mainwindowcurve.h @@ -59,6 +59,11 @@ public slots: void mousePressEvent(QMouseEvent *event); void s_Raise(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, int iTableType, QString strFormInfoType); + //右键--添加分段线 + void s_AddShiftLine(QString strUuid, double left_Low, double right_Hight); + //右键--清除全部分段线 + void s_DelAllShiftLine(QString strUuid); + public slots: void dragEnterEvent(QDragEnterEvent* event); void dragMoveEvent(QDragMoveEvent* event); diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 8560cf0..22b1565 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -12,6 +12,7 @@ #include "TransparentDraggablePhase.h" #include "TransparentDraggableFac.h" #include "transparentdraggableGuan.h" +#include "TransparentDraggableLine.h" #include "qtcommonclass.h" //是否隐藏刻度 @@ -76,6 +77,10 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel //岩性填充-填充 connect(CallManage::getInstance(), SIGNAL(sig_ChangeFillMode(QString, QString, QString, QString, QString, QString, QString, QColor, QString, QString, float, float, QString , QColor, QColor, QString, bool)), this, SLOT(s_ChangeFillMode(QString, QString, QString, QString, QString, QString, QString, QColor, QString, QString, float, float, QString, QColor, QColor, QString, bool))); + //添加校深线段 + connect(CallManage::getInstance(), SIGNAL(sig_AddShifLineToPlot(QString, QString, QString, QString, QString, double, double)), this, SLOT(s_AddShifLineToPlot(QString, QString, QString, QString, QString, double, double))); + //清除全部分段线 + connect(CallManage::getInstance(), SIGNAL(sig_DelAllShiftLineFromPlot(QString, QString, QString, QString, QString)), this, SLOT(s_DelAllShiftLineFromPlot(QString, QString, QString, QString, QString))); } @@ -333,11 +338,15 @@ void QMyCustomPlot::s_LineClicked(int index) void QMyCustomPlot::contextMenuEvent(QContextMenuEvent *event) { - QMenu menu(this); - QAction *resetAction = menu.addAction("添加框图"); - m_event = event; - connect(resetAction, &QAction::triggered, this, &QMyCustomPlot::onAddRect); + // + QMenu menu(this); + + menu.addAction("添加分段线", this, &QMyCustomPlot::onAddShiftLine); + menu.addAction("清除全部分段线", this, &QMyCustomPlot::onDelAllShiftLine); + +// QAction *resetAction = menu.addAction("添加框图"); +// connect(resetAction, &QAction::triggered, this, &QMyCustomPlot::onAddRect); // if (selectedGraphs().size() > 0)//选中曲线 // { @@ -347,6 +356,23 @@ void QMyCustomPlot::contextMenuEvent(QContextMenuEvent *event) menu.exec(event->globalPos()); } +//右键--添加分段线 +void QMyCustomPlot::onAddShiftLine() +{ + double right_Hight = xAxis->pixelToCoord(m_event->pos().y());//x轴展示深度 + double left_Low = right_Hight; + + //通知界面,增加一条校深线段 + emit CallManage::getInstance()->sig_AddShiftLine(m_strUuid, left_Low, right_Hight); +} + +//右键--清除全部分段线 +void QMyCustomPlot::onDelAllShiftLine() +{ + //通知界面,清除全部分段线 + emit CallManage::getInstance()->sig_DelAllShiftLine(m_strUuid); +} + void QMyCustomPlot::onAddRect() { double right_Hight = xAxis->pixelToCoord(m_event->pos().y());//x轴展示深度 @@ -377,12 +403,75 @@ void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QS m_mapDraggable_Image[strUuid] = dragRect; } +//校深线段 +void QMyCustomPlot::s_AddShifLineToPlot(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double left_Low, double right_Hight) +{ + if(m_strUuid == strUuid && + m_strSlfName == strSlfName && + m_strWellName == strWellName && + m_strTrackName == strTrackName && + m_strLineName == strLineName) + { + + } + else + { + return; + } + + addLineToPlot(left_Low, right_Hight, ""); +} + +//校深线段 +void QMyCustomPlot::s_DelAllShiftLineFromPlot(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName) +{ + if(m_strUuid == strUuid && + m_strSlfName == strSlfName && + m_strWellName == strWellName && + m_strTrackName == strTrackName && + m_strLineName == strLineName) + { + + } + else + { + return; + } + + TransparentDraggableLine *pDraggableLine =NULL; + { + QMap::Iterator it = m_mapDraggable_Line.begin(); + while( it != m_mapDraggable_Line.end() ) + { + pDraggableLine = (TransparentDraggableLine*)it.value(); + it++; + pDraggableLine->deleteRect(); + } + } +} + +void QMyCustomPlot::addLineToPlot(double left_Low, double right_Hight, const QString strText, QColor crColor) +{ + QtCommonClass *qtCommon = new QtCommonClass(this); + QString strUuid = qtCommon->getUUid(); + + // 在初始化代码中 + TransparentDraggableLine *dragRect = new TransparentDraggableLine(this, strUuid); + // 设置初始范围 + dragRect->setRange(left_Low, right_Hight); + // 可选:设置颜色 + dragRect->setColor(crColor); // 半透明白色 + //最小宽度 + dragRect->setMinWidth(0.1); + dragRect->setTitle(strText); + + m_mapDraggable_Line[strUuid] = dragRect; +} void QMyCustomPlot::addTextToPlot(double left_Low, double right_Hight, const QString strText, QColor crColor) { QtCommonClass *qtCommon = new QtCommonClass(this); QString strUuid = qtCommon->getUUid(); - // 在初始化代码中 TransparentDraggableRect *dragRect = new TransparentDraggableRect(this, strUuid); // 设置初始范围 diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index cf01c19..bec7703 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -80,6 +80,9 @@ public: QMap m_mapDraggable_Fac; QMap m_mapDraggable_Guan; QMap m_mapDraggable_Jiegutext; + QMap m_mapDraggable_Line; + + QObject* m_SelectShiftLine=nullptr;//当前选中的分段线 public slots: void slot_time(); @@ -108,6 +111,8 @@ public: void addGuanToPlot(double left_Low, double right_Hight, const QString imagePath, float in); + void addLineToPlot(double left_Low, double right_Hight, const QString strText, QColor crColor=QColor(255, 255, 255, 80)); + public slots: void s_LineClicked(int index); void onResetZoom(); @@ -137,6 +142,17 @@ public slots: QString newFillType, QString newTargetLine, QColor newColor, QString newLithosImage, QString newHeadFill, float vMin, float vMax, QString strOtherScaleType, QColor frontColor, QColor backColor, QString newFillMode, bool bFillNow); + + //右键--添加分段线 + void onAddShiftLine(); + //校深线段 + void s_AddShifLineToPlot(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double left_Low, double right_Hight); + + //右键--清除全部分段线 + void onDelAllShiftLine(); + //清除全部分段线 + void s_DelAllShiftLineFromPlot(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName); + void onAddRect(); //蝌蚪图重绘网格线