优化性能。
This commit is contained in:
parent
a9a432a6d2
commit
17b67709cd
|
|
@ -13821,7 +13821,7 @@ QCustomPlot::QCustomPlot(QWidget *parent) :
|
|||
|
||||
setViewport(rect()); // needs to be called after mPlotLayout has been created
|
||||
|
||||
replot(rpQueuedReplot);// 异步重绘(需Qt5.10+)
|
||||
//replot(rpQueuedReplot);// 异步重绘(需Qt5.10+)
|
||||
//replot(rpRefreshHint); // 仅刷新可见部分,跳过轴计算等
|
||||
//replot(rpImmediateRefresh); //立刻刷新
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,6 +182,8 @@ void FormDraw::setDrawData(QStringList listdt, QJsonObject objInfo)
|
|||
curv->m_strObjUuid = pInfo->m_strObjUuid;
|
||||
curv->setDepthY(m_iY1, m_iY2);
|
||||
curv->initGeometry(m_strUuid, m_iScale, dW);
|
||||
// ===== 性能优化: 开启批量模式, 推迟 replot 到 DisplayLines 完成 =====
|
||||
curv->beginBatchLoad();
|
||||
curv->show();
|
||||
|
||||
if ("tdtObject" == strType)
|
||||
|
|
@ -427,6 +429,12 @@ void FormDraw::DisplayLines(QJsonArray linesArray)
|
|||
// DepthProgress mDepthProgress;
|
||||
// mDepthProgress.CreatProgress(0, iCount,"加载..");
|
||||
|
||||
// ===== 性能优化: 批量加载, 暂停 UI 更新 =====
|
||||
bool bLargeLoad = (iCount > 5);
|
||||
if (bLargeLoad) {
|
||||
setUpdatesEnabled(false);
|
||||
}
|
||||
|
||||
for (int id = 0; id < iCount; id++)
|
||||
{
|
||||
if (mapLines.contains(id))
|
||||
|
|
@ -537,6 +545,18 @@ void FormDraw::DisplayLines(QJsonArray linesArray)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 性能优化: 批量加载结束, 统一刷新所有曲线 =====
|
||||
if (bLargeLoad) {
|
||||
setUpdatesEnabled(true);
|
||||
// 结束所有曲线的批量模式, 触发一次性 replot
|
||||
for (int i = 0; i < m_vecCurv.size(); i++) {
|
||||
if (m_vecCurv[i]->isBatchMode()) {
|
||||
m_vecCurv[i]->endBatchLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//mDepthProgress.DelProgress();
|
||||
}
|
||||
|
|
@ -3150,6 +3170,8 @@ QMyCustomPlot* FormDraw::addTableLine(QString strUuid, QString strSlfName, QStri
|
|||
curv->m_formTrack = m_formTrack;
|
||||
curv->setDepthY(m_iY1, m_iY2);
|
||||
curv->initGeometry(m_strUuid, m_iScale, m_nTrackW);
|
||||
// ===== 性能优化: 开启批量模式, 推迟 replot =====
|
||||
curv->beginBatchLoad();
|
||||
curv->show();
|
||||
|
||||
if (strLineName == "FRAC_HOLE.TABLE")
|
||||
|
|
@ -3505,7 +3527,7 @@ void FormDraw::s_AddLine_Property(QString strUuid, QString strSlfName, QString s
|
|||
QMyCustomPlot *curv = new QMyCustomPlot(this, strSlfName, strWellName, strTrackName, strLineName);
|
||||
//绑定m_formTrack,方便关联formInfo
|
||||
curv->m_formTrack = m_formTrack;
|
||||
|
||||
curv->beginBatchLoad();
|
||||
curv->show();
|
||||
initForm(curv, strSlfName, strLineName,
|
||||
newLeftScale, newRightScale, strScaleType, lineColor, width, lineStyle, listOtherProperty);
|
||||
|
|
|
|||
|
|
@ -72,11 +72,20 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel
|
|||
mSizeHandleManager = new QCPSizeHandleManager(this);
|
||||
|
||||
setObjectName("QMyCustomPlot");
|
||||
//this->setOpenGl(true);//不开启,电脑不支持会卡
|
||||
// this->setNotAntialiasedElements(QCP::aeAll); // 关闭所有抗锯齿
|
||||
|
||||
// ===== 性能优化: 启用 OpenGL 硬件加速 =====
|
||||
// 优先尝试 OpenGL, 如果硬件不支持会自动回退到软件渲染
|
||||
this->setOpenGl(true, 16);
|
||||
|
||||
m_newColor = Qt::black;
|
||||
// 开启抗锯齿
|
||||
this->setAntialiasedElement(QCP::aeAll);
|
||||
// ===== 性能优化: 仅对曲线开抗锯齿, 关闭轴/网格/图例抗锯齿 =====
|
||||
this->setAntialiasedElement(QCP::aePlottables);
|
||||
this->setNotAntialiasedElements(QCP::aeAxes | QCP::aeGrid | QCP::aeLegend | QCP::aeOther);
|
||||
|
||||
// ===== 性能优化: 启用 QCustomPlot 内置性能提示 =====
|
||||
this->setPlottingHint(QCP::phFastPolylines, true); // 快速折线绘制, 跳过复杂路径计算
|
||||
this->setPlottingHint(QCP::phCacheLabels, true); // 缓存轴标签为位图, 避免重复渲染文字
|
||||
this->setAutoAddPlottableToLegend(false); // 禁用自动图例, 减少内存和绘制开销
|
||||
|
||||
//背景设置成透明色
|
||||
this->setBackground(Qt::transparent);
|
||||
|
|
@ -6205,7 +6214,7 @@ void QMyCustomPlot::s_ChangeLeftScale(QString strUuid, QString strSlfName, QStri
|
|||
updateCurveTwoBackAndForth();
|
||||
}
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
else if(m_strUuid == strUuid &&
|
||||
m_strSlfName == strSlfName &&
|
||||
|
|
@ -6245,7 +6254,7 @@ void QMyCustomPlot::s_ChangeRightScale(QString strUuid, QString strSlfName, QStr
|
|||
updateCurveTwoBackAndForth();
|
||||
}
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
else if(m_strUuid == strUuid &&
|
||||
m_strSlfName == strSlfName &&
|
||||
|
|
@ -6312,7 +6321,7 @@ void QMyCustomPlot::s_ChangeLineColor(QString strUuid, QString strSlfName, QStri
|
|||
pen.setColor(lineColor);
|
||||
graph->setPen(pen);
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6334,7 +6343,7 @@ void QMyCustomPlot::s_ChangeLineWidth(QString strUuid, QString strSlfName, QStri
|
|||
graph->setPen(pen);
|
||||
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6352,7 +6361,7 @@ void QMyCustomPlot::s_ChangeLineStyle(QString strUuid, QString strSlfName, QStri
|
|||
pen.setStyle(lineStyle);
|
||||
graph(0)->setPen(pen);
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -6412,7 +6421,7 @@ void QMyCustomPlot::s_ChangePointStyle(QString strUuid, QString strSlfName, QStr
|
|||
graph->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(QCPScatterStyle::ssNone)));
|
||||
}
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6471,7 +6480,7 @@ void QMyCustomPlot::ChangeDrawMethod(QString strUuid, QString strSlfName, QStrin
|
|||
graph->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(QCPScatterStyle::ssNone)));
|
||||
}
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6629,7 +6638,7 @@ void QMyCustomPlot::s_ChangeDrawSymmetry(QString strUuid, QString strSlfName, QS
|
|||
//graph_Fill->setPen(QColor(255, 255, 255));
|
||||
graph_Symmetry->setPen(QColor(0, 0, 0));//(graph(0)->pen());
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -6640,7 +6649,7 @@ void QMyCustomPlot::s_ChangeDrawSymmetry(QString strUuid, QString strSlfName, QS
|
|||
this->removeGraph(graph_Symmetry);
|
||||
graph_Symmetry=nullptr;
|
||||
//
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7277,12 +7286,21 @@ void QMyCustomPlot::addRandomGraph(QVector<double> x, QVector<double> y, QString
|
|||
|
||||
m_addRandomGraph=true;
|
||||
|
||||
// ===== 性能优化: 预分配容量, 避免 QVector 增量扩容 =====
|
||||
m_x.reserve(m_x.size() + x.size());
|
||||
m_y.reserve(m_y.size() + y.size());
|
||||
m_showX.reserve(m_showX.size() + x.size());
|
||||
m_showY.reserve(m_showY.size() + y.size());
|
||||
|
||||
m_x.append(x);
|
||||
m_y.append(y);
|
||||
m_showX.append(x);
|
||||
m_showY.append(y);
|
||||
m_showX.append(x);
|
||||
m_showY.append(y);
|
||||
|
||||
QCPGraph *graph=addGraph();
|
||||
// ===== 性能优化: 启用自适应采样, 缩小时自动降采样 =====
|
||||
graph->setAdaptiveSampling(true);
|
||||
|
||||
if(strLineName=="")
|
||||
{
|
||||
strLineName = QString("曲线 %1").arg(graphCount());
|
||||
|
|
@ -7386,21 +7404,41 @@ void QMyCustomPlot::addRandomGraph(QVector<double> x, QVector<double> y, QString
|
|||
if(x.size()<m_iSplitNum)
|
||||
{
|
||||
graph->setData(x, y);
|
||||
replot();
|
||||
//replot(QCustomPlot::rpRefreshHint);// 仅刷新可见部分,跳过轴计算等
|
||||
// ===== 性能优化: 批量模式下跳过 replot, 由 endBatchLoad() 统一刷新 =====
|
||||
if (!m_bBatchMode) {
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
graph->setData(x.mid(0,m_iSplitNum), y.mid(0,m_iSplitNum));
|
||||
replot();
|
||||
if (!m_bBatchMode) {
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
|
||||
m_iCurNum = m_iSplitNum;
|
||||
QTimer::singleShot(100, this, SLOT(slot_time()));
|
||||
if (!m_bBatchMode) {
|
||||
QTimer::singleShot(100, this, SLOT(slot_time()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ===== 性能优化: 批量加载模式实现 =====
|
||||
void QMyCustomPlot::beginBatchLoad()
|
||||
{
|
||||
m_bBatchMode = true;
|
||||
}
|
||||
|
||||
void QMyCustomPlot::endBatchLoad()
|
||||
{
|
||||
m_bBatchMode = false;
|
||||
// 一次性 replot, 使用队列刷新合并同一事件循环中的多次调用
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
|
||||
void QMyCustomPlot::slot_time()
|
||||
{
|
||||
if(m_iCurNum >= m_showX.size())
|
||||
|
|
@ -10885,13 +10923,12 @@ void QMyCustomPlot::updateCurveConBackAndForth()
|
|||
if (m_showX.size() < m_iSplitNum)
|
||||
{
|
||||
graph->setData(m_showX, m_showY);
|
||||
replot();
|
||||
//replot(QCustomPlot::rpRefreshHint);// 仅刷新可见部分,跳过轴计算等
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
}
|
||||
else
|
||||
{
|
||||
graph->setData(m_showX.mid(0, m_iSplitNum), m_showY.mid(0, m_iSplitNum));
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
|
||||
m_iCurNum = m_iSplitNum;
|
||||
QTimer::singleShot(100, this, SLOT(slot_time()));
|
||||
|
|
@ -10979,7 +11016,7 @@ void QMyCustomPlot::updateCurveTwoBackAndForth()
|
|||
else
|
||||
graph->setVisible(false);
|
||||
graph->setData(tmpRightX, tmpRightY);
|
||||
replot();
|
||||
replot(QCustomPlot::rpQueuedReplot);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,6 +87,11 @@ public:
|
|||
|
||||
void initGeometry(QString strUuid, int nscale, double fW);
|
||||
|
||||
// ===== 性能优化: 批量加载模式 =====
|
||||
void beginBatchLoad(); // 开始批量加载, 抑制中间 replot
|
||||
void endBatchLoad(); // 结束批量加载, 一次性 replot
|
||||
bool isBatchMode() const { return m_bBatchMode; }
|
||||
|
||||
void groupBeginResult(float fEndDepth, float fStartDepth);
|
||||
void groupEndResult();
|
||||
|
||||
|
|
@ -223,6 +228,7 @@ public:
|
|||
//分段刷新
|
||||
int m_iSplitNum=2000000; //2000;
|
||||
bool m_addRandomGraph=false;//当前是否绘制曲线 true:是。
|
||||
bool m_bBatchMode = false; // 批量加载模式, 抑制中间 replot
|
||||
bool m_bEditRect=false; //当前是否正在编辑曲线。
|
||||
bool m_bFirstTimeConnect=true; //初次绑定编辑曲线信号槽。
|
||||
bool m_bPriviewRightList=false; //当前是否正在预览曲线。
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user