QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslayoutpdfexportoptionsdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutpdfexportoptionsdialog.cpp
3 -------------------------------------
4 begin : August 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18#include "qgis.h"
19#include "qgssettings.h"
20#include "qgsgui.h"
21#include "qgshelp.h"
23#include "qgsproject.h"
26#include "qgslayertree.h"
27
28#include <QCheckBox>
29#include <QPushButton>
30#include <QMenu>
31
32QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, bool allowGeoPdfExport, const QString &geoPdfReason, const QStringList &geoPdfLayerOrder, Qt::WindowFlags flags )
33 : QDialog( parent, flags )
34{
35 setupUi( this );
36
37 mGeoPdfStructureTreeMenu = new QMenu( this );
38
39 mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), static_cast< int >( Qgis::TextRenderFormat::AlwaysOutlines ) );
40 mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), static_cast< int >( Qgis::TextRenderFormat::AlwaysText ) );
41
42 mGeopdfAvailable = allowGeoPdfExport && QgsAbstractGeoPdfExporter::geoPDFCreationAvailable();
43 mGeoPDFGroupBox->setEnabled( mGeopdfAvailable );
44 mGeoPDFGroupBox->setChecked( false );
45 if ( !mGeopdfAvailable )
46 {
47 mGeoPDFOptionsStackedWidget->setCurrentIndex( 0 );
48 mGeoPdfUnavailableReason->setText( geoPdfReason.isEmpty() ? QgsAbstractGeoPdfExporter::geoPDFAvailabilityExplanation() : geoPdfReason );
49 // avoid showing reason in disabled text color - we want it to stand out
50 QPalette p = mGeoPdfUnavailableReason->palette();
51 p.setColor( QPalette::Disabled, QPalette::WindowText, QPalette::WindowText );
52 mGeoPdfUnavailableReason->setPalette( p );
53 mGeoPDFOptionsStackedWidget->removeWidget( mGeoPDFOptionsStackedWidget->widget( 1 ) );
54 }
55 else
56 {
57 mGeoPDFOptionsStackedWidget->setCurrentIndex( 1 );
58 mGeoPdfFormatComboBox->addItem( tr( "ISO 32000 Extension (recommended)" ) );
59 mGeoPdfFormatComboBox->addItem( tr( "OGC Best Practice" ) );
60 }
61
62 mComboImageCompression->addItem( tr( "Lossy (JPEG)" ), false );
63 mComboImageCompression->addItem( tr( "Lossless" ), true );
64
65 const QStringList themes = QgsProject::instance()->mapThemeCollection()->mapThemes();
66 for ( const QString &theme : themes )
67 {
68 QListWidgetItem *item = new QListWidgetItem( theme );
69 item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
70 item->setCheckState( Qt::Unchecked );
71 mThemesList->addItem( item );
72 }
73
74 QList< QgsMapLayer * > order = QgsProject::instance()->layerTreeRoot()->layerOrder();
75 for ( auto it = geoPdfLayerOrder.rbegin(); it != geoPdfLayerOrder.rend(); ++it )
76 {
77 for ( int i = 0; i < order.size(); ++i )
78 {
79 if ( order.at( i )->id() == *it )
80 {
81 order.move( i, 0 );
82 break;
83 }
84 }
85 }
86 mGeoPdfStructureModel = new QgsGeoPdfLayerTreeModel( order, this );
87 mGeoPdfStructureProxyModel = new QgsGeoPdfLayerFilteredTreeModel( mGeoPdfStructureModel, this );
88 mGeoPdfStructureTree->setModel( mGeoPdfStructureProxyModel );
89 mGeoPdfStructureTree->resizeColumnToContents( 0 );
90 mGeoPdfStructureTree->header()->show();
91 mGeoPdfStructureTree->setSelectionMode( QAbstractItemView::SingleSelection );
92 mGeoPdfStructureTree->setSelectionBehavior( QAbstractItemView::SelectRows );
93
94 mGeoPdfStructureTree->setDragEnabled( true );
95 mGeoPdfStructureTree->setAcceptDrops( true );
96 mGeoPdfStructureTree->setDragDropMode( QAbstractItemView::InternalMove );
97 mGeoPdfStructureTree->setDefaultDropAction( Qt::MoveAction );
98
99 mGeoPdfStructureTree->setContextMenuPolicy( Qt::CustomContextMenu );
100 connect( mGeoPdfStructureTree, &QTreeView::customContextMenuRequested, this, [ = ]( const QPoint & point )
101 {
102 const QModelIndex index = mGeoPdfStructureTree->indexAt( point );
103 if ( index.isValid() )
104 showContextMenuForGeoPdfStructure( point, mGeoPdfStructureProxyModel->mapToSource( index ) );
105 } );
106
107 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
109}
110
112{
113 mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( static_cast< int >( format ) ) );
114}
115
117{
118 return static_cast< Qgis::TextRenderFormat >( mTextRenderFormatComboBox->currentData().toInt() );
119}
120
122{
123 mForceVectorCheckBox->setChecked( force );
124}
125
127{
128 return mForceVectorCheckBox->isChecked();
129}
130
132{
133 mAppendGeoreferenceCheckbox->setEnabled( enabled );
134}
135
137{
138 mAppendGeoreferenceCheckbox->setChecked( enabled );
139}
140
142{
143 return mAppendGeoreferenceCheckbox->isChecked();
144}
145
147{
148 mIncludeMetadataCheckbox->setChecked( enabled );
149}
150
152{
153 return mIncludeMetadataCheckbox->isChecked();
154}
155
157{
158 mDisableRasterTilingCheckBox->setChecked( disabled );
159}
160
162{
163 return mDisableRasterTilingCheckBox->isChecked();
164}
165
167{
168 mSimplifyGeometriesCheckbox->setChecked( enabled );
169}
170
172{
173 return mSimplifyGeometriesCheckbox->isChecked();
174}
175
177{
178 mComboImageCompression->setCurrentIndex( mComboImageCompression->findData( enabled ) );
179}
180
182{
183 return mComboImageCompression->currentData().toBool();
184}
185
187{
188 if ( !mGeopdfAvailable )
189 return;
190
191 mGeoPDFGroupBox->setChecked( enabled );
192}
193
195{
196 if ( !mGeopdfAvailable )
197 return false;
198
199 return mGeoPDFGroupBox->isChecked();
200}
201
203{
204 if ( !mGeopdfAvailable )
205 return;
206
207 if ( enabled )
208 mGeoPdfFormatComboBox->setCurrentIndex( 1 );
209 else
210 mGeoPdfFormatComboBox->setCurrentIndex( 0 );
211}
212
214{
215 if ( !mGeopdfAvailable )
216 return false;
217
218 return mGeoPdfFormatComboBox->currentIndex() == 1;
219}
220
221
223{
224 if ( !mGeopdfAvailable )
225 return;
226
227 mIncludeMapThemesCheck->setChecked( !themes.isEmpty() );
228 for ( int i = 0; i < mThemesList->count(); ++i )
229 {
230 QListWidgetItem *item = mThemesList->item( i );
231 item->setCheckState( themes.contains( item->text() ) ? Qt::Checked : Qt::Unchecked );
232 }
233}
234
236{
237 QStringList res;
238 if ( !mGeopdfAvailable )
239 return res;
240
241 if ( !mIncludeMapThemesCheck || !mIncludeMapThemesCheck->isChecked() )
242 return res;
243
244 res.reserve( mThemesList->count() );
245 for ( int i = 0; i < mThemesList->count(); ++i )
246 {
247 QListWidgetItem *item = mThemesList->item( i );
248 if ( item->checkState() == Qt::Checked )
249 res << item->text();
250 }
251 return res;
252}
253
255{
256 QStringList order;
257 for ( int row = 0; row < mGeoPdfStructureProxyModel->rowCount(); ++row )
258 {
259 order << mGeoPdfStructureProxyModel->data( mGeoPdfStructureProxyModel->index( row, 0 ), static_cast< int >( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
260 }
261 return order;
262}
263
265{
266 mOpenAfterExportingCheckBox->setChecked( enabled );
267}
268
270{
271 return mOpenAfterExportingCheckBox->isChecked();
272}
273
274void QgsLayoutPdfExportOptionsDialog::showHelp()
275{
276 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
277}
278
279void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeoPdfStructure( QPoint point, const QModelIndex &index )
280{
281 mGeoPdfStructureTreeMenu->clear();
282
283 switch ( index.column() )
284 {
287 {
288 QAction *selectAll = new QAction( tr( "Select All" ), mGeoPdfStructureTreeMenu );
289 mGeoPdfStructureTreeMenu->addAction( selectAll );
290 connect( selectAll, &QAction::triggered, this, [ = ]
291 {
292 mGeoPdfStructureModel->checkAll( true, QModelIndex(), index.column() );
293 } );
294 QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeoPdfStructureTreeMenu );
295 mGeoPdfStructureTreeMenu->addAction( deselectAll );
296 connect( deselectAll, &QAction::triggered, this, [ = ]
297 {
298 mGeoPdfStructureModel->checkAll( false, QModelIndex(), index.column() );
299 } );
300 break;
301 }
302
303 default:
304 break;
305 }
306
307 if ( !mGeoPdfStructureTreeMenu->actions().empty() )
308 {
309 mGeoPdfStructureTreeMenu->exec( mGeoPdfStructureTree->mapToGlobal( point ) );
310 }
311}
TextRenderFormat
Options for rendering text.
Definition: qgis.h:2309
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
@ AlwaysText
Always render text as text objects. While this mode preserves text objects as text for post-processin...
static bool geoPDFCreationAvailable()
Returns true if the current QGIS build is capable of GeoPDF support.
static QString geoPDFAvailabilityExplanation()
Returns a user-friendly, translated string explaining why GeoPDF export support is not available on t...
Layer tree model for Geo-PDF layers.
@ InitiallyVisible
Initial visibility state.
@ IncludeVectorAttributes
Vector attribute.
void checkAll(bool checked, const QModelIndex &parent=QModelIndex(), int column=IncludeVectorAttributes)
Checks (or unchecks) all rows and children from the specified parent index.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:194
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:39
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
void setOpenAfterExporting(bool enabled)
Sets whether to open the pdf after exporting it.
QgsLayoutPdfExportOptionsDialog(QWidget *parent=nullptr, bool allowGeoPdfExport=true, const QString &geoPdfReason=QString(), const QStringList &geoPdfLayerOrder=QStringList(), Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutPdfExportOptionsDialog.
QStringList exportThemes() const
Returns the list of export themes.
bool useOgcBestPracticeFormat() const
Returns whether use of OGC best-practice format is enabled.
bool geometriesSimplified() const
Returns whether geometry simplification is enabled.
bool losslessImageExport() const
Returns whether lossless image compression is enabled.
void setLosslessImageExport(bool enabled)
Sets whether to use lossless image compression.
void setUseOgcBestPracticeFormat(bool enabled)
Sets whether to use OGC best-practice format.
bool openAfterExporting() const
Returns whether the pdf should be opened after exporting it.
bool georeferencingEnabled() const
Returns whether georeferencing is enabled.
void setRasterTilingDisabled(bool disabled)
Sets whether to disable raster tiling.
bool forceVector() const
Returns whether vector output is being forced.
void setGeometriesSimplified(bool enabled)
Sets whether to simplify geometries.
bool metadataEnabled() const
Returns whether metadata is enabled.
void setGeoreferencingEnabled(bool enabled)
Sets whether to enable georeferencing.
void setMetadataEnabled(bool enabled)
Sets whether to enable metadata.
void enableGeoreferencingOptions(bool enabled)
Sets whether to enable georeferencing options.
bool exportGeoPdf() const
Returns whether Geo-PDF export is enabled.
void setExportGeoPdf(bool enabled)
Sets whether to export a Geo-PDF.
QStringList geoPdfLayerOrder() const
Returns a list of map layer IDs in the desired order they should appear in a generated GeoPDF file.
void setTextRenderFormat(Qgis::TextRenderFormat format)
Sets the text render format.
Qgis::TextRenderFormat textRenderFormat() const
Returns the current text render format.
bool rasterTilingDisabled() const
Returns whether raster tiling is disabled.
void setForceVector(bool force)
Set whether to force vector output.
void setExportThemes(const QStringList &themes)
Sets the list of export themes.
@ LayerId
Stores the map layer ID.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:481
QgsMapThemeCollection * mapThemeCollection
Definition: qgsproject.h:115
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.