优化模板曲线加载速度,采用分块刷新
This commit is contained in:
parent
6c4f311dfc
commit
c380f9006f
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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<QWidget *>(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<double> x, QVector<double> 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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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; i<columnCount; i++)
|
||||
{
|
||||
if( ui->tableWidget->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()
|
||||
{
|
||||
// 创建根对象
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#-------------------------------------------------
|
||||
|
||||
QT += core gui svg
|
||||
|
||||
#QT += opengl
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = logPlus
|
||||
|
|
|
|||
|
|
@ -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) :
|
||||
|
|
|
|||
|
|
@ -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; i<columnCount; i++)
|
||||
{
|
||||
if(i%2==0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
//空白列
|
||||
continue;
|
||||
}
|
||||
|
||||
//progressBar->setValue(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<int, int> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<double> x, QVector<double> 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()<m_iSplitNum)
|
||||
{
|
||||
graph()->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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,21 @@ public:
|
|||
QContextMenuEvent *m_event;
|
||||
|
||||
bool m_bDrawRect = true;
|
||||
|
||||
public:
|
||||
//分段刷新
|
||||
QVector<double> m_x;
|
||||
QVector<double> m_y;
|
||||
int m_iCurNum=0;
|
||||
int m_iSplitNum=2000; //2000000; //2000;
|
||||
public slots:
|
||||
void slot_time();
|
||||
|
||||
public:
|
||||
void init(QString strName, QVector<double> x, QVector<double> y);
|
||||
void addImageToPlot(double left_Low, double right_Hight, const QString imagePath);
|
||||
void addRandomGraph(QVector<double> x, QVector<double> 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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user