diff options
author | Lukáš Lalinský <lalinsky@gmail.com> | 2009-07-10 11:50:00 +0200 |
---|---|---|
committer | Lukáš Lalinský <lalinsky@gmail.com> | 2009-07-10 11:50:00 +0200 |
commit | 2d25d68e2327513d5a87989038b9a1d9ef5051a1 (patch) | |
tree | b8f1be2b78694b2655cfbefbc566c925048ac5fe /src | |
parent | 90f574f945d1efc5864f2c337bb24070793a24a4 (diff) | |
download | dbmodel-2d25d68e2327513d5a87989038b9a1d9ef5051a1.tar.xz |
Move document printing to DiagramDocument::print
Diffstat (limited to 'src')
-rw-r--r-- | src/diagramdocument.cpp | 17 | ||||
-rw-r--r-- | src/diagramdocument.h | 6 | ||||
-rw-r--r-- | src/export/exporter.cpp | 8 | ||||
-rw-r--r-- | src/export/exporter.h | 3 | ||||
-rw-r--r-- | src/export/pdfexporter.cpp | 2 | ||||
-rw-r--r-- | src/export/pngexporter.cpp | 2 | ||||
-rw-r--r-- | src/export/svgexporter.cpp | 2 | ||||
-rw-r--r-- | src/mainwindow.cpp | 7 |
8 files changed, 28 insertions, 19 deletions
diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp index af2f4ec..a697bc7 100644 --- a/src/diagramdocument.cpp +++ b/src/diagramdocument.cpp @@ -30,6 +30,8 @@ #include <QTextStream> #include <QStyle> #include <QSet> +#include <QPainter> +#include <QPrinter> #include "diagram/linelayouter.h" using namespace std; @@ -468,3 +470,18 @@ DiagramDocument::itemById(const QUuid &id) return item; return 0; } + +void +DiagramDocument::print(QPrinter *printer, const QRectF &target, const QRectF &source) +{ + QPainter painter(printer); + print(&painter, target, source); +} + +void +DiagramDocument::print(QPainter *painter, const QRectF &target, const QRectF &source) +{ + setPrinting(true); + render(painter, target, source); + setPrinting(false); +} diff --git a/src/diagramdocument.h b/src/diagramdocument.h index 9347281..fa061b1 100644 --- a/src/diagramdocument.h +++ b/src/diagramdocument.h @@ -31,6 +31,9 @@ class Line; class DiagramItem; class DiagramObject; +class QPainter; +class QPrinter; + class DiagramDocument : public QGraphicsScene { Q_OBJECT @@ -99,6 +102,9 @@ public: void addItemLater(DiagramItem *item); void removeItemLater(DiagramItem *item); + void print(QPainter *painter, const QRectF &target = QRectF(), const QRectF &source = QRectF()); + void print(QPrinter *printer, const QRectF &target = QRectF(), const QRectF &source = QRectF()); + signals: void modeChanged(DiagramDocument::Mode mode); diff --git a/src/export/exporter.cpp b/src/export/exporter.cpp index 239a550..a20c8df 100644 --- a/src/export/exporter.cpp +++ b/src/export/exporter.cpp @@ -23,11 +23,3 @@ Exporter::filter() const { return QString("%1 (*%2)").arg(name(), extension()); } - -void -Exporter::renderDocument(QPainter *painter, DiagramDocument *document, const QRectF &target, const QRectF &source) -{ - document->setPrinting(true); - document->render(painter, target, source); - document->setPrinting(false); -} diff --git a/src/export/exporter.h b/src/export/exporter.h index ab7f614..30c5b7c 100644 --- a/src/export/exporter.h +++ b/src/export/exporter.h @@ -31,9 +31,6 @@ public: virtual QString name() const = 0; virtual QString extension() const = 0; virtual void exportToFile(const QString &fileName, DiagramDocument *document) = 0; - -protected: - void renderDocument(QPainter *painter, DiagramDocument *document, const QRectF &target, const QRectF &source); }; #endif diff --git a/src/export/pdfexporter.cpp b/src/export/pdfexporter.cpp index 2fb0812..4eadd5c 100644 --- a/src/export/pdfexporter.cpp +++ b/src/export/pdfexporter.cpp @@ -44,5 +44,5 @@ PDFExporter::exportToFile(const QString &fileName, DiagramDocument *document) QPainter painter(&printer); painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing); - renderDocument(&painter, document, QRectF(), boundingRect); + document->print(&painter, QRectF(), boundingRect); } diff --git a/src/export/pngexporter.cpp b/src/export/pngexporter.cpp index 32716a5..0d9032d 100644 --- a/src/export/pngexporter.cpp +++ b/src/export/pngexporter.cpp @@ -43,7 +43,7 @@ PNGExporter::exportToFile(const QString &fileName, DiagramDocument *document) painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing); painter.fillRect(image.rect(), Qt::white); - renderDocument(&painter, document, image.rect(), boundingRect); + document->print(&painter, image.rect(), boundingRect); image.convertToFormat(QImage::Format_Indexed8).save(fileName, "PNG"); } diff --git a/src/export/svgexporter.cpp b/src/export/svgexporter.cpp index 7183dea..74f9ef8 100644 --- a/src/export/svgexporter.cpp +++ b/src/export/svgexporter.cpp @@ -44,5 +44,5 @@ SVGExporter::exportToFile(const QString &fileName, DiagramDocument *document) QPainter painter(&generator); painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing); - renderDocument(&painter, document, QRectF(), boundingRect); + document->print(&painter, QRectF(), boundingRect); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 451e94a..eac5f02 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -535,7 +535,7 @@ MainWindow::print() initPrinter(); QPrintDialog printDialog(d->printer, this); if (printDialog.exec() == QDialog::Accepted) { - printPreview(d->printer); + m_model->print(d->printer); } } @@ -552,10 +552,7 @@ MainWindow::printPreview() void MainWindow::printPreview(QPrinter *printer) { - QPainter painter(printer); - m_model->setPrinting(true); - m_model->render(&painter); - m_model->setPrinting(false); + m_model->print(printer); } void |