diff --git a/CallManage/CallManage.h b/CallManage/CallManage.h index 4cd1823..f895298 100644 --- a/CallManage/CallManage.h +++ b/CallManage/CallManage.h @@ -173,6 +173,9 @@ signals: //Plot重新加载数据 void sig_ReloadPlot(QString strUuid, QString strSlfName, QString strLineName); + //编辑曲线,框选拉伸/压缩 + void sig_EShiftDepth(QString strSlfName, QString strLineName, int count, QList left_Low_List, QList right_Hight_List); + // //void sig_addImageToPlot(QMyCustomPlot* customPlot, double left_Low, double right_Hight, QString imagePath); diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index 08f6561..fca1929 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -135,6 +135,9 @@ MainWindowCurve::MainWindowCurve(QWidget *parent) : //执行拼接 connect(CallManage::getInstance(), SIGNAL(sig_Merge_List(QString, QList, QList)), this, SLOT(s_Merge_List(QString, QList, QList))); + //执行压缩/拉伸 + connect(CallManage::getInstance(), SIGNAL(sig_EShiftDepth(QString, QString, int, QList, QList)), this, SLOT(s_EShiftDepth(QString, QString, int, QList, QList))); + //图头 m_dock1=new QDockWidget(tr(""),this); m_dock1->setFeatures(QDockWidget::NoDockWidgetFeatures);//QDockWidget::DockWidgetMovable @@ -1368,6 +1371,48 @@ void MainWindowCurve::s_runcor() emit CallManage::getInstance()->sig_RuncorFromPlot(m_strUuid, m_LeftCurve.m_strSlfName, m_LeftCurve.m_strWellName, m_LeftCurve.m_strTrackName, m_LeftCurve.m_strLineName); } +//编辑曲线,框选拉伸/压缩 +void MainWindowCurve::s_EShiftDepth(QString strSlfName, QString strLineName, int count, QList left_Low_List, QList right_Hight_List) +{ + if(strSlfName=="") return; + + float sdeps[2],edeps[2]; + sdeps[0]=right_Hight_List[0]; + sdeps[1]=left_Low_List[0]; + edeps[0]=right_Hight_List[1]; + edeps[1]=left_Low_List[1]; + + CMemRdWt * logio=new CMemRdWt(); + if(!logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead)) + { + delete logio; + //AppendConsole(pai::log::PAI_ERROR,"SLF文件打开失败,请检查!"); + return; + } + + int curveindex=logio->FindObjectName((char*)strLineName.toStdString().c_str()); + if(curveindex<0) + { + delete logio; + return; + } + CString szBuffer1=""; + CString szBuffer=""; + for(int i=0;iEShiftDepth((char*)strLineName.toStdString().c_str(),2, sdeps, edeps); + delete logio; + + //Plot重新加载数据 + emit CallManage::getInstance()->sig_ReloadPlot(m_strUuid, strSlfName, strLineName); + +} + +//分段线,拉伸/压缩 void MainWindowCurve::s_Runcor_List(QString strUuid, QList left_Low_List, QList right_Hight_List) { if(strUuid != m_strUuid) diff --git a/logPlus/mainwindowcurve.h b/logPlus/mainwindowcurve.h index 6015634..7cd8e68 100644 --- a/logPlus/mainwindowcurve.h +++ b/logPlus/mainwindowcurve.h @@ -219,6 +219,9 @@ public slots: void s_merge(); void s_Merge_List(QString strUuid, QList left_Low_List, QList right_Hight_List); + //编辑曲线,框选拉伸/压缩 + void s_EShiftDepth(QString strSlfName, QString strLineName, int count, QList left_Low_List, QList right_Hight_List); + // void s_showHeadTable(); //显示/隐藏图头 void s_currtemplite(); //加载图文件 diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 8dd998b..8ce64bf 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -402,113 +402,86 @@ void QMyCustomPlot::onEditLine() QMessageBox::information(nullptr, "提示", "当前正在编辑曲线,请先完成编辑!"); return; } - this->setInteractions(QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables | QCP::iMultiSelect); // 轴、图例、图表可以被选择,并且是多选的方式 this->setSelectionRectMode(QCP::srmCustom); // 鼠标框选 - for (int i=0; i < this->graphCount(); ++i) { - QCPGraph *graph = this->graph(i); - graph->setSelectable(QCP::stDataRange); - break; + if(m_bFirstTimeConnect) + { + //信号槽只绑定一次,避免重复绑定 + m_bFirstTimeConnect = false; + + for (int i=0; i < this->graphCount(); ++i) { + QCPGraph *graph = this->graph(i); + graph->setSelectable(QCP::stDataRange); + break; + } + + connect(this->selectionRect(), &QCPSelectionRect::accepted, [this](){ + if(this->m_bDrawRect == false) + { + this->m_bDrawRect = true; + return; + } + // 当选择完成时,获取矩形范围并放大 + QRectF rect = this->selectionRect()->rect(); // 获取选择的矩形区域(像素坐标) + m_bEditRect=true;//当前是否正在编辑曲线。 + + // 转换为坐标轴范围 + double top = rect.top(); + double bottom = rect.bottom(); + + double right_Hight = this->xAxis->pixelToCoord(top); + double left_Low = this->xAxis->pixelToCoord(bottom); + + float rlev=0; + if(m_x.size()>=2) + { + rlev = abs(m_x[1] - m_x[0]); + } + // + int left_Low_Number=0; + int right_Hight_Number=0; + for(int i =0; i= (3*rlev) )//至少选中5个点 + { + // for (int j=right_Hight_Number; jsetPen(QPen(Qt::blue)); + // qcpItemLine->setLayer("overlay"); // 确保在最上层 + // qcpItemLine->start->setCoords(this->m_x[j], this->m_y[j]); + // qcpItemLine->end->setCoords(this->m_x[j+1], this->m_y[j+1]); + // } + // this->replot(); + // QPixmap p = this->grab(QRect(rect.x(), rect.y(), rect.width(), rect.height())); + // p.save("./Rectpicture.png", "png"); + + //添加图形 + this->addSelectRectToPlot(m_x[left_Low_Number], m_x[right_Hight_Number], left_Low_Number, right_Hight_Number);//left_Low, right_Hight + + //取消框选 + this->setInteractions(QCP::iSelectLegend | QCP::iSelectPlottables); + this->setSelectionRectMode(QCP::srmNone); + } + }); + } - - connect(this->selectionRect(), &QCPSelectionRect::accepted, [this](){ - if(this->m_bDrawRect == false) - { - this->m_bDrawRect = true; - return; - } - // 当选择完成时,获取矩形范围并放大 - QRectF rect = this->selectionRect()->rect(); // 获取选择的矩形区域(像素坐标) - m_bEditRect=true;//当前是否正在编辑曲线。 - - // 转换为坐标轴范围 - double top = rect.top(); - double bottom = rect.bottom(); - - double right_Hight = this->xAxis->pixelToCoord(top); - double left_Low = this->xAxis->pixelToCoord(bottom); - - float rlev=0; - if(m_x.size()>=2) - { - rlev = abs(m_x[1] - m_x[0]); - } - // - int left_Low_Number=0; - int right_Hight_Number=0; - for(int i =0; i= (3*rlev) )//至少选中5个点 - { -// for (int j=right_Hight_Number; jsetPen(QPen(Qt::blue)); -// qcpItemLine->setLayer("overlay"); // 确保在最上层 -// qcpItemLine->start->setCoords(this->m_x[j], this->m_y[j]); -// qcpItemLine->end->setCoords(this->m_x[j+1], this->m_y[j+1]); -// } -// this->replot(); -// QPixmap p = this->grab(QRect(rect.x(), rect.y(), rect.width(), rect.height())); -// p.save("./Rectpicture.png", "png"); - - //添加图形 - this->addSelectRectToPlot(m_x[left_Low_Number], m_x[right_Hight_Number], left_Low_Number, right_Hight_Number);//left_Low, right_Hight - - //取消框选 - this->setInteractions(QCP::iSelectLegend | QCP::iSelectPlottables); - this->setSelectionRectMode(QCP::srmNone); - } - }); - - // 连接QCustomPlot的信号,selectionChangedByUser表明是由鼠标点击进行的选择 - // 这里主要就是同步图表和图例的显示 -// connect(this, &QMyCustomPlot::selectionChangedByUser, [this](){ -// for (int i=0; i < this->graphCount(); ++i) { -// QCPGraph *graph = this->graph(i); -// QCPPlottableLegendItem *item = this->legend->itemWithPlottable(graph); - -// if (item->selected() && !graph->selected()) -// { -// graph->setSelection(QCPDataSelection(graph->data()->dataRange())); // 当图例项被选择时,选择图表全部的数据 -// } -// else if (graph->selected()) -// { -// item->setSelected(true); - -// QCPDataSelection selection = this->graph(i)->selection(); -// // 遍历选中的数据范围 -// for (int j = 0; j < selection.dataRangeCount(); ++j) -// { -// QCPDataRange dataRange = selection.dataRange(j); -// double left_Low = this->graph(i)->data()->at(dataRange.begin())->key; -// double right_Hight = this->graph(i)->data()->at(dataRange.end())->key; -// if(right_Hight-left_Low>1) -// { -// //添加图形 -// //emit CallManage::getInstance()->sig_addImageToPlot(customPlot, left_Low, right_Hight, ":/image/file.png"); -// this->addImageToPlot(left_Low, right_Hight, ":/image/file.png"); -// } -// } -// } -// } -// }); } void QMyCustomPlot::onAddRect() @@ -543,6 +516,8 @@ void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QS void QMyCustomPlot::addSelectRectToPlot(double left_Low, double right_Hight, int left_Low_Number, int right_Hight_Number) { + //qDebug() << "QMyCustomPlot addSelectRectToPlot"; + QtCommonClass *qtCommon = new QtCommonClass(this); QString strUuid = qtCommon->getUUid(); @@ -558,7 +533,7 @@ void QMyCustomPlot::addSelectRectToPlot(double left_Low, double right_Hight, int dragRect->setMinWidth(0.1); //dragRect->setTitle(strText); - m_mapDraggable_Image[strUuid] = dragRect; + m_mapDraggable_SelectRect[strUuid] = dragRect; } //校深线段 diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 20b4051..2adc0d2 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -70,6 +70,7 @@ public: int m_iSplitNum=2000; //2000000; //2000; bool m_addRandomGraph=false;//当前是否绘制曲线 true:是。 bool m_bEditRect=false; //当前是否正在编辑曲线。 + bool m_bFirstTimeConnect=true; //初次绑定编辑曲线信号槽。 QMap m_mapDraggable_Rect; QMap m_mapDraggable_Result; @@ -86,6 +87,7 @@ public: QMap m_mapDraggable_SelectRect; QObject* m_SelectShiftLine=nullptr;//当前选中的分段线 + QObject* m_SelectRect=nullptr;//当前选中的曲线编辑框 public slots: void slot_time(); diff --git a/logPlus/transparentdraggableSelectRect.cpp b/logPlus/transparentdraggableSelectRect.cpp index 031f1fe..d30c36a 100644 --- a/logPlus/transparentdraggableSelectRect.cpp +++ b/logPlus/transparentdraggableSelectRect.cpp @@ -1,4 +1,5 @@ #include "transparentdraggableSelectRect.h" +#include "CallManage.h" extern double g_dPixelPerCm;//每厘米像素数 @@ -102,20 +103,6 @@ void TransparentDraggableSelectRect::setNumber(int left_Low_Number, int right_Hi // m_qcpItemLine_List.append(qcpItemLine); } - -// // -// double lY1 = mPlot->yAxis->range().lower;//+10 -// double lY2 = mPlot->yAxis->range().upper; -// double left_Low = mPlot->m_x[left_Low_Number]; -// double right_Hight = mPlot->m_x[right_Hight_Number]; -// // -// double x1 = mPlot->xAxis->coordToPixel(left_Low); -// double x2 = mPlot->xAxis->coordToPixel(right_Hight); -// double y1 = mPlot->yAxis->coordToPixel(lY1); -// double y2 = mPlot->yAxis->coordToPixel(lY2); -// // -// QPixmap p = this->grab(QRect(x2, x1, y2-y1, x1-x2)); -// p.save("./Rectpicture.png","png"); } //设置解释结论 @@ -207,6 +194,9 @@ void TransparentDraggableSelectRect::setRange(double left_Low, double right_High { if(left_Low >= right_Hight) return; + m_left_Low_Current = left_Low; + m_right_Hight_Current = right_Hight; + // double lY1 = mPlot->yAxis->range().lower;//+10 double lY2 = mPlot->yAxis->range().upper; mRect->topLeft->setCoords(left_Low, lY1); @@ -265,7 +255,7 @@ void TransparentDraggableSelectRect::deleteRect() // mRightHandle->deleteLater(); // mPixmap->deleteLater(); - mPlot->m_mapDraggable_Image.remove(m_strUuid); + mPlot->m_mapDraggable_SelectRect.remove(m_strUuid); mPlot->removeItem(mRect); mPlot->removeItem(mLeftHandle); @@ -355,6 +345,30 @@ void TransparentDraggableSelectRect::updateHandles() } +void TransparentDraggableSelectRect::slotSaveChange() +{ + // + QList left_Low_List; + QList right_Hight_List; + left_Low_List.append(0 - mPlot->m_x[m_left_Low_Number]); + right_Hight_List.append(0 - mPlot->m_x[m_right_Hight_Number]); + // + left_Low_List.append(0 - m_left_Low_Current); + right_Hight_List.append(0 - m_right_Hight_Current); + + QString strSlfName = mPlot->m_strSlfName; + QString strLineName = mPlot->m_strLineName; + int count = 2; + + //执行校正 + emit CallManage::getInstance()->sig_EShiftDepth(strSlfName, strLineName, count, left_Low_List, right_Hight_List); + + + //删除框图 + deleteRect(); + //emit sig_DelRect(); +} + void TransparentDraggableSelectRect::onDelRect() { //mDragMode = DragNone; @@ -378,6 +392,11 @@ void TransparentDraggableSelectRect::onMousePress(QMouseEvent *event) //else if(x >= currentRange.lower && x <= currentRange.upper) { else if(y >= currentRange.lower && y <= currentRange.upper) { mDragMode = DragNone; + + QMenu menu(mPlot); + menu.addAction(QIcon(::GetImagePath() + "icon/savecurve.png"), "保存当前数据修改", this, &TransparentDraggableSelectRect::slotSaveChange); + menu.addAction(QIcon(::GetImagePath() + "icon/ClearSel.png"), "放弃当前数据修改", this, &TransparentDraggableSelectRect::onDelRect); + menu.exec(event->globalPos()); } else { mDragMode = DragNone; @@ -385,22 +404,6 @@ void TransparentDraggableSelectRect::onMousePress(QMouseEvent *event) } //event->accept(); - - QMenu menu(nullptr); - QAction *delAction = menu.addAction("删除框图"); - //delAction->installEventFilter(this); - connect(delAction, &QAction::triggered, this, &TransparentDraggableSelectRect::onDelRect); - - // QAction* pItem = menu.exec(event->globalPos()); - // if(pItem == delAction) - // { - // //event->accept(); - - // int ii=0; - // ii++; - // } - menu.exec(event->globalPos()); - return; } @@ -455,7 +458,8 @@ void TransparentDraggableSelectRect::onMouseMove(QMouseEvent *event) double proposedLeft = mDragStartRange.lower + dy; // 确保不超出轴范围且不使宽度小于最小值 newRange.lower = qBound( - mPlot->xAxis->range().lower, + //mPlot->xAxis->range().lower, + getMyLower(), proposedLeft, mDragStartRange.upper - mMinWidth); break; @@ -467,7 +471,8 @@ void TransparentDraggableSelectRect::onMouseMove(QMouseEvent *event) newRange.upper = qBound( mDragStartRange.lower + mMinWidth, proposedRight, - mPlot->xAxis->range().upper); + getMyUpper()); + //mPlot->xAxis->range().upper); break; } case DragRect: { @@ -478,15 +483,24 @@ void TransparentDraggableSelectRect::onMouseMove(QMouseEvent *event) newRange.upper = center + width/2; // 检查是否超出轴范围 - QCPRange axisRange = mPlot->xAxis->range(); - if(newRange.lower < axisRange.lower) { - newRange.lower = axisRange.lower; - newRange.upper = newRange.lower + width; + if(newRange.lower < getMyLower()) { + newRange.lower = getMyLower(); + newRange.upper = newRange.lower + width; } - else if(newRange.upper > axisRange.upper) { - newRange.upper = axisRange.upper; - newRange.lower = newRange.upper - width; + else if(newRange.upper > getMyUpper()) { + newRange.upper = getMyUpper(); + newRange.lower = newRange.upper - width; } + + // QCPRange axisRange = mPlot->xAxis->range(); + // if(newRange.lower < axisRange.lower) { + // newRange.lower = axisRange.lower; + // newRange.upper = newRange.lower + width; + // } + // else if(newRange.upper > axisRange.upper) { + // newRange.upper = axisRange.upper; + // newRange.lower = newRange.upper - width; + // } break; } default: @@ -541,3 +555,61 @@ void TransparentDraggableSelectRect::onMouseRelease(QMouseEvent *event) mPlot->selectionRect()->mActive=true; } } + +double TransparentDraggableSelectRect::getMyLower() +{ + double dLower = mPlot->xAxis->range().lower; + double proposedLeft = mDragStartRange.lower; + + TransparentDraggableSelectRect *pDraggableRect =NULL; + { + QMap::Iterator it = mPlot->m_mapDraggable_SelectRect.begin(); + while( it != mPlot->m_mapDraggable_SelectRect.end() ) + { + if(it.key() == m_strUuid) + { + it++; + continue; + } + pDraggableRect = (TransparentDraggableSelectRect*)it.value(); + // + QCPRange tmpRange = pDraggableRect->getRange(); + if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft) + { + dLower = tmpRange.upper; + } + it++; + } + } + + return dLower; +} + +double TransparentDraggableSelectRect::getMyUpper() +{ + double dUpper = mPlot->xAxis->range().upper; + double proposedRight = mDragStartRange.upper; + + TransparentDraggableSelectRect *pDraggableRect =NULL; + { + QMap::Iterator it = mPlot->m_mapDraggable_SelectRect.begin(); + while( it != mPlot->m_mapDraggable_SelectRect.end() ) + { + if(it.key() == m_strUuid) + { + it++; + continue; + } + pDraggableRect = (TransparentDraggableSelectRect*)it.value(); + // + QCPRange tmpRange = pDraggableRect->getRange(); + if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight) + { + dUpper = tmpRange.lower; + } + it++; + } + } + + return dUpper; +} diff --git a/logPlus/transparentdraggableSelectRect.h b/logPlus/transparentdraggableSelectRect.h index eda537d..8a69c67 100644 --- a/logPlus/transparentdraggableSelectRect.h +++ b/logPlus/transparentdraggableSelectRect.h @@ -49,16 +49,20 @@ public: signals: void rangeChanged(QCPRange newRange); + void sig_DelRect(); private: void initRect(); void updateHandles() ; private slots: + void slotSaveChange(); void onDelRect(); void onMousePress(QMouseEvent *event); void onMouseMove(QMouseEvent *event); void onMouseRelease(QMouseEvent *event); + double getMyLower(); + double getMyUpper(); private: QMyCustomPlot *mPlot; @@ -75,6 +79,8 @@ private: QList m_qcpItemLine_List; int m_left_Low_Number; int m_right_Hight_Number; + double m_left_Low_Current; + double m_right_Hight_Current; enum DragMode { DragNone, DragLeft, DragRight, DragRect }; DragMode mDragMode = DragNone;