From 963b1c9653b1ecc93911f9e16b28ef92f4df1a06 Mon Sep 17 00:00:00 2001 From: jiayulong Date: Wed, 1 Apr 2026 18:08:00 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=BB=BA=E6=88=96=E6=89=93=E5=BC=80?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=EF=BC=8C=E4=BC=9A=E6=8F=90=E9=86=92=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=97=A7=E8=A7=86=E5=9B=BE=EF=BC=8C=E5=B9=B6=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=89=93=E5=BC=80=E7=9A=84tab=E9=A1=B5=E3=80=82=202.?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AF=BC=E5=87=BA=E9=95=BF=E5=9B=BE=E3=80=81?= =?UTF-8?q?PDF=E3=80=81SVG=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/logPlus.pro | 2 +- logPlus/main.cpp | 3 + logPlus/mainwindow.cpp | 95 ++++++++++++-- logPlus/mainwindow.h | 5 +- logPlus/mainwindowcurve.cpp | 237 ++++++++++++++++++++++++++++++++++- logPlus/mainwindowcurve.h | 2 + logPlus/qtprojectwidgets.cpp | 5 +- 7 files changed, 326 insertions(+), 23 deletions(-) diff --git a/logPlus/logPlus.pro b/logPlus/logPlus.pro index 509081f..cd57fde 100644 --- a/logPlus/logPlus.pro +++ b/logPlus/logPlus.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui svg +QT += core gui svg printsupport #QT += opengl greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/logPlus/main.cpp b/logPlus/main.cpp index 38594fe..bae95d1 100644 --- a/logPlus/main.cpp +++ b/logPlus/main.cpp @@ -5,6 +5,8 @@ double g_logicalDpi; double g_dPixelPerCm;//每厘米像素数 +MainWindow *g_mainWindow = nullptr; + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -34,6 +36,7 @@ int main(int argc, char *argv[]) //qRegisterMetaType("QPoint"); MainWindow w; + g_mainWindow = &w; w.show(); return a.exec(); diff --git a/logPlus/mainwindow.cpp b/logPlus/mainwindow.cpp index 3e9cc99..23007fa 100644 --- a/logPlus/mainwindow.cpp +++ b/logPlus/mainwindow.cpp @@ -106,6 +106,21 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::closeEvent(QCloseEvent *event) +{ + //关闭老项目 + bool bClosed = closeProject(); + if(!bClosed) + { + if(event) + { + event->ignore(); + } + return; + } + QMainWindow::closeEvent( event ); +} + void MainWindow::ReadConfig() { int iIndex; @@ -145,10 +160,7 @@ void MainWindow::ReadConfig() qtCommon->readShowScale(configPath, iShow); g_iShow = iShow; } -CallManage* MainWindow::getInstanceCallManage() -{ - return CallManage::getInstance(); -} + void MainWindow::loadStyle(const QString &qssFile) { //加载样式表 @@ -339,13 +351,69 @@ void MainWindow::dockLayout() m_propertyWidget->InitCurrentViewInfo(); } +//关闭成功返回true +bool MainWindow::closeProject() +{ + //先判断是否需要保存tab页 + bool bNeedSave = false; + if(m_centerWidgets) + { + int iCount = m_centerWidgets->count(); + for(int i=0; itabWidget(i); + QString objectName = selectWidget->objectName(); + if(objectName == "MainWindowSplitter") + { + bNeedSave = true; + break; + } + } + } + if(bNeedSave) + { + int flag = QMessageBox::warning(NULL,"提示",QString("图文件尚未保存,您确信关闭当前窗口?"),QMessageBox::Yes,QMessageBox::No); + if(flag!=QMessageBox::Yes) + { + return false; + } + } + + //关闭老项目 + if(m_centerWidgets) + { + int iCount = m_centerWidgets->count(); + for(int i=0; iremoveTab(0); + } + } + g_prjname=""; + return true; +} + void MainWindow::s_New() { + //关闭老项目 + bool bClosed = closeProject(); + if(!bClosed) + { + return; + } + + //新建 emit CallManage::getInstance()->sig_NewProject(); } void MainWindow::s_Open() { + //关闭老项目 + bool bClosed = closeProject(); + if(!bClosed) + { + return; + } + //打开 QString fileFull = ""; fileFull = QFileDialog::getOpenFileName(this, @@ -544,19 +612,20 @@ void MainWindow::s_DrawLine() qDebug() << "vecSlfList:" << QString::number(i+1) << "=" << vecSlfList[i]; } } - } void MainWindow::s_CloseProject() { -// if(m_centerWidgets) -// { -// int iCount = m_centerWidgets->count(); -// for(int i=0; iremoveTab(0); -// } -// } + if(m_centerWidgets) + { + int iCount = m_centerWidgets->count(); + for(int i=0; iremoveTab(0); + } + } + //关闭老项目 + g_prjname=""; } //参数卡数据查看 diff --git a/logPlus/mainwindow.h b/logPlus/mainwindow.h index 9e630f1..be08393 100644 --- a/logPlus/mainwindow.h +++ b/logPlus/mainwindow.h @@ -60,6 +60,8 @@ public: ConsoleOutputWidget *m_consoleOutputWidget;//日志 public: + virtual void closeEvent(QCloseEvent *event); + //样式 void loadStyle(const QString &qssFile); @@ -71,8 +73,7 @@ public: void dockLayout(); //停靠 void ReadConfig(); - - CallManage *getInstanceCallManage(); + bool closeProject(); public slots: void s_New(); diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index 78e30dc..a99cbc9 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -15,6 +15,11 @@ #include "DepPairs.h" #include "mainwindowsplitter.h" #include "selectwelldialog.h" +#include "mainwindow.h" +#include + +//主窗口,为了方便获取tab当前页 +extern MainWindow *g_mainWindow; extern int g_iOneWidth; //道宽 extern QString g_prjname; @@ -163,6 +168,7 @@ MainWindowCurve::MainWindowCurve(QWidget *parent) : MainWindowCurve::~MainWindowCurve() { + delete ui; } @@ -198,6 +204,8 @@ void MainWindowCurve::initMainToolBar() QIcon joindepthIcon(::GetImagePath()+"icon/joindepth.png"); QIcon ModuleOpenIcon(::GetImagePath()+"icon/ModuleOne.png"); QIcon SaveAsPictureIcon(::GetImagePath()+"icon/SaveAsPicture.png"); + QIcon SaveAsPdfIcon(::GetImagePath()+"icon/ExportPDF.png"); + QIcon SaveAsSvgIcon(::GetImagePath()+"icon/ExportSVG.png"); QIcon runIcon(":/image/capacity.png"); QIcon debugIcon(":/image/anaysis.png"); QIcon loadIcon(":/image/export.png"); @@ -211,6 +219,8 @@ void MainWindowCurve::initMainToolBar() QAction* m_joindepthAc = nullptr; //拼接 QAction* m_ModuleOpenAc = nullptr; //处理方法 QAction* m_SaveAsPictureAc = nullptr; //导出长图 + QAction* m_SaveAsPdfAc = nullptr; //导出PDF + QAction* m_SaveAsSvgAc = nullptr; //导出SVG // QAction* m_runAc = nullptr;// // QAction* m_debugAc = nullptr; // // QAction* m_loadAc = nullptr; //加载 @@ -223,6 +233,8 @@ void MainWindowCurve::initMainToolBar() m_joindepthAc = new QAction(joindepthIcon, "拼接", this); m_ModuleOpenAc = new QAction(ModuleOpenIcon, "处理方法", this); m_SaveAsPictureAc = new QAction(SaveAsPictureIcon, "导出长图", this); + m_SaveAsPdfAc = new QAction(SaveAsPdfIcon, "导出PDF", this); + m_SaveAsSvgAc = new QAction(SaveAsSvgIcon, "导出SVG", this); // m_debugAc = new QAction(debugIcon, "撤销", this); // m_loadAc = new QAction(loadIcon, "重做", this); //m_openAc = new QAction(openFileIcon, "打开", this); @@ -236,9 +248,10 @@ void MainWindowCurve::initMainToolBar() ui->mainToolBar->addAction(m_saveastemplateAc); ui->mainToolBar->addAction(m_executeDepthShiftAc); ui->mainToolBar->addAction(m_joindepthAc); - ui->mainToolBar->addAction(m_ModuleOpenAc); - - //ui->mainToolBar->addAction(m_SaveAsPictureAc);//导出长图 + ui->mainToolBar->addAction(m_ModuleOpenAc); + ui->mainToolBar->addAction(m_SaveAsPictureAc);//导出长图 + ui->mainToolBar->addAction(m_SaveAsPdfAc);//导出PDF + ui->mainToolBar->addAction(m_SaveAsSvgAc);//导出SVG // ui->mainToolBar->addAction(m_debugAc); // ui->mainToolBar->addAction(m_loadAc); @@ -253,6 +266,8 @@ void MainWindowCurve::initMainToolBar() connect(m_ModuleOpenAc, &QAction::triggered, this, &MainWindowCurve::s_ModuleOpen); connect(m_SaveAsPictureAc, &QAction::triggered, this, &MainWindowCurve::s_SaveAsPicture); + connect(m_SaveAsPdfAc, &QAction::triggered, this, &MainWindowCurve::s_SaveAsPdf); + connect(m_SaveAsSvgAc, &QAction::triggered, this, &MainWindowCurve::s_SaveAsSvg); // connect(m_grepAc, &QAction::triggered, this, &MainWindow::s_Risize); // connect(m_compileAc, &QAction::triggered, this, &MainWindow::s_AddOne); @@ -2324,9 +2339,221 @@ void MainWindowCurve::s_ModuleOpen() //导出长图 void MainWindowCurve::s_SaveAsPicture() { + QString strTmpName = ""; + int curIndex = g_mainWindow->m_centerWidgets->currentIndex(); + strTmpName = g_mainWindow->m_centerWidgets->tabText(curIndex); + //去掉后缀.json + int ind=strTmpName.lastIndexOf("."); + if(ind>=0) strTmpName=strTmpName.left(ind); + + // + QString pdfName = GetLogdataPath(); + pdfName = pdfName + g_prjname; + if(strTmpName != "") + { + pdfName=pdfName + "/" + strTmpName +".tif"; + } + + // + QString dir=pdfName; + QString pngName =QFileDialog::getSaveFileName( NULL,"输出为图片",dir, + "图像文件(*.tif);;图像文件(*.png);;图像文件(*.jpg);;图像文件(*.bmp);;图像文件(*.xpm)"); + if(pngName=="") { + return; + } + + // 获取客户区几何信息(不含边框) + QRect geoRect = ui->centralwidget->geometry(); + qDebug() << "Geometry:" << geoRect.x() << "," << geoRect.y() + << "w:" << geoRect.width() << "h:" << geoRect.height(); + + //获取可视视图大小 tableWidget_2 + int iHight = 0; + int iWidth = 0; + for(int i=0; itableWidget_2->rowCount(); i++) + { + //高度 + iHight += ui->tableWidget_2->rowHeight(i); + } + + for(int j=0; jtableWidget_2->columnCount(); j++) + { + //高度 + iWidth += ui->tableWidget_2->columnWidth(j); + } + //指标体系图 - QPixmap pPixmap = ui->tableWidget_2->grab(QRect(0, 0, ui->tableWidget_2->width()*2, ui->tableWidget_2->height()*2)); - pPixmap.save("d:\\3.png", "png"); + ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), iWidth, iHight); + QPixmap pPixmap = ui->centralwidget->grab(QRect(0, 0, ui->centralwidget->width(), ui->centralwidget->height())); + pPixmap.save(pngName); + + //恢复窗口 + ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), geoRect.width(), geoRect.height()); +} + +//导出PDF +void MainWindowCurve::s_SaveAsPdf() +{ + QString strTmpName = ""; + + int curIndex = g_mainWindow->m_centerWidgets->currentIndex(); + strTmpName = g_mainWindow->m_centerWidgets->tabText(curIndex); + //去掉后缀.json + int ind=strTmpName.lastIndexOf("."); + if(ind>=0) strTmpName=strTmpName.left(ind); + + // + QString pdfName = GetLogdataPath(); + pdfName = pdfName + g_prjname; + if(strTmpName != "") + { + pdfName=pdfName + "/" + strTmpName +".pdf"; + } + + // + QString pngName =QFileDialog::getSaveFileName( NULL,"输出为PDF文件",pdfName,"PDF文件(*.pdf)"); + if(pngName=="") { + return; + } + + // 获取客户区几何信息(不含边框) + QRect geoRect = ui->centralwidget->geometry(); + qDebug() << "Geometry:" << geoRect.x() << "," << geoRect.y() + << "w:" << geoRect.width() << "h:" << geoRect.height(); + + //获取可视视图大小 tableWidget_2 + int iHight = 0; + int iWidth = 0; + for(int i=0; i<2; i++) + { + //高度 + iHight += ui->tableWidget_2->rowHeight(i); + } + + for(int j=0; jtableWidget_2->columnCount(); j++) + { + //高度 + iWidth += ui->tableWidget_2->columnWidth(j); + } + + //指标体系图 + ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), iWidth, iHight); + QPixmap pPixmap = ui->centralwidget->grab(QRect(0, 0, ui->centralwidget->width(), ui->centralwidget->height())); + + // + QPrinter printer;//(QPrinter::ScreenResolution); + printer.setOrientation(QPrinter::Portrait); + printer.setResolution(200); + printer.setPaperSize(QPrinter::Custom);//自定义大小 + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setPageMargins(0.0, 0.0, 0.0, 0.0, QPrinter::Point); + printer.setOutputFileName(pngName); + + printer.setPageMargins(0.0,0.0,0.0,0.0,QPrinter::DevicePixel); + printer.setFullPage(true); + + printer.setOrientation(QPrinter::Portrait); + printer.setPaperSize(QPrinter::Custom); + printer.setPaperSize(QSizeF(ui->centralwidget->width(), ui->centralwidget->height()),QPrinter::DevicePixel); + + // + float sx=1; + float sy=1; + QPainter painter; + painter.begin(&printer); + painter.setRenderHint(QPainter::Antialiasing); + painter.scale(sx,sy); + painter.drawPixmap(0, 0, pPixmap); + painter.end(); + + //恢复窗口 + ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), geoRect.width(), geoRect.height()); +} + +//导出长图 +void MainWindowCurve::s_SaveAsSvg() +{ + QString strTmpName = ""; + int curIndex = g_mainWindow->m_centerWidgets->currentIndex(); + strTmpName = g_mainWindow->m_centerWidgets->tabText(curIndex); + //去掉后缀.json + int ind=strTmpName.lastIndexOf("."); + if(ind>=0) strTmpName=strTmpName.left(ind); + + // + QString pdfName = GetLogdataPath(); + pdfName = pdfName + g_prjname; + if(strTmpName != "") + { + pdfName=pdfName + "/" + strTmpName +".svg"; + } + + // + QString dir=pdfName; + QString pngName =QFileDialog::getSaveFileName( NULL,"输出为SVG图",pdfName,"svg图文件(*.svg)"); + if(pngName=="") { + return; + } + + // 获取客户区几何信息(不含边框) + QRect geoRect = ui->centralwidget->geometry(); + qDebug() << "Geometry:" << geoRect.x() << "," << geoRect.y() + << "w:" << geoRect.width() << "h:" << geoRect.height(); + + //获取可视视图大小 tableWidget_2 + int iHight = 0; + int iWidth = 0; + for(int i=0; i<2; i++) + { + //高度 + iHight += ui->tableWidget_2->rowHeight(i); + } + + for(int j=0; jtableWidget_2->columnCount(); j++) + { + //高度 + iWidth += ui->tableWidget_2->columnWidth(j); + } + + //指标体系图 + ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), iWidth, iHight); + QPixmap pPixmap = ui->centralwidget->grab(QRect(0, 0, ui->centralwidget->width(), ui->centralwidget->height())); + + // + QString strTmpPng = pngName; + int indTmp=strTmpPng.lastIndexOf("."); + if(indTmp>=0) strTmpPng=strTmpPng.left(indTmp) + "_tmp.PNG"; + pPixmap.save(strTmpPng); + + QSvgGenerator generator; + generator.setFileName(pngName); // 设置输出SVG文件的路径和名称 + generator.setSize(QSize(ui->centralwidget->width(), ui->centralwidget->height())); // 设置SVG的尺寸,这里使用QPixmap的尺寸 + generator.setViewBox(QRect(0, 0, ui->centralwidget->width(), ui->centralwidget->height())); // 设置视图框,可选,根据需要设置 + + QImage image; + image.load(strTmpPng); + // + float sx=1; + float sy=1; + QPainter painter; + painter.begin(&generator); + painter.setRenderHint(QPainter::Antialiasing); + painter.scale(sx,sy); + //painter.drawPixmap(0, 0, pPixmap); // 绘制QPixmap到SVG中 + painter.drawImage(0, 0, image); + painter.end(); // 结束绘制过程 + +// float sx=1; +// float sy=1; +// QPainter painter; +// painter.begin(&generator); +// painter.setRenderHint(QPainter::Antialiasing); +// painter.scale(sx,sy); +// painter.drawPixmap(0, 0, pPixmap); // 绘制QPixmap到SVG中 +// painter.end(); // 结束绘制过程 + + //恢复窗口 + ui->centralwidget->setGeometry(geoRect.x(), geoRect.y(), geoRect.width(), geoRect.height()); } //void MainWindowCurve::s_Open(QString fileFull) diff --git a/logPlus/mainwindowcurve.h b/logPlus/mainwindowcurve.h index f2d361d..abdd06d 100644 --- a/logPlus/mainwindowcurve.h +++ b/logPlus/mainwindowcurve.h @@ -244,6 +244,8 @@ public slots: void s_ExecuteMerge(); //拼接 void s_ModuleOpen(); //处理算法 void s_SaveAsPicture(); //导出长图 + void s_SaveAsPdf(); //导出PDF + void s_SaveAsSvg(); //导出SVG }; diff --git a/logPlus/qtprojectwidgets.cpp b/logPlus/qtprojectwidgets.cpp index 7154663..2ae571b 100644 --- a/logPlus/qtprojectwidgets.cpp +++ b/logPlus/qtprojectwidgets.cpp @@ -907,8 +907,9 @@ void QtProjectWidgets::onOpenProject(bool checked) void QtProjectWidgets::s_NewProject() { + // ui->treeWidget->clear();//清理数据 - emit CallManage::getInstance()->sig_CloseProject();//关闭tab页 + //emit CallManage::getInstance()->sig_CloseProject();//关闭tab页 // 创建对话框 CWellLogProjectDialog* dialog = new CWellLogProjectDialog(); @@ -936,7 +937,7 @@ void QtProjectWidgets::s_NewProject() void QtProjectWidgets::s_OpenProject(QString fileFull) { ui->treeWidget->clear();//清理数据 - emit CallManage::getInstance()->sig_CloseProject();//关闭tab页 + //emit CallManage::getInstance()->sig_CloseProject();//关闭tab页 s_loadTreeWidget(fileFull); }