From c380f9006f137481da617d512c45385698bd24b8 Mon Sep 17 00:00:00 2001 From: jiayulong Date: Thu, 13 Nov 2025 15:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E6=9D=BF=E6=9B=B2?= =?UTF-8?q?=E7=BA=BF=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6=EF=BC=8C=E9=87=87?= =?UTF-8?q?=E7=94=A8=E5=88=86=E5=9D=97=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/3rd_qcustomplot/v2_1/qcustomplot.cpp | 4 +- logPlus/formdraw.cpp | 113 ++++++++++++------- logPlus/formdraw.h | 2 + logPlus/formwell.cpp | 25 ++++ logPlus/formwell.h | 1 + logPlus/logPlus.pro | 2 +- logPlus/mainwindow.cpp | 2 +- logPlus/mainwindowcurve.cpp | 63 ++++++++++- logPlus/mainwindowcurve.h | 3 + logPlus/qmycustomplot.cpp | 97 +++++++++++++++- logPlus/qmycustomplot.h | 12 ++ 11 files changed, 278 insertions(+), 46 deletions(-) diff --git a/logPlus/3rd_qcustomplot/v2_1/qcustomplot.cpp b/logPlus/3rd_qcustomplot/v2_1/qcustomplot.cpp index 83913c8..2d7f126 100644 --- a/logPlus/3rd_qcustomplot/v2_1/qcustomplot.cpp +++ b/logPlus/3rd_qcustomplot/v2_1/qcustomplot.cpp @@ -13792,7 +13792,9 @@ QCustomPlot::QCustomPlot(QWidget *parent) : setViewport(rect()); // needs to be called after mPlotLayout has been created - replot(rpQueuedReplot); + replot(rpQueuedReplot);// 异步重绘(需Qt5.10+) + //replot(rpRefreshHint); // 仅刷新可见部分,跳过轴计算等 + //replot(rpImmediateRefresh); //立刻刷新 } QCustomPlot::~QCustomPlot() diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index 3a499c3..71aa7e2 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -200,6 +200,34 @@ void FormDraw::s_mouseWheel(QWheelEvent *event) emit CallManage::getInstance()->sig_mouseWheel(event); } +void FormDraw::setRowHeight(double dHight, QProgressBar *progressBar, int iSplit) +{ + int iBeginValue = progressBar->value(); + + // 获取当前widget的所有子控件 + const QObjectList &children = this->children(); + int columnCount = children.size(); + int iSplitCurv = iSplit / columnCount; + int i=0; + // 遍历子控件列表 + for (QObject *child : children) { + // 判断子控件是否为QWidget类型 + if (QWidget *childWidget = qobject_cast(child)) { + // 打印子控件的信息,使用缩进表示层级关系 + //qDebug() << QString("%1").arg(childWidget->objectName()); + QString strObjName = childWidget->objectName(); + if(strObjName=="QMyCustomPlot") + { + //progressBar->setValue(iBeginValue+ i*iSplitCurv); // 更新进度条的值 + // + QMyCustomPlot *form = (QMyCustomPlot*)childWidget; + form->setGeometry(0, 0, g_iOneWidth, (int)dHight);//7500-3184 + } + } + i++; + } +} + void FormDraw::s_delLine(QString strUuid, QString strWellName, QString strTrackName, QString strLineName) { //井名&道名不一致 @@ -604,48 +632,55 @@ void FormDraw::initForm(QMyCustomPlot *widget, QString strSlfName, QString strLi void FormDraw::addRandomGraph(QMyCustomPlot *widget, QVector x, QVector y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit, double newLeftScale, double newRightScale, QString strScaleType, QColor newlineColor, double width, Qt::PenStyle lineStyle) { -//AppendConsole(PAI_INFO, "FormDraw addRandomGraph"); - widget->addGraph(); - if(strLineName=="") - { - strLineName = QString("曲线 %1").arg(widget->graphCount()); - } - widget->graph()->setName(strLineName); - widget->graph()->setData(x, y); - - if(newLeftScale!=-9999) - { - widget->graph()->setLineStyle((QCPGraph::LineStyle)(lineStyle));//曲线 - - widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); - - QPen graphPen; - graphPen.setColor(newlineColor); - graphPen.setWidthF(width); - graphPen.setStyle(lineStyle);//实线 - widget->graph()->setPen(graphPen); - } - else - { - widget->graph()->setLineStyle((QCPGraph::LineStyle)(1));//曲线 - - - widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); - // widget->graph()->setScatterStyle(QCPScatterStyle(QPixmap(":/image/file.png"))); - //widget->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); - - QPen graphPen; - newlineColor = QColor(std::rand()%245+10, std::rand()%245+10, std::rand()%245+10); - graphPen.setColor(newlineColor); - width = 2; - graphPen.setWidthF(width); - graphPen.setStyle(Qt::SolidLine);//实线 - widget->graph()->setPen(graphPen); - //widget->replot(); - } + widget->addRandomGraph(x, y, strSlfName, strLineName, strAliasName, strUnit, + newLeftScale, newRightScale, strScaleType, newlineColor, width, lineStyle); //道-对象 m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_vmax, m_vmin, strScaleType); + +//AppendConsole(PAI_INFO, "FormDraw addRandomGraph"); +// widget->addGraph(); +// if(strLineName=="") +// { +// strLineName = QString("曲线 %1").arg(widget->graphCount()); +// } +// widget->graph()->setName(strLineName); +// //禁用自动重绘:在大量数据更新前禁用自动重绘 +// //widget->setNotAntialiasedElements(QCP::aeAll); +// widget->graph()->setData(x, y); + +// if(newLeftScale!=-9999) +// { +// widget->graph()->setLineStyle((QCPGraph::LineStyle)(lineStyle));//曲线 + +// widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); + +// QPen graphPen; +// graphPen.setColor(newlineColor); +// graphPen.setWidthF(width); +// graphPen.setStyle(lineStyle);//实线 +// widget->graph()->setPen(graphPen); +// } +// else +// { +// widget->graph()->setLineStyle((QCPGraph::LineStyle)(1));//曲线 + + +// widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); +// // widget->graph()->setScatterStyle(QCPScatterStyle(QPixmap(":/image/file.png"))); +// //widget->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); + +// QPen graphPen; +// newlineColor = QColor(std::rand()%245+10, std::rand()%245+10, std::rand()%245+10); +// graphPen.setColor(newlineColor); +// width = 2; +// graphPen.setWidthF(width); +// graphPen.setStyle(Qt::SolidLine);//实线 +// widget->graph()->setPen(graphPen); +// //widget->replot(); +// } +// //道-对象 +// m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_vmax, m_vmin, strScaleType); //AppendConsole(PAI_INFO, "FormDraw addRandomGraph end"); } diff --git a/logPlus/formdraw.h b/logPlus/formdraw.h index 4e5bf29..ccb8c7b 100644 --- a/logPlus/formdraw.h +++ b/logPlus/formdraw.h @@ -36,6 +36,8 @@ public slots: // void s_mouseWheel(QWheelEvent *event); + void setRowHeight(double dHight, QProgressBar *progressBar, int iSplit); + public: QString m_strUuid; QString m_strWellName; diff --git a/logPlus/formwell.cpp b/logPlus/formwell.cpp index 4fd71a1..702ddf5 100644 --- a/logPlus/formwell.cpp +++ b/logPlus/formwell.cpp @@ -191,6 +191,31 @@ void FormWell::s_NewTrack_No_Line(QString strUuid, QString strWellName, QString } } +void FormWell::setRowHeight(double dHight, QProgressBar *progressBar, int iSplit) +{ + //设置高度 + ui->tableWidget->setRowHeight(2, (int)dHight);//7582 + + int iBeginValue = progressBar->value(); + // + int columnCount = ui->tableWidget->columnCount();//总列数 + int iSplitWell = iSplit / columnCount; + for(int i=0; itableWidget->cellWidget(1, i) != nullptr ) + { + auto myWidget = ui->tableWidget->cellWidget(2, i); + // + FormDraw *formDraw = (FormDraw*)myWidget;//获得widget + if(formDraw) + { + //progressBar->setValue(iBeginValue+ i*iSplitWell); // 更新进度条的值 + formDraw->setRowHeight(dHight, progressBar, iSplitWell); + } + } + } +} + QJsonObject FormWell::makeJson() { // 创建根对象 diff --git a/logPlus/formwell.h b/logPlus/formwell.h index bacd8d5..771760c 100644 --- a/logPlus/formwell.h +++ b/logPlus/formwell.h @@ -28,6 +28,7 @@ public: public: QJsonObject makeJson(); + void setRowHeight(double dHight, QProgressBar *progressBar, int iSplit); public slots: void s_NewTrack(QString strUuid, QString strWellName, QString strSlfName, QString strLineName); diff --git a/logPlus/logPlus.pro b/logPlus/logPlus.pro index 8945c32..689794e 100644 --- a/logPlus/logPlus.pro +++ b/logPlus/logPlus.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui svg - +#QT += opengl greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = logPlus diff --git a/logPlus/mainwindow.cpp b/logPlus/mainwindow.cpp index 22dca27..e6af4aa 100644 --- a/logPlus/mainwindow.cpp +++ b/logPlus/mainwindow.cpp @@ -39,7 +39,7 @@ int g_iY1 = -3000; int g_iY2 = 0; int g_iCanZoom = 0; -int g_iScale = 3000; +int g_iScale = 2500;//0 QString g_prjname=""; MainWindow::MainWindow(QWidget *parent) : diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index e822feb..892b684 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -1021,11 +1021,68 @@ void MainWindowCurve::Open(QString fileFull) // file.close(); qDebug() << "JSON 模板文件读取成功!"; + + //触发更新 + //QTimer::singleShot(2000, this, SLOT(slot_time())); } else { qWarning() << "JSON 模板文件打开失败:" << file.errorString(); } } +void MainWindowCurve::slot_time() +{ + QProgressBar *progressBar = new QProgressBar(this); + progressBar->setGeometry(100, 100, 500, 30); // 设置进度条的位置和大小 + progressBar->setMaximum(100); // 设置最大值为100 + progressBar->setValue(0); // 初始值设为0 + progressBar->show(); + + double dHight = 0; + dHight = (g_iY2-g_iY1)*100.0/(double)g_iScale * g_dPixelPerCm *10; + if(dHight>32767) + { + dHight = 32767; + } + + double dHightOne = dHight+300+100+10; + //设置高度 + ui->tableWidget_2->setRowHeight(1, (int)dHightOne);//8020 + + //-------------------- + // + int columnCount = ui->tableWidget_2->columnCount();//总列数 + int iSplit = 100 / (columnCount/2+1); + + for(int i=0; isetValue(i*iSplit); // 更新进度条的值 + + QCoreApplication::processEvents(); // 让界面更新显示进度条的当前值 + + if( ui->tableWidget_2->cellWidget(1, i) != nullptr ) + { + auto myWidget = ui->tableWidget_2->cellWidget(1, i); + // + FormWell *widgetWell = (FormWell*)myWidget;//获得widget + if(widgetWell) + { + widgetWell->setRowHeight(dHight, progressBar, iSplit); + } + } + } + // + progressBar->deleteLater(); +} + void MainWindowCurve::DisplayWells(QJsonArray wellsArray) { QMap mapWells; @@ -1580,8 +1637,8 @@ void MainWindowCurve::DisplayLine_One(QJsonObject lineObjInfo) } else //if(newFillMode=="填充") { - emit CallManage::getInstance()->sig_ChangeFillMode(m_strUuid, strSlfName, strWellName, strTrackName, strLineName, - newFillType, newTargetLine, newColor, newLithosImage, newHeadFill, - new_vMin, new_vMax, strOtherScaleType, frontColor, backColor, newFillMode); +// emit CallManage::getInstance()->sig_ChangeFillMode(m_strUuid, strSlfName, strWellName, strTrackName, strLineName, +// newFillType, newTargetLine, newColor, newLithosImage, newHeadFill, +// new_vMin, new_vMax, strOtherScaleType, frontColor, backColor, newFillMode); } } diff --git a/logPlus/mainwindowcurve.h b/logPlus/mainwindowcurve.h index cd0d905..f869dc0 100644 --- a/logPlus/mainwindowcurve.h +++ b/logPlus/mainwindowcurve.h @@ -32,6 +32,9 @@ public: bool eventFilter(QObject* obj, QEvent* event); void onPasteExcelData(); +public slots: + void slot_time(); + public slots: void dragEnterEvent(QDragEnterEvent* event); void dragMoveEvent(QDragMoveEvent* event); diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index d87d4aa..49a5b08 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -13,7 +13,8 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel setObjectName("QMyCustomPlot"); - //this->setOpenGl(true); + //this->setOpenGl(true);//不开启,电脑不支持会卡 + this->setNotAntialiasedElements(QCP::aeAll); // 关闭所有抗锯齿 xAxis->setTickLabels(false); yAxis->setTickLabels(false); @@ -899,3 +900,97 @@ void QMyCustomPlot::mouseMoveEvent(QMouseEvent *event) QCustomPlot::mouseMoveEvent(event); } + + +void QMyCustomPlot::addRandomGraph(QVector x, QVector y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit, + double newLeftScale, double newRightScale, QString strScaleType, QColor newlineColor, double width, Qt::PenStyle lineStyle) +{ +//AppendConsole(PAI_INFO, "FormDraw addRandomGraph"); + + m_x.append(x); + m_y.append(y); + + addGraph(); + if(strLineName=="") + { + strLineName = QString("曲线 %1").arg(graphCount()); + } + graph()->setName(strLineName); + //禁用自动重绘:在大量数据更新前禁用自动重绘 + //setNotAntialiasedElements(QCP::aeAll); + + //graph()->setData(x, y); + + if(newLeftScale!=-9999) + { + graph()->setLineStyle((QCPGraph::LineStyle)(lineStyle));//曲线 + + graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); + + QPen graphPen; + graphPen.setColor(newlineColor); + graphPen.setWidthF(width); + graphPen.setStyle(lineStyle);//实线 + graph()->setPen(graphPen); + } + else + { + graph()->setLineStyle((QCPGraph::LineStyle)(1));//曲线 + + + graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); + // graph()->setScatterStyle(QCPScatterStyle(QPixmap(":/image/file.png"))); + //graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); + + QPen graphPen; + newlineColor = QColor(std::rand()%245+10, std::rand()%245+10, std::rand()%245+10); + graphPen.setColor(newlineColor); + width = 2; + graphPen.setWidthF(width); + graphPen.setStyle(Qt::SolidLine);//实线 + graph()->setPen(graphPen); + //replot(); + } + + + if(x.size()setData(x, y); + replot(); + //replot(QCustomPlot::rpRefreshHint);// 仅刷新可见部分,跳过轴计算等 + } + else + { + graph()->setData(x.mid(0,m_iSplitNum), y.mid(0,m_iSplitNum)); + replot(); + + m_iCurNum = m_iSplitNum; + QTimer::singleShot(100, this, SLOT(slot_time())); + } + +} + +void QMyCustomPlot::slot_time() +{ + if(m_iCurNum >= m_x.size()) + { + //处理完成 + return; + } + + // + if(m_x.size() <= m_iCurNum+m_iSplitNum) + { + graph()->addData(m_x.mid(m_iCurNum), m_y.mid(m_iCurNum)); + m_iCurNum = m_x.size(); + replot(); + } + else + { + graph()->addData(m_x.mid(m_iCurNum, m_iSplitNum), m_y.mid(m_iCurNum, m_iSplitNum)); + m_iCurNum = m_iCurNum + m_iSplitNum; + //replot(); + QTimer::singleShot(100, this, SLOT(slot_time())); + } + //replot(); +} diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 696280d..a68823f 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -48,9 +48,21 @@ public: QContextMenuEvent *m_event; bool m_bDrawRect = true; + +public: + //分段刷新 + QVector m_x; + QVector m_y; + int m_iCurNum=0; + int m_iSplitNum=2000; //2000000; //2000; +public slots: + void slot_time(); + public: void init(QString strName, QVector x, QVector y); void addImageToPlot(double left_Low, double right_Hight, const QString imagePath); + void addRandomGraph(QVector x, QVector y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit, + double newLeftScale, double newRightScale, QString strScaleType, QColor newlineColor, double width, Qt::PenStyle lineStyle); public slots: void s_LineClicked(int index);