QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 "moc_qgslayoutpdfexportoptionsdialog.cpp"
19#include "qgis.h"
20#include "qgssettings.h"
21#include "qgsgui.h"
22#include "qgshelp.h"
24#include "qgsproject.h"
27#include "qgslayertree.h"
28
29#include <QCheckBox>
30#include <QPushButton>
31#include <QMenu>
32
33QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, bool allowGeospatialPdfExport, const QString &geospatialPdfReason, const QStringList &geospatialPdfLayerOrder, Qt::WindowFlags flags )
34 : QDialog( parent, flags )
35{
36 setupUi( this );
37
38 mGeospatialPdfStructureTreeMenu = new QMenu( this );
39
40 mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), static_cast< int >( Qgis::TextRenderFormat::AlwaysOutlines ) );
41 mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), static_cast< int >( Qgis::TextRenderFormat::AlwaysText ) );
42 mTextRenderFormatComboBox->addItem( tr( "Prefer Exporting Text as Text Objects" ), static_cast< int >( Qgis::TextRenderFormat::PreferText ) );
43
44 mGeospatialPdfAvailable = allowGeospatialPdfExport && QgsAbstractGeospatialPdfExporter::geospatialPDFCreationAvailable();
45 mGeospatialPDFGroupBox->setEnabled( mGeospatialPdfAvailable );
46 mGeospatialPDFGroupBox->setChecked( false );
47 if ( !mGeospatialPdfAvailable )
48 {
49 mGeospatialPDFOptionsStackedWidget->setCurrentIndex( 0 );
50 mGeospatialPdfUnavailableReason->setText( geospatialPdfReason.isEmpty() ? QgsAbstractGeospatialPdfExporter::geospatialPDFAvailabilityExplanation() : geospatialPdfReason );
51 // avoid showing reason in disabled text color - we want it to stand out
52 QPalette p = mGeospatialPdfUnavailableReason->palette();
53 p.setColor( QPalette::Disabled, QPalette::WindowText, QPalette::WindowText );
54 mGeospatialPdfUnavailableReason->setPalette( p );
55 mGeospatialPDFOptionsStackedWidget->removeWidget( mGeospatialPDFOptionsStackedWidget->widget( 1 ) );
56 }
57 else
58 {
59 mGeospatialPDFOptionsStackedWidget->setCurrentIndex( 1 );
60 mGeospatialPdfFormatComboBox->addItem( tr( "ISO 32000 Extension (recommended)" ) );
61 mGeospatialPdfFormatComboBox->addItem( tr( "OGC Best Practice" ) );
62 }
63
64 mComboImageCompression->addItem( tr( "Lossy (JPEG)" ), false );
65 mComboImageCompression->addItem( tr( "Lossless" ), true );
66
67 const QStringList themes = QgsProject::instance()->mapThemeCollection()->mapThemes();
68 for ( const QString &theme : themes )
69 {
70 QListWidgetItem *item = new QListWidgetItem( theme );
71 item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
72 item->setCheckState( Qt::Unchecked );
73 mThemesList->addItem( item );
74 }
75
76 QList< QgsMapLayer * > order = QgsProject::instance()->layerTreeRoot()->layerOrder();
77 for ( auto it = geospatialPdfLayerOrder.rbegin(); it != geospatialPdfLayerOrder.rend(); ++it )
78 {
79 for ( int i = 0; i < order.size(); ++i )
80 {
81 if ( order.at( i )->id() == *it )
82 {
83 order.move( i, 0 );
84 break;
85 }
86 }
87 }
88 mGeospatialPdfStructureModel = new QgsGeospatialPdfLayerTreeModel( order, this );
89 mGeospatialPdfStructureProxyModel = new QgsGeospatialPdfLayerFilteredTreeModel( mGeospatialPdfStructureModel, this );
90 mGeospatialPdfStructureTree->setModel( mGeospatialPdfStructureProxyModel );
91 mGeospatialPdfStructureTree->resizeColumnToContents( 0 );
92 mGeospatialPdfStructureTree->header()->show();
93 mGeospatialPdfStructureTree->setSelectionMode( QAbstractItemView::SingleSelection );
94 mGeospatialPdfStructureTree->setSelectionBehavior( QAbstractItemView::SelectRows );
95
96 mGeospatialPdfStructureTree->setDragEnabled( true );
97 mGeospatialPdfStructureTree->setAcceptDrops( true );
98 mGeospatialPdfStructureTree->setDragDropMode( QAbstractItemView::InternalMove );
99 mGeospatialPdfStructureTree->setDefaultDropAction( Qt::MoveAction );
100
101 mGeospatialPdfStructureTree->setContextMenuPolicy( Qt::CustomContextMenu );
102 connect( mGeospatialPdfStructureTree, &QTreeView::customContextMenuRequested, this, [ = ]( const QPoint & point )
103 {
104 const QModelIndex index = mGeospatialPdfStructureTree->indexAt( point );
105 if ( index.isValid() )
106 showContextMenuForGeospatialPdfStructure( point, mGeospatialPdfStructureProxyModel->mapToSource( index ) );
107 } );
108
109 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
111}
112
114{
115 mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( static_cast< int >( format ) ) );
116}
117
119{
120 return static_cast< Qgis::TextRenderFormat >( mTextRenderFormatComboBox->currentData().toInt() );
121}
122
124{
125 mForceVectorCheckBox->setChecked( force );
126}
127
129{
130 return mForceVectorCheckBox->isChecked();
131}
132
134{
135 mAppendGeoreferenceCheckbox->setEnabled( enabled );
136}
137
139{
140 mAppendGeoreferenceCheckbox->setChecked( enabled );
141}
142
144{
145 return mAppendGeoreferenceCheckbox->isChecked();
146}
147
149{
150 mIncludeMetadataCheckbox->setChecked( enabled );
151}
152
154{
155 return mIncludeMetadataCheckbox->isChecked();
156}
157
159{
160 mDisableRasterTilingCheckBox->setChecked( disabled );
161}
162
164{
165 return mDisableRasterTilingCheckBox->isChecked();
166}
167
169{
170 mSimplifyGeometriesCheckbox->setChecked( enabled );
171}
172
174{
175 return mSimplifyGeometriesCheckbox->isChecked();
176}
177
179{
180 mComboImageCompression->setCurrentIndex( mComboImageCompression->findData( enabled ) );
181}
182
184{
185 return mComboImageCompression->currentData().toBool();
186}
187
189{
190 if ( !mGeospatialPdfAvailable )
191 return;
192
193 mGeospatialPDFGroupBox->setChecked( enabled );
194}
195
197{
198 if ( !mGeospatialPdfAvailable )
199 return false;
200
201 return mGeospatialPDFGroupBox->isChecked();
202}
203
205{
206 if ( !mGeospatialPdfAvailable )
207 return;
208
209 if ( enabled )
210 mGeospatialPdfFormatComboBox->setCurrentIndex( 1 );
211 else
212 mGeospatialPdfFormatComboBox->setCurrentIndex( 0 );
213}
214
216{
217 if ( !mGeospatialPdfAvailable )
218 return false;
219
220 return mGeospatialPdfFormatComboBox->currentIndex() == 1;
221}
222
223
225{
226 if ( !mGeospatialPdfAvailable )
227 return;
228
229 mIncludeMapThemesCheck->setChecked( !themes.isEmpty() );
230 for ( int i = 0; i < mThemesList->count(); ++i )
231 {
232 QListWidgetItem *item = mThemesList->item( i );
233 item->setCheckState( themes.contains( item->text() ) ? Qt::Checked : Qt::Unchecked );
234 }
235}
236
238{
239 QStringList res;
240 if ( !mGeospatialPdfAvailable )
241 return res;
242
243 if ( !mIncludeMapThemesCheck || !mIncludeMapThemesCheck->isChecked() )
244 return res;
245
246 res.reserve( mThemesList->count() );
247 for ( int i = 0; i < mThemesList->count(); ++i )
248 {
249 QListWidgetItem *item = mThemesList->item( i );
250 if ( item->checkState() == Qt::Checked )
251 res << item->text();
252 }
253 return res;
254}
255
257{
258 QStringList order;
259 for ( int row = 0; row < mGeospatialPdfStructureProxyModel->rowCount(); ++row )
260 {
261 order << mGeospatialPdfStructureProxyModel->data( mGeospatialPdfStructureProxyModel->index( row, 0 ), static_cast< int >( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
262 }
263 return order;
264}
265
267{
268 // we don't explicitly expose a "group order" widget in the dialog -- rather
269 // we use the ordering of the layers, and build the group ordering based
270 // on grouped layers which appear first
271 QStringList groupOrder;
272 for ( int row = 0; row < mGeospatialPdfStructureProxyModel->rowCount(); ++row )
273 {
274 const QString group = mGeospatialPdfStructureProxyModel->data( mGeospatialPdfStructureProxyModel->index( row, QgsGeospatialPdfLayerTreeModel::GroupColumn ), Qt::DisplayRole ).toString().trimmed();
275 if ( !group.isEmpty() && !groupOrder.contains( group ) )
276 groupOrder << group;
277 }
278 return groupOrder;
279}
280
282{
283 mOpenAfterExportingCheckBox->setChecked( enabled );
284}
285
287{
288 return mOpenAfterExportingCheckBox->isChecked();
289}
290
291void QgsLayoutPdfExportOptionsDialog::showHelp()
292{
293 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
294}
295
296void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeospatialPdfStructure( QPoint point, const QModelIndex &index )
297{
298 mGeospatialPdfStructureTreeMenu->clear();
299
300 switch ( index.column() )
301 {
304 {
305 QAction *selectAll = new QAction( tr( "Select All" ), mGeospatialPdfStructureTreeMenu );
306 mGeospatialPdfStructureTreeMenu->addAction( selectAll );
307 connect( selectAll, &QAction::triggered, this, [ = ]
308 {
309 mGeospatialPdfStructureModel->checkAll( true, QModelIndex(), index.column() );
310 } );
311 QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeospatialPdfStructureTreeMenu );
312 mGeospatialPdfStructureTreeMenu->addAction( deselectAll );
313 connect( deselectAll, &QAction::triggered, this, [ = ]
314 {
315 mGeospatialPdfStructureModel->checkAll( false, QModelIndex(), index.column() );
316 } );
317 break;
318 }
319
320 default:
321 break;
322 }
323
324 if ( !mGeospatialPdfStructureTreeMenu->actions().empty() )
325 {
326 mGeospatialPdfStructureTreeMenu->exec( mGeospatialPdfStructureTree->mapToGlobal( point ) );
327 }
328}
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:209
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.