diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp
index 7eeef7c..d0e6d9f 100644
--- a/source/mainwindow.cpp
+++ b/source/mainwindow.cpp
@@ -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);
+}
diff --git a/source/mainwindow.h b/source/mainwindow.h
index c2cf130..9675fb7 100644
--- a/source/mainwindow.h
+++ b/source/mainwindow.h
@@ -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);
};
diff --git a/source/mainwindow.ui b/source/mainwindow.ui
index 86d0199..9622ce3 100644
--- a/source/mainwindow.ui
+++ b/source/mainwindow.ui
@@ -133,6 +133,7 @@
+
@@ -228,6 +229,14 @@
Ctrl+P
+
+
+ Export PDF
+
+
+ Export as PDF file
+
+