QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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 allowGeospatialPdfExport, const QString &geospatialPdfReason, const QStringList &geospatialPdfLayerOrder, Qt::WindowFlags flags )
33 : QDialog( parent, flags )
34{
35 setupUi( this );
36
37 mGeospatialPdfStructureTreeMenu = 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 mTextRenderFormatComboBox->addItem( tr( "Prefer Exporting Text as Text Objects" ), static_cast< int >( Qgis::TextRenderFormat::PreferText ) );
42
43 mGeospatialPdfAvailable = allowGeospatialPdfExport && QgsAbstractGeospatialPdfExporter::geospatialPDFCreationAvailable();
44 mGeospatialPDFGroupBox->setEnabled( mGeospatialPdfAvailable );
45 mGeospatialPDFGroupBox->setChecked( false );
46 if ( !mGeospatialPdfAvailable )
47 {
48 mGeospatialPDFOptionsStackedWidget->setCurrentIndex( 0 );
49 mGeospatialPdfUnavailableReason->setText( geospatialPdfReason.isEmpty() ? QgsAbstractGeospatialPdfExporter::geospatialPDFAvailabilityExplanation() : geospatialPdfReason );
50 // avoid showing reason in disabled text color - we want it to stand out
51 QPalette p = mGeospatialPdfUnavailableReason->palette();
52 p.setColor( QPalette::Disabled, QPalette::WindowText, QPalette::WindowText );
53 mGeospatialPdfUnavailableReason->setPalette( p );
54 mGeospatialPDFOptionsStackedWidget->removeWidget( mGeospatialPDFOptionsStackedWidget->widget( 1 ) );
55 }
56 else
57 {
58 mGeospatialPDFOptionsStackedWidget->setCurrentIndex( 1 );
59 mGeospatialPdfFormatComboBox->addItem( tr( "ISO 32000 Extension (recommended)" ) );
60 mGeospatialPdfFormatComboBox->addItem( tr( "OGC Best Practice" ) );
61 }
62
63 mComboImageCompression->addItem( tr( "Lossy (JPEG)" ), false );
64 mComboImageCompression->addItem( tr( "Lossless" ), true );
65
66 const QStringList themes = QgsProject::instance()->mapThemeCollection()->mapThemes();
67 for ( const QString &theme : themes )
68 {
69 QListWidgetItem *item = new QListWidgetItem( theme );
70 item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
71 item->setCheckState( Qt::Unchecked );
72 mThemesList->addItem( item );
73 }
74
75 QList< QgsMapLayer * > order = QgsProject::instance()->layerTreeRoot()->layerOrder();
76 for ( auto it = geospatialPdfLayerOrder.rbegin(); it != geospatialPdfLayerOrder.rend(); ++it )
77 {
78 for ( int i = 0; i < order.size(); ++i )
79 {
80 if ( order.at( i )->id() == *it )
81 {
82 order.move( i, 0 );
83 break;
84 }
85 }
86 }
87 mGeospatialPdfStructureModel = new QgsGeospatialPdfLayerTreeModel( order, this );
88 mGeospatialPdfStructureProxyModel = new QgsGeospatialPdfLayerFilteredTreeModel( mGeospatialPdfStructureModel, this );
89 mGeospatialPdfStructureTree->setModel( mGeospatialPdfStructureProxyModel );
90 mGeospatialPdfStructureTree->resizeColumnToContents( 0 );
91 mGeospatialPdfStructureTree->header()->show();
92 mGeospatialPdfStructureTree->setSelectionMode( QAbstractItemView::SingleSelection );
93 mGeospatialPdfStructureTree->setSelectionBehavior( QAbstractItemView::SelectRows );
94
95 mGeospatialPdfStructureTree->setDragEnabled( true );
96 mGeospatialPdfStructureTree->setAcceptDrops( true );
97 mGeospatialPdfStructureTree->setDragDropMode( QAbstractItemView::InternalMove );
98 mGeospatialPdfStructureTree->setDefaultDropAction( Qt::MoveAction );
99
100 mGeospatialPdfStructureTree->setContextMenuPolicy( Qt::CustomContextMenu );
101 connect( mGeospatialPdfStructureTree, &QTreeView::customContextMenuRequested, this, [ = ]( const QPoint & point )
102 {
103 const QModelIndex index = mGeospatialPdfStructureTree->indexAt( point );
104 if ( index.isValid() )
105 showContextMenuForGeospatialPdfStructure( point, mGeospatialPdfStructureProxyModel->mapToSource( index ) );
106 } );
107
108 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
110}
111
113{
114 mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( static_cast< int >( format ) ) );
115}
116
118{
119 return static_cast< Qgis::TextRenderFormat >( mTextRenderFormatComboBox->currentData().toInt() );
120}
121
123{
124 mForceVectorCheckBox->setChecked( force );
125}
126
128{
129 return mForceVectorCheckBox->isChecked();
130}
131
133{
134 mAppendGeoreferenceCheckbox->setEnabled( enabled );
135}
136
138{
139 mAppendGeoreferenceCheckbox->setChecked( enabled );
140}
141
143{
144 return mAppendGeoreferenceCheckbox->isChecked();
145}
146
148{
149 mIncludeMetadataCheckbox->setChecked( enabled );
150}
151
153{
154 return mIncludeMetadataCheckbox->isChecked();
155}
156
158{
159 mDisableRasterTilingCheckBox->setChecked( disabled );
160}
161
163{
164 return mDisableRasterTilingCheckBox->isChecked();
165}
166
168{
169 mSimplifyGeometriesCheckbox->setChecked( enabled );
170}
171
173{
174 return mSimplifyGeometriesCheckbox->isChecked();
175}
176
178{
179 mComboImageCompression->setCurrentIndex( mComboImageCompression->findData( enabled ) );
180}
181
183{
184 return mComboImageCompression->currentData().toBool();
185}
186
188{
189 if ( !mGeospatialPdfAvailable )
190 return;
191
192 mGeospatialPDFGroupBox->setChecked( enabled );
193}
194
196{
197 if ( !mGeospatialPdfAvailable )
198 return false;
199
200 return mGeospatialPDFGroupBox->isChecked();
201}
202
204{
205 if ( !mGeospatialPdfAvailable )
206 return;
207
208 if ( enabled )
209 mGeospatialPdfFormatComboBox->setCurrentIndex( 1 );
210 else
211 mGeospatialPdfFormatComboBox->setCurrentIndex( 0 );
212}
213
215{
216 if ( !mGeospatialPdfAvailable )
217 return false;
218
219 return mGeospatialPdfFormatComboBox->currentIndex() == 1;
220}
221
222
224{
225 if ( !mGeospatialPdfAvailable )
226 return;
227
228 mIncludeMapThemesCheck->setChecked( !themes.isEmpty() );
229 for ( int i = 0; i < mThemesList->count(); ++i )
230 {
231 QListWidgetItem *item = mThemesList->item( i );
232 item->setCheckState( themes.contains( item->text() ) ? Qt::Checked : Qt::Unchecked );
233 }
234}
235
237{
238 QStringList res;
239 if ( !mGeospatialPdfAvailable )
240 return res;
241
242 if ( !mIncludeMapThemesCheck || !mIncludeMapThemesCheck->isChecked() )
243 return res;
244
245 res.reserve( mThemesList->count() );
246 for ( int i = 0; i < mThemesList->count(); ++i )
247 {
248 QListWidgetItem *item = mThemesList->item( i );
249 if ( item->checkState() == Qt::Checked )
250 res << item->text();
251 }
252 return res;
253}
254
256{
257 QStringList order;
258 for ( int row = 0; row < mGeospatialPdfStructureProxyModel->rowCount(); ++row )
259 {
260 order << mGeospatialPdfStructureProxyModel->data( mGeospatialPdfStructureProxyModel->index( row, 0 ), static_cast< int >( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
261 }
262 return order;
263}
264
266{
267 // we don't explicitly expose a "group order" widget in the dialog -- rather
268 // we use the ordering of the layers, and build the group ordering based
269 // on grouped layers which appear first
270 QStringList groupOrder;
271 for ( int row = 0; row < mGeospatialPdfStructureProxyModel->rowCount(); ++row )
272 {
273 const QString group = mGeospatialPdfStructureProxyModel->data( mGeospatialPdfStructureProxyModel->index( row, QgsGeospatialPdfLayerTreeModel::GroupColumn ), Qt::DisplayRole ).toString().trimmed();
274 if ( !group.isEmpty() && !groupOrder.contains( group ) )
275 groupOrder << group;
276 }
277 return groupOrder;
278}
279
281{
282 mOpenAfterExportingCheckBox->setChecked( enabled );
283}
284
286{
287 return mOpenAfterExportingCheckBox->isChecked();
288}
289
290void QgsLayoutPdfExportOptionsDialog::showHelp()
291{
292 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
293}
294
295void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeospatialPdfStructure( QPoint point, const QModelIndex &index )
296{
297 mGeospatialPdfStructureTreeMenu->clear();
298
299 switch ( index.column() )
300 {
303 {
304 QAction *selectAll = new QAction( tr( "Select All" ), mGeospatialPdfStructureTreeMenu );
305 mGeospatialPdfStructureTreeMenu->addAction( selectAll );
306 connect( selectAll, &QAction::triggered, this, [ = ]
307 {
308 mGeospatialPdfStructureModel->checkAll( true, QModelIndex(), index.column() );
309 } );
310 QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeospatialPdfStructureTreeMenu );
311 mGeospatialPdfStructureTreeMenu->addAction( deselectAll );
312 connect( deselectAll, &QAction::triggered, this, [ = ]
313 {
314 mGeospatialPdfStructureModel->checkAll( false, QModelIndex(), index.column() );
315 } );
316 break;
317 }
318
319 default:
320 break;
321 }
322
323 if ( !mGeospatialPdfStructureTreeMenu->actions().empty() )
324 {
325 mGeospatialPdfStructureTreeMenu->exec( mGeospatialPdfStructureTree->mapToGlobal( point ) );
326 }
327}
TextRenderFormat
Options for rendering text.
Definition qgis.h:2624
@ PreferText
Render text as text objects, unless doing so results in rendering artifacts or poor quality rendering...
@ 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 QString geospatialPDFAvailabilityExplanation()
Returns a user-friendly, translated string explaining why Geospatial PDF export support is not availa...
static bool geospatialPDFCreationAvailable()
Returns true if the current QGIS build is capable of Geospatial PDF support.
Layer tree model for Geo-PDF layers.
@ InitiallyVisible
Initial visibility state.
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:208
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 setExportGeospatialPdf(bool enabled)
Sets whether to export a Geospatial PDF.
void setOpenAfterExporting(bool enabled)
Sets whether to open the pdf after exporting it.
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 exportGeospatialPdf() const
Returns whether Geospatial PDF export is enabled.
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.
QStringList geospatialPdfGroupOrder() const
Returns a list of groups in the desired order they should appear in a generated Geospatial PDF file.
QgsLayoutPdfExportOptionsDialog(QWidget *parent=nullptr, bool allowGeospatialPdfExport=true, const QString &geospatialPdfReason=QString(), const QStringList &geospatialPdfLayerOrder=QStringList(), Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutPdfExportOptionsDialog.
QStringList geospatialPdfLayerOrder() const
Returns a list of map layer IDs in the desired order they should appear in a generated Geospatial PDF...
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.
QgsMapThemeCollection * mapThemeCollection
Definition qgsproject.h:115
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.