2025-05-19T13:58:34
This commit is contained in:
parent
ebfd4a1e88
commit
b117c5e0be
@ -9,7 +9,7 @@ CONFIG+=precompile_header
|
|||||||
PRECOMPILED_HEADER=stable.h
|
PRECOMPILED_HEADER=stable.h
|
||||||
|
|
||||||
#
|
#
|
||||||
VERSION = 0.9.8
|
VERSION = 0.9.8.1
|
||||||
# 设置目标文件名,包含版本号
|
# 设置目标文件名,包含版本号
|
||||||
TARGET = AnalysisTool_$${VERSION}
|
TARGET = AnalysisTool_$${VERSION}
|
||||||
|
|
||||||
|
|||||||
@ -409,7 +409,7 @@ void XlsxHandler::readAnalysisOperation(
|
|||||||
for(int i = 0;i < size; i++){
|
for(int i = 0;i < size; i++){
|
||||||
AnaOpRecorderOperation ao;
|
AnaOpRecorderOperation ao;
|
||||||
|
|
||||||
ao.filePath = cfd.filePath;
|
ao.filePath = cfd.fileName;
|
||||||
|
|
||||||
QString modeStr = sheet->cellAt(startLineIndex, 1)->value().toString();
|
QString modeStr = sheet->cellAt(startLineIndex, 1)->value().toString();
|
||||||
|
|
||||||
|
|||||||
@ -470,8 +470,10 @@ void MainWindow::on_actionEnthalpyCorrectionSelection_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionPrintPreview_triggered()
|
void MainWindow::on_actionPrintPreview_triggered()
|
||||||
{
|
{
|
||||||
_printPreviewForm->setPixmap(_centralWidget->getPixMap());
|
// _printPreviewForm->setPixmap(_centralWidget->getPixMap());
|
||||||
_printPreviewForm->show();
|
// _printPreviewForm->show();
|
||||||
|
|
||||||
|
_printPreviewForm->_customPrintPreviewDialog->showMaximized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionOnsetTemperaturePoint_triggered()
|
void MainWindow::on_actionOnsetTemperaturePoint_triggered()
|
||||||
|
|||||||
@ -167,8 +167,8 @@ void SerialPort::updateStatus(const CommonData &cd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// logde<<"_curveExperimentDataVtr size:"
|
// logde<<"_curveExperimentDataVtr size:"
|
||||||
// <<Global::_curveExperimentDataVtr.size();
|
// <<Global::_curveExperimentDataVtr.size();
|
||||||
|
|
||||||
//
|
//
|
||||||
updateAxis();
|
updateAxis();
|
||||||
@ -403,7 +403,7 @@ void SerialPort::sendCmd(const SerialPort::E_CMD_TYPE e)
|
|||||||
|
|
||||||
char out_char[21] = {'\0'};
|
char out_char[21] = {'\0'};
|
||||||
int hex_length = 10;
|
int hex_length = 10;
|
||||||
to_hex(in_char, hex_length, out_char);
|
toHex(in_char, hex_length, out_char);
|
||||||
|
|
||||||
int num = _sp->write(out_char,
|
int num = _sp->write(out_char,
|
||||||
hex_length);
|
hex_length);
|
||||||
@ -417,7 +417,7 @@ void SerialPort::sendCmd(const SerialPort::E_CMD_TYPE e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialPort::to_hex(char *in_char, int char_length, char *out_char)
|
void SerialPort::toHex(char *in_char, int char_length, char *out_char)
|
||||||
{
|
{
|
||||||
while (char_length--)
|
while (char_length--)
|
||||||
{
|
{
|
||||||
@ -547,11 +547,18 @@ void SerialPort::slotSendData(const QByteArray &ba)
|
|||||||
|
|
||||||
if (_sp != nullptr && _sp->isOpen())
|
if (_sp != nullptr && _sp->isOpen())
|
||||||
{
|
{
|
||||||
_sp->write(ba);
|
int bytesWritten = _sp->write(ba);
|
||||||
|
if (bytesWritten == -1) {
|
||||||
|
logde << "Write failed." << _sp->errorString().toStdString();
|
||||||
|
} else if (bytesWritten != ba.size()) {
|
||||||
|
logde << "Not all data was writen.";
|
||||||
|
} else {
|
||||||
|
logde << "All data writen.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "sp not open.";
|
logde<< "sp not open.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,12 +44,11 @@ public slots:
|
|||||||
void slotCloseSp();
|
void slotCloseSp();
|
||||||
private slots:
|
private slots:
|
||||||
void slotReadData();
|
void slotReadData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateStatus(const CommonData &cd);
|
void updateStatus(const CommonData &cd);
|
||||||
void updateAxis();
|
void updateAxis();
|
||||||
void commonDataParser(const int dataLength, const u16 addr, const CommonData &cd);
|
void commonDataParser(const int dataLength, const u16 addr, const CommonData &cd);
|
||||||
void to_hex(char *in_char, int char_length, char *out_char);
|
void toHex(char *in_char, int char_length, char *out_char);
|
||||||
void displayPortInfo();
|
void displayPortInfo();
|
||||||
private:
|
private:
|
||||||
SerialPort(QObject *parent = nullptr);
|
SerialPort(QObject *parent = nullptr);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ void addAnalysisOperation(const AnalysisOperation ao)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QVector<AnalysisOperation> _ananlysisOperationVtr;
|
QVector<AnalysisOperation> _analysisOperationVtr;
|
||||||
|
|
||||||
void removeTheLastAnalysisOperation()
|
void removeTheLastAnalysisOperation()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -310,7 +310,7 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &filePath)
|
|||||||
// Add analysis operation data.
|
// Add analysis operation data.
|
||||||
if(cfd.analysisOperationVtr.size() > 0){
|
if(cfd.analysisOperationVtr.size() > 0){
|
||||||
for(AnaOpRecorder::AnalysisOperation& ao
|
for(AnaOpRecorder::AnalysisOperation& ao
|
||||||
:AnalysisOperationRecorder::_analysisOperationVtr){
|
:cfd.analysisOperationVtr){
|
||||||
loadAnalysisData(ao.mode,ao.x1,ao.x2);
|
loadAnalysisData(ao.mode,ao.x1,ao.x2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,167 +337,14 @@ void CentralWidget::slotAnalysisSettingApply()
|
|||||||
//
|
//
|
||||||
loadAnalysisData(_analysisMode,x1,x2);
|
loadAnalysisData(_analysisMode,x1,x2);
|
||||||
|
|
||||||
//
|
if(Global::_mode == Global::Mode::Analysis){
|
||||||
#if 0
|
AnalysisOperation ao;
|
||||||
switch (_analysisMode) {
|
ao.mode = _analysisMode;
|
||||||
case AnalysisMode::NumericalLabel:
|
|
||||||
{
|
|
||||||
QPointF selectPoint = PointCalculate::getClosestPointByX(x1);
|
|
||||||
|
|
||||||
// logde<<"lin1 x:"<<x1;
|
|
||||||
|
|
||||||
if(selectPoint.isNull()){
|
|
||||||
QMessageBox::warning((QWidget*)this->parent(), "warnning", "曲线选择错误.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString str = PointCalculate::textFormatNumbericalLabel(selectPoint);
|
|
||||||
|
|
||||||
drawText(selectPoint,str);
|
|
||||||
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnaOpRecorder::NumericalLabel;
|
|
||||||
ao.x1 = x1;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AnalysisMode::StartPoint:
|
|
||||||
case AnalysisMode::StopPoint:{
|
|
||||||
PointCalculate::setRegionPointX(x1,x2);
|
|
||||||
|
|
||||||
QPair<QPointF, QPointF> startEndPointPair =
|
|
||||||
PointCalculate::calculateStartAndEndPoint();
|
|
||||||
//
|
|
||||||
QPointF point;
|
|
||||||
QString str;
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
|
|
||||||
if(_analysisMode == AnalysisMode::StartPoint){
|
|
||||||
point = startEndPointPair.first;
|
|
||||||
str = PointCalculate::textFormatStartPoint(point);
|
|
||||||
ao.mode = AnaOpRecorder::StartPoint;
|
|
||||||
}else{
|
|
||||||
point = startEndPointPair.second;
|
|
||||||
str = PointCalculate::textFormatEndPoint(point);
|
|
||||||
ao.mode = AnaOpRecorder::StopPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawText(point,str);
|
|
||||||
//
|
|
||||||
ao.x1 = x1;
|
ao.x1 = x1;
|
||||||
ao.x2 = x2;
|
ao.x2 = x2;
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
AnaOpRecorder::_analysisOperationVtr.push_back(ao);
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case AnalysisMode::PeakSynthesisAnalysis:
|
|
||||||
{
|
|
||||||
fillGraph(x1,x2);
|
|
||||||
|
|
||||||
PointCalculate::setRegionPointX(x1,x2);
|
|
||||||
|
|
||||||
//enthalpy
|
|
||||||
double sampleWeight = 0.0f;
|
|
||||||
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
|
|
||||||
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
|
|
||||||
if(_currentCurve && _currentCurve == pti.curve){
|
|
||||||
sampleWeight = cfd.ei.sampleWeight.toDouble();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// logde<<"sample weight:"<<sampleWeight;
|
|
||||||
|
|
||||||
double enthalpyValue = PointCalculate::calculateArea() / sampleWeight;
|
|
||||||
|
|
||||||
// peak
|
|
||||||
QPointF peakPoint = PointCalculate::getPeakPoint();
|
|
||||||
|
|
||||||
// start point and end point
|
|
||||||
QPair<QPointF, QPointF> startEndPointPair =
|
|
||||||
PointCalculate::calculateStartAndEndPoint();
|
|
||||||
|
|
||||||
logde<<"start,end:"<<startEndPointPair.first.x()<<","
|
|
||||||
<<startEndPointPair.second.x();
|
|
||||||
|
|
||||||
QString str;
|
|
||||||
if(Global::_displayTimeValue){
|
|
||||||
double peakPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(peakPoint.x());
|
|
||||||
double startPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.first.x());
|
|
||||||
double endPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.second.x());
|
|
||||||
|
|
||||||
str = PointCalculate::textFormatPeakPointWithTime(
|
|
||||||
enthalpyValue,
|
|
||||||
peakPointTime,
|
|
||||||
startPointTime,
|
|
||||||
endPointTime);
|
|
||||||
drawText(peakPoint,str);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
str = PointCalculate::textFormatPeakPoint(enthalpyValue,
|
|
||||||
peakPoint.x(),
|
|
||||||
startEndPointPair.first.x(),
|
|
||||||
startEndPointPair.second.x());
|
|
||||||
drawText(peakPoint,str);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnaOpRecorder::PeakSynthesisAnalysis;
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AnalysisMode::GlassTransition:
|
|
||||||
{
|
|
||||||
glassTransitionHandle(x1,x2);
|
|
||||||
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnaOpRecorder::GlassTransition;
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AnalysisMode::OnsetTemperaturePoint:{
|
|
||||||
#if 0
|
|
||||||
QPointF point = OnsetTemperaturePointHandle(x1,x2);
|
|
||||||
|
|
||||||
QString str = QString::number(point.y(),'f',3);
|
|
||||||
|
|
||||||
drawText(point,str);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QPointF point = OnsetTemperaturePointHandle(x1,x2);
|
|
||||||
QString str = QString::number(point.x(),'f',3);
|
|
||||||
drawText(point,str);
|
|
||||||
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnaOpRecorder::OnsetTemperaturePoint;
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AnalysisMode::EndsetTemperaturePoint:{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CentralWidget::slotAnalysisSettingConfirm()
|
void CentralWidget::slotAnalysisSettingConfirm()
|
||||||
@ -1074,7 +921,7 @@ void CentralWidget::clearData(const CentralWidget::ClearDataMode mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
AnalysisOperationRecorder::_ananlysisOperationVtr.clear();
|
AnalysisOperationRecorder::_analysisOperationVtr.clear();
|
||||||
|
|
||||||
}else if(mode == ClearDataMode::Undo){
|
}else if(mode == ClearDataMode::Undo){
|
||||||
// Clear the data of graph.
|
// Clear the data of graph.
|
||||||
@ -1123,12 +970,8 @@ void CentralWidget::clearData(const CentralWidget::ClearDataMode mode)
|
|||||||
_customPlot->replot();
|
_customPlot->replot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CentralWidget::loadAnalysisData(const AnalysisOperation ao)
|
void CentralWidget::loadAnalysisData(const AnalysisMode mode,const double x1,const double x2)
|
||||||
{
|
{
|
||||||
if(Global::_mode == Global::Mode::Analysis){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case AnalysisMode::NumericalLabel:
|
case AnalysisMode::NumericalLabel:
|
||||||
{
|
{
|
||||||
@ -1145,13 +988,6 @@ void CentralWidget::loadAnalysisData(const AnalysisOperation ao)
|
|||||||
|
|
||||||
drawText(selectPoint,str);
|
drawText(selectPoint,str);
|
||||||
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnalysisMode::NumericalLabel;
|
|
||||||
ao.x1 = x1;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AnalysisMode::StartPoint:
|
case AnalysisMode::StartPoint:
|
||||||
@ -1165,22 +1001,16 @@ void CentralWidget::loadAnalysisData(const AnalysisOperation ao)
|
|||||||
QString str;
|
QString str;
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
AnaOpRecorder::AnalysisOperation ao;
|
||||||
|
|
||||||
if(_analysisMode == AnalysisMode::StartPoint){
|
if(mode == AnalysisMode::StartPoint){
|
||||||
point = startEndPointPair.first;
|
point = startEndPointPair.first;
|
||||||
str = PointCalculate::textFormatStartPoint(point);
|
str = PointCalculate::textFormatStartPoint(point);
|
||||||
ao.mode = Global::AnalysisMode::StartPoint;
|
|
||||||
}else{
|
}else{
|
||||||
point = startEndPointPair.second;
|
point = startEndPointPair.second;
|
||||||
str = PointCalculate::textFormatEndPoint(point);
|
str = PointCalculate::textFormatEndPoint(point);
|
||||||
ao.mode = Global::AnalysisMode::StopPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawText(point,str);
|
drawText(point,str);
|
||||||
//
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1233,13 +1063,7 @@ void CentralWidget::loadAnalysisData(const AnalysisOperation ao)
|
|||||||
startEndPointPair.second.x());
|
startEndPointPair.second.x());
|
||||||
drawText(peakPoint,str);
|
drawText(peakPoint,str);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnalysisMode::PeakSynthesisAnalysis;
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1247,13 +1071,6 @@ void CentralWidget::loadAnalysisData(const AnalysisOperation ao)
|
|||||||
{
|
{
|
||||||
glassTransitionHandle(x1,x2);
|
glassTransitionHandle(x1,x2);
|
||||||
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnalysisMode::GlassTransition;
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1270,13 +1087,6 @@ void CentralWidget::loadAnalysisData(const AnalysisOperation ao)
|
|||||||
QString str = QString::number(point.x(),'f',3);
|
QString str = QString::number(point.x(),'f',3);
|
||||||
drawText(point,str);
|
drawText(point,str);
|
||||||
|
|
||||||
//
|
|
||||||
AnaOpRecorder::AnalysisOperation ao;
|
|
||||||
ao.mode = AnalysisMode::OnsetTemperaturePoint;
|
|
||||||
ao.x1 = x1;
|
|
||||||
ao.x2 = x2;
|
|
||||||
|
|
||||||
AnaOpRecorder::addAnalysisOperation(ao);
|
|
||||||
//
|
//
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -85,7 +85,7 @@ public slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent* event);
|
void timerEvent(QTimerEvent* event);
|
||||||
// void contextMenuEvent(QContextMenuEvent *event);
|
// void contextMenuEvent(QContextMenuEvent *event);
|
||||||
private:
|
private:
|
||||||
void glassTransitionHandle(const double x1,const double x2);
|
void glassTransitionHandle(const double x1,const double x2);
|
||||||
void quadraticFit(const QVector<QPointF>& points, double& a, double& b, double& c);
|
void quadraticFit(const QVector<QPointF>& points, double& a, double& b, double& c);
|
||||||
@ -106,7 +106,7 @@ private:
|
|||||||
};
|
};
|
||||||
void clearData(const ClearDataMode);
|
void clearData(const ClearDataMode);
|
||||||
|
|
||||||
void loadAnalysisData(const AnalysisOperationRecorder::AnalysisOperation);
|
void loadAnalysisData(const AnalysisMode mode,const double x1,const double x2);
|
||||||
private:
|
private:
|
||||||
AnalysisOperationRecorder::AnalysisMode _analysisMode;
|
AnalysisOperationRecorder::AnalysisMode _analysisMode;
|
||||||
LocalCustomPlot *_customPlot;
|
LocalCustomPlot *_customPlot;
|
||||||
|
|||||||
@ -4,11 +4,23 @@
|
|||||||
PrinterEditForm::PrinterEditForm(QWidget *parent) :
|
PrinterEditForm::PrinterEditForm(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::PrinterEditForm)
|
ui(new Ui::PrinterEditForm)
|
||||||
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrinterEditForm::~PrinterEditForm()
|
PrinterEditForm::~PrinterEditForm()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
#define PRINTEREDITFORM_H
|
#define PRINTEREDITFORM_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QPrintPreviewDialog>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PrinterEditForm;
|
class PrinterEditForm;
|
||||||
@ -17,6 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::PrinterEditForm *ui;
|
Ui::PrinterEditForm *ui;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PRINTEREDITFORM_H
|
#endif // PRINTEREDITFORM_H
|
||||||
|
|||||||
@ -6,8 +6,21 @@
|
|||||||
PrintPreviewForm::PrintPreviewForm(QWidget *parent) :
|
PrintPreviewForm::PrintPreviewForm(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::PrintPreviewForm)
|
ui(new Ui::PrintPreviewForm)
|
||||||
|
,_printer(new QPrinter(QPrinter::HighResolution))
|
||||||
|
,_customPrintPreviewDialog(new QPrintPreviewDialog(_printer,this))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
||||||
|
_printer->setPageSize(QPageSize(QPageSize::A4));
|
||||||
|
_printer->setOrientation(QPrinter::Landscape);
|
||||||
|
|
||||||
|
QObject::connect(_customPrintPreviewDialog, &QPrintPreviewDialog::paintRequested,
|
||||||
|
this,&PrintPreviewForm::slotPaintRequested);
|
||||||
|
|
||||||
|
_customPrintPreviewDialog->setWindowFlags(_customPrintPreviewDialog->windowFlags()
|
||||||
|
| Qt::WindowMaximizeButtonHint
|
||||||
|
| Qt::WindowMinimizeButtonHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintPreviewForm::~PrintPreviewForm()
|
PrintPreviewForm::~PrintPreviewForm()
|
||||||
@ -21,3 +34,67 @@ void PrintPreviewForm::setPixmap(const QPixmap &pixmap)
|
|||||||
localPixmap.scaled(ui->labelPixmap->size());
|
localPixmap.scaled(ui->labelPixmap->size());
|
||||||
ui->labelPixmap->setPixmap(pixmap);
|
ui->labelPixmap->setPixmap(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
|
||||||
|
{
|
||||||
|
printer->setOrientation(QPrinter::Landscape);
|
||||||
|
QPainter painter(printer);
|
||||||
|
|
||||||
|
// 绘制第一页(不需要先调用 newPage())
|
||||||
|
// painter.drawText(100, 100, "Page 1");
|
||||||
|
|
||||||
|
QRect pageRect = printer->pageRect();
|
||||||
|
qDebug()<<"rect:"<<pageRect;
|
||||||
|
|
||||||
|
// painter.drawText(pageRect.width()/2 - 50, 100, "Page 1"); // 居中显示
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// 绘制矩形框
|
||||||
|
QRect frameRect(50, 50, pageRect.width() - 100, pageRect.height() - 100);
|
||||||
|
QPen pen(Qt::black, 1); // 设置笔的宽度和颜色
|
||||||
|
painter.setPen(pen);
|
||||||
|
painter.drawRect(frameRect);
|
||||||
|
|
||||||
|
// 在框中绘制文字
|
||||||
|
// painter.drawText(frameRect, Qt::AlignCenter, "Hello, World!");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Draw image.
|
||||||
|
QRect imageRect = frameRect;
|
||||||
|
imageRect.setHeight(imageRect.height() - 200);
|
||||||
|
QPixmap pixmap(":/curve.png"); // 确保这个路径是正确的
|
||||||
|
if (!pixmap.isNull()) {
|
||||||
|
#if 0
|
||||||
|
QRect pixmapRect = pixmap.rect();
|
||||||
|
pixmapRect.moveCenter(pageRect.center());
|
||||||
|
#endif
|
||||||
|
painter.drawPixmap(imageRect, pixmap);
|
||||||
|
}else{
|
||||||
|
qDebug()<<" file not exist";
|
||||||
|
}
|
||||||
|
// File info.
|
||||||
|
QRect fileInfoRect(frameRect.x(),frameRect.y() + imageRect.height(),
|
||||||
|
frameRect.width(),30);
|
||||||
|
painter.drawRect(fileInfoRect);
|
||||||
|
painter.drawText(fileInfoRect, Qt::AlignLeft|Qt::AlignVCenter, " Hello, World!");
|
||||||
|
|
||||||
|
// Experiment info.
|
||||||
|
QRect experimentRect(frameRect.x(),fileInfoRect.y() + fileInfoRect.height(),
|
||||||
|
400,frameRect.height() - imageRect.height() - fileInfoRect.height());
|
||||||
|
painter.drawRect(experimentRect);
|
||||||
|
|
||||||
|
QString experimentInfoStr = QString(" 实验员:%1 \n"
|
||||||
|
" 时间:%2 \n").arg("Jay").arg("20250101");
|
||||||
|
painter.drawText(experimentRect, Qt::AlignLeft|Qt::AlignVCenter, experimentInfoStr);
|
||||||
|
// Phase info.
|
||||||
|
QRect phaseInfoRect(experimentRect.x() + experimentRect.width(),experimentRect.y(),
|
||||||
|
frameRect.width() - experimentRect.width(),experimentRect.height());
|
||||||
|
QString phaseInfoStr = QString(" 气氛:%1 ; 扫描速率:%2 ; 持续时间:%3 \n").arg("Jay").arg("20250101");
|
||||||
|
painter.drawText(phaseInfoRect, Qt::AlignLeft|Qt::AlignVCenter, phaseInfoStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
#define PRINTPREVIEWFORM_H
|
#define PRINTPREVIEWFORM_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QPrintPreviewDialog>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PrintPreviewForm;
|
class PrintPreviewForm;
|
||||||
@ -16,9 +18,13 @@ public:
|
|||||||
~PrintPreviewForm();
|
~PrintPreviewForm();
|
||||||
|
|
||||||
void setPixmap(const QPixmap &);
|
void setPixmap(const QPixmap &);
|
||||||
|
|
||||||
|
QPrintPreviewDialog* _customPrintPreviewDialog;
|
||||||
|
private slots:
|
||||||
|
void slotPaintRequested(QPrinter *printer);
|
||||||
private:
|
private:
|
||||||
Ui::PrintPreviewForm *ui;
|
Ui::PrintPreviewForm *ui;
|
||||||
|
QPrinter * _printer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PRINTPREVIEWFORM_H
|
#endif // PRINTPREVIEWFORM_H
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user