1.新建或打开项目,会提醒保存旧视图,并关闭打开的tab页。 2.支持导出长图、PDF、SVG。
This commit is contained in:
parent
be04da0bff
commit
963b1c9653
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui svg
|
||||
QT += core gui svg printsupport
|
||||
#QT += opengl
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
|
|
|||
|
|
@ -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>("QPoint");
|
||||
|
||||
MainWindow w;
|
||||
g_mainWindow = &w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
|
|
|
|||
|
|
@ -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; i<iCount; i++)
|
||||
{
|
||||
QWidget *selectWidget = m_centerWidgets->tabWidget(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; i<iCount; i++)
|
||||
{
|
||||
m_centerWidgets->removeTab(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; i<iCount; i++)
|
||||
// {
|
||||
// m_centerWidgets->removeTab(0);
|
||||
// }
|
||||
// }
|
||||
if(m_centerWidgets)
|
||||
{
|
||||
int iCount = m_centerWidgets->count();
|
||||
for(int i=0; i<iCount; i++)
|
||||
{
|
||||
m_centerWidgets->removeTab(0);
|
||||
}
|
||||
}
|
||||
//关闭老项目
|
||||
g_prjname="";
|
||||
}
|
||||
|
||||
//参数卡数据查看
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@
|
|||
#include "DepPairs.h"
|
||||
#include "mainwindowsplitter.h"
|
||||
#include "selectwelldialog.h"
|
||||
#include "mainwindow.h"
|
||||
#include <QSvgGenerator>
|
||||
|
||||
//主窗口,为了方便获取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);
|
||||
|
|
@ -237,8 +249,9 @@ void MainWindowCurve::initMainToolBar()
|
|||
ui->mainToolBar->addAction(m_executeDepthShiftAc);
|
||||
ui->mainToolBar->addAction(m_joindepthAc);
|
||||
ui->mainToolBar->addAction(m_ModuleOpenAc);
|
||||
|
||||
//ui->mainToolBar->addAction(m_SaveAsPictureAc);//导出长图
|
||||
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; i<ui->tableWidget_2->rowCount(); i++)
|
||||
{
|
||||
//高度
|
||||
iHight += ui->tableWidget_2->rowHeight(i);
|
||||
}
|
||||
|
||||
for(int j=0; j<ui->tableWidget_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; j<ui->tableWidget_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; j<ui->tableWidget_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)
|
||||
|
|
|
|||
|
|
@ -244,6 +244,8 @@ public slots:
|
|||
void s_ExecuteMerge(); //拼接
|
||||
void s_ModuleOpen(); //处理算法
|
||||
void s_SaveAsPicture(); //导出长图
|
||||
void s_SaveAsPdf(); //导出PDF
|
||||
void s_SaveAsSvg(); //导出SVG
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user