Skip to content

Commit aa15512

Browse files
committedDec 11, 2018
[layouts][needs-docs] Add a PDF export settings dialog which is shown
whenever exporting a layout to PDF This matches the behavior with SVG and raster exports, and allows users to set specific properties for the export (such as text rendering format) Fixes #8844 (cherry picked from commit 484d5d9)
1 parent de18cc7 commit aa15512

File tree

3 files changed

+191
-10
lines changed

3 files changed

+191
-10
lines changed
 

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "qgsreportorganizerwidget.h"
6666
#include "qgsreadwritecontext.h"
6767
#include "ui_qgssvgexportoptions.h"
68+
#include "ui_qgspdfexportoptions.h"
6869
#include "qgsproxyprogresstask.h"
6970
#include "ui_defaults.h"
7071

@@ -2067,13 +2068,15 @@ void QgsLayoutDesignerDialog::exportToPdf()
20672068

20682069
mView->setPaintingEnabled( false );
20692070
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
2071+
2072+
QgsLayoutExporter::PdfExportSettings pdfSettings;
2073+
if ( !getPdfExportSettings( pdfSettings ) )
2074+
return;
2075+
20702076
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
20712077
QgsApplication::taskManager()->addTask( proxyTask );
20722078

2073-
QgsLayoutExporter::PdfExportSettings pdfSettings;
20742079
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
2075-
pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
2076-
pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat();
20772080

20782081
// force a refresh, to e.g. update data defined properties, tables, etc
20792082
mLayout->refresh();
@@ -2970,9 +2973,10 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
29702973
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
29712974

29722975
QgsLayoutExporter::PdfExportSettings pdfSettings;
2976+
if ( !getPdfExportSettings( pdfSettings ) )
2977+
return;
2978+
29732979
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
2974-
pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
2975-
pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat();
29762980

29772981
QString error;
29782982
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
@@ -3347,17 +3351,15 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
33473351
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
33483352

33493353
bool rasterize = false;
3350-
bool forceVectorOutput = false;
33513354
if ( mLayout )
33523355
{
33533356
rasterize = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
3354-
forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
33553357
}
33563358
QgsLayoutExporter::PdfExportSettings pdfSettings;
3357-
// TODO - show a dialog allowing users to control these settings on a per-output basis
3359+
if ( !getPdfExportSettings( pdfSettings ) )
3360+
return;
3361+
33583362
pdfSettings.rasterizeWholeImage = rasterize;
3359-
pdfSettings.forceVectorOutput = forceVectorOutput;
3360-
pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat();
33613363

33623364
QString error;
33633365
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
@@ -4049,6 +4051,55 @@ bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExport
40494051
return true;
40504052
}
40514053

4054+
bool QgsLayoutDesignerDialog::getPdfExportSettings( QgsLayoutExporter::PdfExportSettings &settings )
4055+
{
4056+
QgsRenderContext::TextRenderFormat prevTextRenderFormat = mMasterLayout->layoutProject()->labelingEngineSettings().defaultTextRenderFormat();
4057+
bool previousForceVector = false;
4058+
bool includeMetadata = true;
4059+
if ( mLayout )
4060+
{
4061+
mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
4062+
includeMetadata = mLayout->customProperty( QStringLiteral( "pdfIncludeMetadata" ), 1 ).toBool();
4063+
const int prevLayoutSettingLabelsAsOutlines = mLayout->customProperty( QStringLiteral( "pdfTextFormat" ), -1 ).toInt();
4064+
if ( prevLayoutSettingLabelsAsOutlines >= 0 )
4065+
{
4066+
// previous layout setting takes default over project setting
4067+
prevTextRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( prevLayoutSettingLabelsAsOutlines );
4068+
}
4069+
}
4070+
4071+
// open options dialog
4072+
QDialog dialog;
4073+
Ui::QgsPdfExportOptionsDialog options;
4074+
options.setupUi( &dialog );
4075+
4076+
options.mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
4077+
options.mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText );
4078+
4079+
options.mTextRenderFormatComboBox->setCurrentIndex( options.mTextRenderFormatComboBox->findData( prevTextRenderFormat ) );
4080+
options.mForceVectorCheckBox->setChecked( previousForceVector );
4081+
options.mIncludeMetadataCheckbox->setChecked( includeMetadata );
4082+
4083+
if ( dialog.exec() != QDialog::Accepted )
4084+
return false;
4085+
4086+
includeMetadata = options.mIncludeMetadataCheckbox->isChecked();
4087+
QgsRenderContext::TextRenderFormat textRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( options.mTextRenderFormatComboBox->currentData().toInt() );
4088+
4089+
if ( mLayout )
4090+
{
4091+
//save dialog settings
4092+
mLayout->setCustomProperty( QStringLiteral( "pdfIncludeMetadata" ), includeMetadata ? 1 : 0 );
4093+
mLayout->setCustomProperty( QStringLiteral( "pdfTextFormat" ), static_cast< int >( textRenderFormat ) );
4094+
}
4095+
4096+
settings.forceVectorOutput = options.mForceVectorCheckBox->isChecked();
4097+
settings.exportMetadata = includeMetadata;
4098+
settings.textRenderFormat = textRenderFormat;
4099+
4100+
return true;
4101+
}
4102+
40524103
void QgsLayoutDesignerDialog::toggleAtlasControls( bool atlasEnabled )
40534104
{
40544105
//preview defaults to unchecked

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
505505
bool showFileSizeWarning();
506506
bool getRasterExportSettings( QgsLayoutExporter::ImageExportSettings &settings, QSize &imageSize );
507507
bool getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings );
508+
bool getPdfExportSettings( QgsLayoutExporter::PdfExportSettings &settings );
508509

509510
void toggleAtlasActions( bool enabled );
510511

‎src/ui/layout/qgspdfexportoptions.ui

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsPdfExportOptionsDialog</class>
4+
<widget class="QDialog" name="QgsPdfExportOptionsDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>489</width>
10+
<height>190</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>PDF Export Options</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox">
19+
<property name="title">
20+
<string>PDF Options</string>
21+
</property>
22+
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
23+
<item row="1" column="0" colspan="2">
24+
<widget class="QCheckBox" name="mIncludeMetadataCheckbox">
25+
<property name="text">
26+
<string>Export RDF metadata</string>
27+
</property>
28+
<property name="checked">
29+
<bool>true</bool>
30+
</property>
31+
</widget>
32+
</item>
33+
<item row="2" column="1">
34+
<widget class="QComboBox" name="mTextRenderFormatComboBox"/>
35+
</item>
36+
<item row="2" column="0">
37+
<widget class="QLabel" name="label_6">
38+
<property name="text">
39+
<string>Text export</string>
40+
</property>
41+
</widget>
42+
</item>
43+
<item row="0" column="0" colspan="2">
44+
<widget class="QCheckBox" name="mForceVectorCheckBox">
45+
<property name="toolTip">
46+
<string>If checked, the layout will always be kept as vector objects when exported to a compatible format, even if the appearance of the resultant file does not match the layouts settings. If unchecked, some elements in the layout may be rasterized in order to keep their appearance intact.</string>
47+
</property>
48+
<property name="text">
49+
<string>Always export as vectors</string>
50+
</property>
51+
</widget>
52+
</item>
53+
</layout>
54+
</widget>
55+
</item>
56+
<item>
57+
<spacer name="verticalSpacer">
58+
<property name="orientation">
59+
<enum>Qt::Vertical</enum>
60+
</property>
61+
<property name="sizeHint" stdset="0">
62+
<size>
63+
<width>20</width>
64+
<height>40</height>
65+
</size>
66+
</property>
67+
</spacer>
68+
</item>
69+
<item>
70+
<widget class="QDialogButtonBox" name="buttonBox">
71+
<property name="orientation">
72+
<enum>Qt::Horizontal</enum>
73+
</property>
74+
<property name="standardButtons">
75+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
76+
</property>
77+
</widget>
78+
</item>
79+
</layout>
80+
</widget>
81+
<customwidgets>
82+
<customwidget>
83+
<class>QgsCollapsibleGroupBoxBasic</class>
84+
<extends>QGroupBox</extends>
85+
<header location="global">qgscollapsiblegroupbox.h</header>
86+
<container>1</container>
87+
</customwidget>
88+
</customwidgets>
89+
<tabstops>
90+
<tabstop>mForceVectorCheckBox</tabstop>
91+
<tabstop>mIncludeMetadataCheckbox</tabstop>
92+
<tabstop>mTextRenderFormatComboBox</tabstop>
93+
</tabstops>
94+
<resources/>
95+
<connections>
96+
<connection>
97+
<sender>buttonBox</sender>
98+
<signal>accepted()</signal>
99+
<receiver>QgsPdfExportOptionsDialog</receiver>
100+
<slot>accept()</slot>
101+
<hints>
102+
<hint type="sourcelabel">
103+
<x>248</x>
104+
<y>254</y>
105+
</hint>
106+
<hint type="destinationlabel">
107+
<x>157</x>
108+
<y>274</y>
109+
</hint>
110+
</hints>
111+
</connection>
112+
<connection>
113+
<sender>buttonBox</sender>
114+
<signal>rejected()</signal>
115+
<receiver>QgsPdfExportOptionsDialog</receiver>
116+
<slot>reject()</slot>
117+
<hints>
118+
<hint type="sourcelabel">
119+
<x>316</x>
120+
<y>260</y>
121+
</hint>
122+
<hint type="destinationlabel">
123+
<x>286</x>
124+
<y>274</y>
125+
</hint>
126+
</hints>
127+
</connection>
128+
</connections>
129+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.