优化分页打印出图

This commit is contained in:
jiayulong 2026-04-17 17:59:52 +08:00
parent c1c0b72e17
commit d78bc38a27
9 changed files with 216 additions and 36 deletions

View File

@ -3198,8 +3198,8 @@ void FormDraw::setRowHeight(double dHight, QProgressBar *progressBar, int iSplit
QMyCustomPlot *form = (QMyCustomPlot*)childWidget;
if(form)
{
//jyl int nw = form->geometry().width();
//jyl form->setGeometry(0, 0, nw, (int)dHight);
int nw = form->geometry().width();
form->setGeometry(0, 0, nw, (int)dHight);
form->updateDepthY(m_iY1, m_iY2);
//emit CallManage::getInstance()->sig_ChangeLeftScale(m_strUuid, form->m_strSlfName, m_strWellName, m_strTrackName, form->m_strLineName, form->m_iX1);

View File

@ -708,7 +708,7 @@ void FormWell::setRowHeight(double dHight, QProgressBar *progressBar, int iSplit
//int iHeightOfRow = ui->tableWidget->rowHeight(2);
//设置高度
//jyl ui->tableWidget->setRowHeight(2, (int)dHight);//7582
ui->tableWidget->setRowHeight(2, (int)iHeightOfScreen+5);
ui->tableWidget->m_iScale = m_iScale;
ui->tableWidget->m_strUuid = m_strUuid;

View File

@ -24,7 +24,7 @@
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QMyTableWidget" name="tableWidget"/>

View File

@ -49,6 +49,12 @@ int g_iHeight_MyCustom = 0;
int g_WorkSpace_Width = 0;
int g_WorkSpace_Height = 0;
//Debug
int g_iDebug = 0;
//SmallPrint
int g_iSmallPrint = 0;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
@ -161,9 +167,19 @@ void MainWindow::ReadConfig()
g_iShow = iShow;
//读取,MyCustom界面高度
int iHeight = 0;
qtCommon->readHeight(configPath, iHeight);
int iHeight = 1;
//qtCommon->readHeight(configPath, iHeight);
g_iHeight_MyCustom = iHeight;
//Debug模式
int iDebug = 0;
qtCommon->readDebug(configPath, iDebug);
g_iDebug = iDebug;
//Small模式出图的原始图片是否采用小图片(默认0:大图--缺点出图时占用内存大, 1:小图--缺点小图拼接容易有缝隙)
int iSmallPrint = 0;
qtCommon->readSmallPrint(configPath, iSmallPrint);
g_iSmallPrint = iSmallPrint;
}
void MainWindow::loadStyle(const QString &qssFile)

View File

@ -45,6 +45,11 @@ extern int g_SelectWellIndex;
extern int g_iHeight_MyCustom;
extern int g_WorkSpace_Height;
extern int g_iDebug;
//SmallPrint
extern int g_iSmallPrint;
MainWindowCurve::MainWindowCurve(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindowCurve)
@ -2150,7 +2155,7 @@ QStringList MainWindowCurve::insertCol(int nW)
QString strWellName = ui->tableWidget_2->item(0, column)->text();
//设置列宽
ui->tableWidget_2->setColumnWidth(column, iWidth+nW*g_dPixelPerCm+8);
ui->tableWidget_2->setColumnWidth(column, iWidth+nW*g_dPixelPerCm);
sret << strWellName << strSlfName;
@ -2389,7 +2394,7 @@ void MainWindowCurve::s_SaveAsPicture()
//
QString dir=pdfName;
QString pngName =QFileDialog::getSaveFileName( NULL,"输出为图片",dir,
"图像文件(*.tif);;图像文件(*.png);;图像文件(*.jpg);;图像文件(*.bmp);;图像文件(*.xpm)");
"图像文件(*.tif);;图像文件(*.png);;图像文件(*.jpg);;图像文件(*.bmp)");
if(pngName=="") {
return;
}
@ -2545,13 +2550,24 @@ bool MainWindowCurve::saveMultipageTiff(const QList<QImage> images, const QStrin
// =4 to svg
void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName, QString strTmpName)
{
//Small模式出图的原始图片是否采用小图片(默认0:大图--缺点出图时占用内存大, 1:小图--缺点小图拼接容易有缝隙)
if(g_iSmallPrint==0)
{
//首先调整为最大图,减少打印空隙
//MyCustom界面高度g_iHeight_MyCustom的值 (0:采用最大30000像素高度 1:采用屏幕工作区域高度, 其他数字高度采用g_iHeight_MyCustom的值)
g_iHeight_MyCustom = 0;
//打印出图,改变深度
changeDepthForPrint();
}
printer.setPageMargins(0.0,0.0,0.0,0.0,QPrinter::DevicePixel);
printer.setFullPage(true);
//临时存储图片
QString tmpPath = GetLogdataPath();
tmpPath = tmpPath + g_prjname;
if(strTmpName != "")
if(strTmpName != "" && g_iDebug)
{
tmpPath=tmpPath + "/" + strTmpName +"/";
tmpPath += QDateTime::currentDateTime().toString("yyyyMMddHHmmsszzz");
@ -2646,7 +2662,10 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
m_dock1->setGeometry(geoRect_Head.x(), geoRect_Head.y(), iMaxWidth, iHight_Head);
QPixmap pPixmap_Head = this->grab(QRect(geoRect_Head.x(), geoRect_Head.y(), iMaxWidth, iHight_Head));
//保存,方便查看
pPixmap_Head.save(tmpPath + "pPixmap_Head.png");
if(g_iDebug)
{
pPixmap_Head.save(tmpPath + "pPixmap_Head.png");
}
//尾
m_dock1->hide();
@ -2656,7 +2675,10 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
m_dock2->setGeometry(geoRect_Tail.x(), geoRect_Tail.y(), iMaxWidth, iHight_Tail);
QPixmap pPixmap_Tail = this->grab(QRect(geoRect_Tail.x(), geoRect_Tail.y(), iMaxWidth, iHight_Tail));
//保存,方便查看
pPixmap_Tail.save(tmpPath + "pPixmap_Tail.png");
if(g_iDebug)
{
pPixmap_Tail.save(tmpPath + "pPixmap_Tail.png");
}
//打印页数------------------------------
int iHeightOfScreen = 30000;//QApplication::desktop()->height();
@ -2701,7 +2723,7 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
int iTableSize_Head = 0;
getTableSize_Head(iTableSize_Head);
//
int iTableWellTrack_height = ui->tableWidget_2->rowHeight(0) + (9+4) + iTableSize_Head +1;
int iTableWellTrack_height = ui->tableWidget_2->rowHeight(0) + (9+3) + iTableSize_Head;
//图片高度
int iTotalSize_Height = iHight_Head+iHight_Tail;
int iNum = dDeep/dScrollHeight;
@ -2767,7 +2789,10 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), iMaxWidth, iHight+40);
QPixmap pPixmap_wellTrackInfo = this->grab(QRect(geoRect.x(), geoRect.y(), iMaxWidth, iTableWellTrack_height));
//保存,方便查看
pPixmap_wellTrackInfo.save(tmpPath + "0.png");
if(g_iDebug)
{
pPixmap_wellTrackInfo.save(tmpPath + "0.png");
}
if(IsBmp == 0 || IsBmp == 4)
{
//pdf,svg
@ -2778,6 +2803,7 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
images.append(convertToQImage(pPixmap_wellTrackInfo)); // 将QPixmap转换为QImage并存储到列表中
}
//int iPreH = 6;
int iLoop = 0;
for(iLoop = 0; iLoop<iNum; iLoop++)
{
@ -2788,23 +2814,26 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
double newValue = -m_iY2 + dScrollHeight*iLoop;
if(newValue < -m_iY1)
{
double tmp = newValue*100.0/(double)m_iScale * g_dPixelPerCm;
if(tmp>1)
{
newValue = (tmp-1)/g_dPixelPerCm/100.0 * (double)m_iScale;
}
// double tmp = newValue*100.0/(double)m_iScale * g_dPixelPerCm;
// if(tmp>1)
// {
// newValue = (tmp-iPreH*iLoop)/g_dPixelPerCm/100.0 * (double)m_iScale;
// }
ui->verticalScrollBar->setValue(newValue);//设置右侧滚动条
if(iLoop==iNum-1)
{
//最后1页
ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), iMaxWidth, iHight+40);
QPixmap pPixmap = this->grab(QRect(geoRect.x(), geoRect.y()+iTableWellTrack_height, iMaxWidth, dLastHeight-4));
QPixmap pPixmap = this->grab(QRect(geoRect.x(), geoRect.y()+iTableWellTrack_height, iMaxWidth, dLastHeight-2));
//保存,方便查看
pPixmap.save(tmpPath + QString::number(iLoop+1) + ".png");
if(g_iDebug)
{
pPixmap.save(tmpPath + QString::number(iLoop+1) + ".png");
}
if(IsBmp == 0 || IsBmp == 4)
{
//pdf,svg
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height + (iHeightOfScreen-4)*iLoop, pPixmap);
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height + (iHeightOfScreen-2)*iLoop, pPixmap);
}
else
{
@ -2813,13 +2842,16 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
}
else{
ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), iMaxWidth, iHight+40);
QPixmap pPixmap = this->grab(QRect(geoRect.x(), geoRect.y()+iTableWellTrack_height, iMaxWidth, iHeightOfScreen-4));
QPixmap pPixmap = this->grab(QRect(geoRect.x(), geoRect.y()+iTableWellTrack_height, iMaxWidth, iHeightOfScreen-2));
//保存,方便查看
pPixmap.save(tmpPath + QString::number(iLoop+1) + ".png");
if(g_iDebug)
{
pPixmap.save(tmpPath + QString::number(iLoop+1) + ".png");
}
if(IsBmp == 0 || IsBmp == 4)
{
//pdf,svg
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height + (iHeightOfScreen-4)*iLoop, pPixmap);
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height + (iHeightOfScreen-2)*iLoop, pPixmap);
}
else
{
@ -2836,9 +2868,9 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
mDepthProgress.SetShowName(s);
mDepthProgress.SetDepth(iNumShow+2);
//
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height + (iHeightOfScreen-4)*(iNum-1) + (dLastHeight-4), pPixmap_wellTrackInfo);
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height + (iHeightOfScreen-2)*(iNum-1) + (dLastHeight-2), pPixmap_wellTrackInfo);
//尾
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height*2 + (iHeightOfScreen-4)*(iNum-1) + (dLastHeight-4), pPixmap_Tail);
painter.drawPixmap(0, iHight_Head + iTableWellTrack_height*2 + (iHeightOfScreen-2)*(iNum-1) + (dLastHeight-2), pPixmap_Tail);
//结束
painter.end();
}
@ -2908,6 +2940,17 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName,
//
mDepthProgress.DelProgress();
//Small模式出图的原始图片是否采用小图片(默认0:大图--缺点出图时占用内存大, 1:小图--缺点小图拼接容易有缝隙)
if(g_iSmallPrint==0)
{
//恢复调整为最小图,减少卡顿
//MyCustom界面高度g_iHeight_MyCustom的值 (0:采用最大30000像素高度 1:采用屏幕工作区域高度, 其他数字高度采用g_iHeight_MyCustom的值)
g_iHeight_MyCustom = 1;
//打印出图,改变深度
changeDepthForPrint();
}
ui->verticalScrollBar->setValue(-m_iY2);//设置右侧滚动条
if(bOK)
{
QMessageBox::information(NULL,"提示","图件输出完成!",QMessageBox::Ok);
@ -3149,13 +3192,25 @@ void MainWindowCurve::s_NewWell(QString strWellName, QString strSlfName)
//jyl ui->tableWidget_2->setRowHeight(i, (int)dHight);
// 屏幕高度
int iHeightOfScreen = 30000;//QApplication::desktop()->height();
if(g_iHeight_MyCustom == 0)
{
iHeightOfScreen = 30000;
}
else if(g_iHeight_MyCustom == 1)
{
iHeightOfScreen = g_WorkSpace_Height;
}
else
{
iHeightOfScreen = g_iHeight_MyCustom;
}
//
//获取井well前2行的高度
int iTableSize_Head = 100 + 300;
//此处还没有生成well所以不能这样获取
//getTableSize_Head(iTableSize_Head);
//
ui->tableWidget_2->setRowHeight(i, (int)iHeightOfScreen+iTableSize_Head+(3+1));
ui->tableWidget_2->setRowHeight(i, (int)iHeightOfScreen+iTableSize_Head+(3+1)+10);
//
FormWell *widgetWell = new FormWell(this, strWellName);
widgetWell->setBorderFlags(BorderFlags(BottomBorder | LeftBorder | RightBorder));
@ -4366,7 +4421,7 @@ void MainWindowCurve::s_changeScale(QString strUuid, int iNewScale)
progressBar->setGeometry(100, 100, 500, 30); // 设置进度条的位置和大小
progressBar->setMaximum(100); // 设置最大值为100
progressBar->setValue(0); // 初始值设为0
progressBar->show();
progressBar->hide();
m_iScale = iNewScale;
@ -4441,7 +4496,7 @@ void MainWindowCurve::s_changeDepth(QString strUuid, QString strSlfName, QString
progressBar->setGeometry(100, 100, 500, 30); // 设置进度条的位置和大小
progressBar->setMaximum(100); // 设置最大值为100
progressBar->setValue(0); // 初始值设为0
progressBar->show();
progressBar->hide();
m_iY1 = iY1;
m_iY2 = iY2;
@ -4520,6 +4575,86 @@ void MainWindowCurve::s_changeDepth(QString strUuid, QString strSlfName, QString
//update();
}
//打印出图,改变深度
void MainWindowCurve::changeDepthForPrint()
{
QProgressBar *progressBar = new QProgressBar(this);
progressBar->setGeometry(100, 100, 500, 30); // 设置进度条的位置和大小
progressBar->setMaximum(100); // 设置最大值为100
progressBar->setValue(0); // 初始值设为0
progressBar->hide();
double dHight = 0;
dHight = (m_iY2-m_iY1)*100.0/(double)m_iScale * g_dPixelPerCm;
if(g_iShow==1)
{
//显示刻度
dHight = dHight+30;
}
if(dHight>32767)
{
dHight = 32767;
}
//--------------------
//
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;
}
if( ui->tableWidget_2->cellWidget(1, i) != nullptr )
{
auto myWidget = ui->tableWidget_2->cellWidget(1, i);
if(myWidget)
{
//
FormWell *widgetWell = (FormWell*)myWidget;//获得widget
if(widgetWell)
{
widgetWell->setRowHeight(dHight, progressBar, iSplit);
}
}
}
}
// 屏幕高度
int iHeightOfScreen = 30000;//QApplication::desktop()->height();
if(g_iHeight_MyCustom == 0)
{
iHeightOfScreen = 30000;
}
else if(g_iHeight_MyCustom == 1)
{
iHeightOfScreen = g_WorkSpace_Height;
}
else
{
iHeightOfScreen = g_iHeight_MyCustom;
}
//
//获取井well前2行的高度
int iTableSize_Head = 100 + 300;
//此处还没有生成well所以不能这样获取
//getTableSize_Head(iTableSize_Head);
//
ui->tableWidget_2->setRowHeight(1, (int)iHeightOfScreen+iTableSize_Head+(3+1)+10);
//update();
//
progressBar->deleteLater();
}
void MainWindowCurve::s_changeWellProperty(QString strSlfName, QString strWellName, QVariantList listVal)
{
FormWell* pWell = m_mapFWell.value(strWellName);

View File

@ -252,7 +252,8 @@ public slots:
void s_SaveAsSvg(); //导出SVG
//
void _slotExport(QPrinter &printer, int IsBmp, QString pngName, QString strTmpName);
//打印出图,改变深度
void changeDepthForPrint();
};
#endif // MAINWINDOWCURVE_H

View File

@ -10127,13 +10127,15 @@ void QMyCustomPlot::resetPosition_SwallCore()
//--------------------------
// 设置初始范围
//double h = 32;
double Depth1 = tmpRange.lower;
double Depth2 = tmpRange.upper;
double tmpDepth1 = tmpRange.lower;
double tmpDepth2 = tmpRange.upper;
// double x1 = this->xAxis->coordToPixel(Depth);
// double Depth2 = this->xAxis->pixelToCoord(x1-h);
//--------------------------
// 设置初始范围
double h = SideWallCoreHeight * g_dPixelPerCm; //0.4cm //40;//32;
double x1 = this->xAxis->coordToPixel((tmpDepth1+tmpDepth2)/2.0);
//
double Depth1 = this->xAxis->pixelToCoord(x1+h/2.0);
double Depth2 = this->xAxis->pixelToCoord(x1-h/2.0);
//
pDraggableRect->setRange(Depth1, Depth2, false);

View File

@ -24,6 +24,28 @@ QString QtCommonClass::getUUid()
return strId;
}
//
double QtCommonClass::readSmallPrint(QString filePathName, int &iSmallPrint)
{
QSettings set(filePathName, QSettings::IniFormat);
set.beginGroup("config");
iSmallPrint = set.value("iSmallPrint", "0").toInt();
set.endGroup();
return 0;
}
//读取Debug模式
double QtCommonClass::readDebug(QString filePathName, int &iDebug)
{
QSettings set(filePathName, QSettings::IniFormat);
set.beginGroup("config");
iDebug = set.value("iDebug", "0").toInt();
set.endGroup();
return 0;
}
//读取,MyCustom界面高度
double QtCommonClass::readHeight(QString filePathName, int &iHeight)
{

View File

@ -21,6 +21,10 @@ public:
double readShowScale(QString filePathName, int &iShow);
//读取,MyCustom界面高度
double readHeight(QString filePathName, int &iHeight);
//Debug模式记录出图的原始图片
double readDebug(QString filePathName, int &iDebug);
//Small模式出图的原始图片是否采用小图片(默认0:大图--缺点出图时占用内存大, 1:小图--缺点小图拼接容易有缝隙)
double readSmallPrint(QString filePathName, int &iSmallPrint);
double readXyRange(QString filePathName, int &iX1, int &iX2, int &iY1, int &iY2);