QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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( buttonBox, &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 ), QgsGeoPdfLayerTreeModel::LayerIdRole ).toString();
260 }
261 return order;
262}
263
264void QgsLayoutPdfExportOptionsDialog::showHelp()
265{
266 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
267}
268
269void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeoPdfStructure( QPoint point, const QModelIndex &index )
270{
271 mGeoPdfStructureTreeMenu->clear();
272
273 switch ( index.column() )
274 {
277 {
278 QAction *selectAll = new QAction( tr( "Select All" ), mGeoPdfStructureTreeMenu );
279 mGeoPdfStructureTreeMenu->addAction( selectAll );
280 connect( selectAll, &QAction::triggered, this, [ = ]
281 {
282 mGeoPdfStructureModel->checkAll( true, QModelIndex(), index.column() );
283 } );
284 QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeoPdfStructureTreeMenu );
285 mGeoPdfStructureTreeMenu->addAction( deselectAll );
286 connect( deselectAll, &QAction::triggered, this, [ = ]
287 {
288 mGeoPdfStructureModel->checkAll( false, QModelIndex(), index.column() );
289 } );
290 break;
291 }
292
293 default:
294 break;
295 }
296
297 if ( !mGeoPdfStructureTreeMenu->actions().empty() )
298 {
299 mGeoPdfStructureTreeMenu->exec( mGeoPdfStructureTree->mapToGlobal( point ) );
300 }
301}
TextRenderFormat
Options for rendering text.
Definition: qgis.h:1416
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 visiblity 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:178
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:38
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
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 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.
@ LayerIdRole
Stores the map layer ID.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:477
QgsMapThemeCollection * mapThemeCollection
Definition: qgsproject.h:112
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.