diff options
-rw-r--r-- | dbmodel.pro | 2 | ||||
-rw-r--r-- | mainwindow.cpp | 39 |
2 files changed, 30 insertions, 11 deletions
diff --git a/dbmodel.pro b/dbmodel.pro index 218ca8e..c47acd9 100644 --- a/dbmodel.pro +++ b/dbmodel.pro @@ -1,4 +1,4 @@ -QT += xml +QT += xml svg CONFIG += debug SOURCES = \ column.cpp \ diff --git a/mainwindow.cpp b/mainwindow.cpp index 62983c8..c6cd1b8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,6 +22,8 @@ #include <QFileDialog> #include <QIcon> #include <QImage> +#include <QSvgGenerator> +#include <QMessageBox> #include <QDebug> #include "mainwindow.h" #include "databasetable.h" @@ -234,18 +236,35 @@ MainWindow::saveAs() void MainWindow::exportPNG() { - QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), "Portable Network Graphics (*.png)"); + QStringList filters; + filters << "Portable Network Graphics (*.png)"; + filters << "Scalable Vector Graphics (*.svg)"; + QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), filters.join(";;")); if (!fileName.isNull()) { QRectF boundingRect = m_model->itemsBoundingRect().adjusted(-2, -2, 2, 2); - QImage image(int(ceil(boundingRect.width())), int(ceil(boundingRect.height())), QImage::Format_RGB32); - QPainter painter(&image); - painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing); - painter.fillRect(image.rect(), Qt::white); - m_model->render(&painter, image.rect(), boundingRect); - if (true) - image.convertToFormat(QImage::Format_Indexed8).save(fileName, "PNG"); - else - image.save(fileName, "PNG"); + QSize size(int(ceil(boundingRect.width())), int(ceil(boundingRect.height()))); + if (fileName.endsWith(".svg", Qt::CaseInsensitive)) { + QSvgGenerator generator; + generator.setSize(size); + generator.setFileName(fileName); + QPainter painter(&generator); + painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing); + m_model->render(&painter, QRectF(), boundingRect); + } + else if (fileName.endsWith(".png", Qt::CaseInsensitive)) { + QImage image(size, QImage::Format_RGB32); + QPainter painter(&image); + painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing); + painter.fillRect(image.rect(), Qt::white); + m_model->render(&painter, image.rect(), boundingRect); + if (true) + image.convertToFormat(QImage::Format_Indexed8).save(fileName, "PNG"); + else + image.save(fileName, "PNG"); + } + else { + QMessageBox::critical(this, tr("Error"), tr("Unknown format.")); + } } } |