Commit 4d91194e authored by Jochen Becher's avatar Jochen Becher Committed by Tobias Hunger

Modeling: Fix build with/without SVG

Change-Id: I5152571010fecaf91986a16ca71bf7b89fada064
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 47950597
include(../../qtcreatorlibrary.pri)
QT += svg
!isEmpty(QT.svg.name): QT += svg
else: DEFINES += QT_NO_SVG
DEFINES += QMT_LIBRARY
......
......@@ -9,9 +9,15 @@ QtcLibrary {
"./qtserialization/inc",
])
Depends { name: "Qt"; submodules: ["widgets", "svg"] }
Depends { name: "Qt"; submodules: ["widgets"] }
Depends { name: "Qt.svg"; required: false }
Depends { name: "Utils" }
Properties {
condition: !Qt.svg.present
cpp.defines: base.concat("QT_NO_SVG")
}
Group {
name: "Qmt"
prefix: "./qmt/"
......
......@@ -59,7 +59,9 @@
#include <QPdfWriter>
#include <QFile>
#ifndef QT_NO_SCG
#include <QtSvg/QSvgGenerator>
#endif
namespace qmt {
......@@ -339,59 +341,6 @@ void DiagramSceneModel::copyToClipboard()
mimeData->setImageData(image);
}
#ifdef USE_PDF_CLIPBOARD
{
const double scaleFactor = 1.0;
const double border = 5;
const double baseDpi = 100;
const double dotsPerMm = 25.4 / baseDpi;
QBuffer pdfBuffer;
pdfBuffer.open(QIODevice::WriteOnly);
QPdfWriter pdfWriter(&pdfBuffer);
QSizeF pageSize = sceneBoundingRect.size();
pageSize += QSizeF(2.0 * border, 2.0 * border);
pageSize *= scaleFactor;
pdfWriter.setPageSize(QPdfWriter::Custom);
pdfWriter.setPageSizeMM(pageSize * dotsPerMm);
QPainter pdfPainter;
pdfPainter.begin(&pdfWriter);
m_graphicsScene->render(&pdfPainter,
QRectF(border, border,
pdfPainter.device()->width() - 2 * border,
pdfPainter.device()->height() - 2 * border),
sceneBoundingRect);
pdfPainter.end();
pdfBuffer.close();
mimeData->setData(QStringLiteral("application/pdf"), pdfBuffer.buffer());
}
#endif
#ifdef USE_SVG_CLIPBOARD
{
const double border = 5;
QBuffer svgBuffer;
QSvgGenerator svgGenerator;
svgGenerator.setOutputDevice(&svgBuffer);
QSize svgSceneSize = sceneBoundingRect.size().toSize();
svgGenerator.setSize(svgSceneSize);
svgGenerator.setViewBox(QRect(QPoint(0,0), svgSceneSize));
QPainter svgPainter;
svgPainter.begin(&svgGenerator);
svgPainter.setRenderHint(QPainter::Antialiasing);
m_graphicsScene->render(&svgPainter,
QRectF(border, border,
svgPainter.device()->width() - 2 * border,
svgPainter.device()->height() - 2 * border),
sceneBoundingRect);
svgPainter.end();
mimeData->setData(QStringLiteral("image/svg+xml"), svgBuffer.buffer());
}
#endif
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
if (!copyAll) {
......@@ -489,6 +438,7 @@ bool DiagramSceneModel::exportPdf(const QString &fileName)
bool DiagramSceneModel::exportSvg(const QString &fileName)
{
#ifndef QT_NO_SVG
// TODO support exporting selected elements only
removeExtraSceneItems();
......@@ -515,6 +465,10 @@ bool DiagramSceneModel::exportSvg(const QString &fileName)
// TODO how to know that file was successfully created?
return true;
#else // QT_NO_SVG
Q_UNUSED(fileName);
return false;
#endif // QT_NO_SVG
}
void DiagramSceneModel::selectItem(QGraphicsItem *item, bool multiSelect)
......
......@@ -524,10 +524,13 @@ void ModelEditor::exportDiagram()
if (diagram) {
if (d->lastExportDirPath.isEmpty())
d->lastExportDirPath = d->document->filePath().toFileInfo().canonicalPath();
QString filter = tr("Images (*.png *.jpeg *.jpg *.tif *.tiff);;PDF (*.pdf)");
#ifndef QT_NO_SVG
filter += tr(";;SVG (*.svg)");
#endif // QT_NO_SVG
QString fileName = QFileDialog::getSaveFileName(
Core::ICore::dialogParent(),
tr("Export Diagram"), d->lastExportDirPath,
tr("Images (*.png *.jpeg *.jpg *.tif *.tiff);;PDF (*.pdf);;SVG (*.svg)"));
tr("Export Diagram"), d->lastExportDirPath, filter);
if (!fileName.isEmpty()) {
qmt::DocumentController *documentController = d->document->documentController();
qmt::DiagramSceneModel *sceneModel = documentController->diagramsManager()->diagramSceneModel(diagram);
......@@ -535,13 +538,15 @@ void ModelEditor::exportDiagram()
QString suffix = QFileInfo(fileName).suffix().toLower();
// TODO use QFileDialog::selectedNameFilter() as fallback if no suffix is given
if (suffix.isEmpty()) {
suffix = QStringLiteral(".png");
fileName += suffix;
suffix = QStringLiteral("png");
fileName += QStringLiteral(".png");
}
if (suffix == QStringLiteral(".pdf"))
if (suffix == QStringLiteral("pdf"))
success = sceneModel->exportPdf(fileName);
else if (suffix == QStringLiteral(".svg"))
#ifndef QT_NO_SVG
else if (suffix == QStringLiteral("svg"))
success = sceneModel->exportSvg(fileName);
#endif // QT_NO_SVG
else
success = sceneModel->exportImage(fileName);
if (success)
......
......@@ -4,27 +4,7 @@ DEFINES += MODELEDITOR_LIBRARY
QT += core gui widgets
!win32:CONFIG(pdf) {
DEFINES += USE_PDF_CLIPBOARD
}
!win32:CONFIG(svg): {
QT += svg
DEFINES += USE_SVG_CLIPBOARD
}
#win32:CONFIG(emf): {
# DEFINES += USE_EMF USE_EMF_CLIPBOARD
#
# SOURCES += \
# emf-engine/qemfpaintengine.cpp \
# emf-engine/qemfwriter.cpp
#
# HEADERS += \
# emf-engine/qemfpaintengine.h \
# emf-engine/qemfwriter.h
#
#}
isEmpty(QT.svg.name): DEFINES += QT_NO_SVG
SOURCES += \
actionhandler.cpp \
......
......@@ -6,12 +6,18 @@ QtcPlugin {
name: "ModelEditor"
Depends { name: "Qt.widgets" }
Depends { name: "Qt.svg"; required: false }
Depends { name: "Core" }
Depends { name: "CPlusPlus" }
Depends { name: "CppTools" }
Depends { name: "ProjectExplorer" }
Depends { name: "ModelingLib" }
Properties {
condition: !Qt.svg.present
cpp.defines: base.concat("QT_NO_SVG")
}
cpp.includePaths: [
"qmt",
"qstringparser",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment