Merge branch 'develop' into feature/print-as-qtextdocument
This commit is contained in:
commit
e89f157bac
@ -56,6 +56,7 @@ void MainWindow::setupUi()
|
||||
connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile));
|
||||
connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs);
|
||||
connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print);
|
||||
connect(ui->actionExport_PDF, &QAction::triggered, this, qOverload<>(&MainWindow::savePdf));
|
||||
|
||||
connect(&m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
|
||||
}
|
||||
@ -162,8 +163,6 @@ void MainWindow::print() const
|
||||
m_dataModel.printTo(printCursor);
|
||||
|
||||
printDoc.print(&printer);
|
||||
|
||||
printDoc.print(&printer);
|
||||
}
|
||||
|
||||
void MainWindow::dataModelChanged()
|
||||
@ -172,6 +171,22 @@ void MainWindow::dataModelChanged()
|
||||
setWindowModified(true);
|
||||
}
|
||||
|
||||
void MainWindow::savePdf()
|
||||
{
|
||||
QFileDialog saveFilenameDialog(this);
|
||||
saveFilenameDialog.setDefaultSuffix("pdf");
|
||||
saveFilenameDialog.setFileMode(QFileDialog::AnyFile);
|
||||
saveFilenameDialog.setNameFilter("PDF File (*.pdf)");
|
||||
saveFilenameDialog.setWindowTitle("Save file");
|
||||
|
||||
if (!saveFilenameDialog.exec())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
savePdf(saveFilenameDialog.selectedFiles().first());
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
closeFile();
|
||||
@ -190,3 +205,17 @@ void MainWindow::saveFile(const QString &filename)
|
||||
m_filename = filename;
|
||||
m_saveOnClose = false;
|
||||
}
|
||||
|
||||
void MainWindow::savePdf(const QString &filename)
|
||||
{
|
||||
QPrinter printer;
|
||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
printer.setPaperSize(QPrinter::A4);
|
||||
printer.setOutputFileName(filename);
|
||||
|
||||
QTextDocument printDoc;
|
||||
QTextCursor printCursor(&printDoc);
|
||||
m_dataModel.printTo(printCursor);
|
||||
|
||||
printDoc.print(&printer);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public slots:
|
||||
void closeFile();
|
||||
void print() const;
|
||||
void dataModelChanged();
|
||||
void savePdf();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
@ -44,4 +45,5 @@ protected:
|
||||
private:
|
||||
void setupUi();
|
||||
void saveFile(const QString &filename);
|
||||
void savePdf(const QString &filename);
|
||||
};
|
||||
|
@ -133,6 +133,7 @@
|
||||
<addaction name="actionSave_as"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionPrint"/>
|
||||
<addaction name="actionExport_PDF"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
@ -228,6 +229,14 @@
|
||||
<string>Ctrl+P</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExport_PDF">
|
||||
<property name="text">
|
||||
<string>Export PDF</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Export as PDF file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
Reference in New Issue
Block a user