QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
19#include "qgis.h"
22#include "qgsgui.h"
23#include "qgshelp.h"
24#include "qgslayertree.h"
26#include "qgsproject.h"
27#include "qgssettings.h"
28
29#include <QCheckBox>
30#include <QMenu>
31#include <QPushButton>
32#include <QString>
33
34#include "moc_qgslayoutpdfexportoptionsdialog.cpp"
35
36using namespace Qt::StringLiterals;
37
38QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, bool allowGeospatialPdfExport, const QString &geospatialPdfReason, const QStringList &geospatialPdfLayerOrder, Qt::WindowFlags flags )
39 : QDialog( parent, flags )
40{
41 setupUi( this );
42
43 mGeospatialPdfStructureTreeMenu = new QMenu( this );
44
45 mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), static_cast<int>( Qgis::TextRenderFormat::AlwaysOutlines ) );
46 mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), static_cast<int>( Qgis::TextRenderFormat::AlwaysText ) );
47 mTextRenderFormatComboBox->addItem( tr( "Prefer Exporting Text as Text Objects" ), static_cast<int>( Qgis::TextRenderFormat::PreferText ) );
48
49 mGeospatialPdfAvailable = allowGeospatialPdfExport && QgsAbstractGeospatialPdfExporter::geospatialPDFCreationAvailable();
50 mGeospatialPDFGroupBox->setEnabled( mGeospatialPdfAvailable );
51 mGeospatialPDFGroupBox->setChecked( false );
52 if ( !mGeospatialPdfAvailable )
53 {
54 mGeospatialPDFOptionsStackedWidget->setCurrentIndex( 0 );
55 mGeospatialPdfUnavailableReason->setText( geospatialPdfReason.isEmpty() ? QgsAbstractGeospatialPdfExporter::geospatialPDFAvailabilityExplanation() : geospatialPdfReason );
56 // avoid showing reason in disabled text color - we want it to stand out
57 QPalette p = mGeospatialPdfUnavailableReason->palette();
58 p.setColor( QPalette::Disabled, QPalette::WindowText, QPalette::WindowText );
59 mGeospatialPdfUnavailableReason->setPalette( p );
60 mGeospatialPDFOptionsStackedWidget->removeWidget( mGeospatialPDFOptionsStackedWidget->widget( 1 ) );
61 }
62 else
63 {
64 mGeospatialPDFOptionsStackedWidget->setCurrentIndex( 1 );
65 }
66
67 mComboImageCompression->addItem( tr( "Lossy (JPEG)" ), false );
68 mComboImageCompression->addItem( tr( "Lossless" ), true );
69
70 const QStringList themes = QgsProject::instance()->mapThemeCollection()->mapThemes();
71 for ( const QString &theme : themes )
72 {
73 QListWidgetItem *item = new QListWidgetItem( theme );
74 item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
75 item->setCheckState( Qt::Unchecked );
76 mThemesList->addItem( item );
77 }
78
79 QList<QgsMapLayer *> order = QgsProject::instance()->layerTreeRoot()->layerOrder();
80 for ( auto it = geospatialPdfLayerOrder.rbegin(); it != geospatialPdfLayerOrder.rend(); ++it )
81 {
82 for ( int i = 0; i < order.size(); ++i )
83 {
84 if ( order.at( i )->id() == *it )
85 {
86 order.move( i, 0 );
87 break;
88 }
89 }
90 }
91 mGeospatialPdfStructureModel = new QgsGeospatialPdfLayerTreeModel( order, this );
92 mGeospatialPdfStructureProxyModel = new QgsGeospatialPdfLayerFilteredTreeModel( mGeospatialPdfStructureModel, this );
93 mGeospatialPdfStructureTree->setModel( mGeospatialPdfStructureProxyModel );
94 mGeospatialPdfStructureTree->resizeColumnToContents( 0 );
95 mGeospatialPdfStructureTree->header()->show();
96 mGeospatialPdfStructureTree->setSelectionMode( QAbstractItemView::SingleSelection );
97 mGeospatialPdfStructureTree->setSelectionBehavior( QAbstractItemView::SelectRows );
98
99 mGeospatialPdfStructureTree->setDragEnabled( true );
100 mGeospatialPdfStructureTree->setAcceptDrops( true );
101 mGeospatialPdfStructureTree->setDragDropMode( QAbstractItemView::InternalMove );
102 mGeospatialPdfStructureTree->setDefaultDropAction( Qt::MoveAction );
103
104 mGeospatialPdfStructureTree->setContextMenuPolicy( Qt::CustomContextMenu );
105 connect( mGeospatialPdfStructureTree, &QTreeView::customContextMenuRequested, this, [this]( const QPoint &point ) {
106 const QModelIndex index = mGeospatialPdfStructureTree->indexAt( point );
107 if ( index.isValid() )
108 showContextMenuForGeospatialPdfStructure( point, mGeospatialPdfStructureProxyModel->mapToSource( index ) );
109 } );
110
111 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
113}
114
116{
117 mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( static_cast<int>( format ) ) );
118}
119
121{
122 return static_cast<Qgis::TextRenderFormat>( mTextRenderFormatComboBox->currentData().toInt() );
123}
124
126{
127 mForceVectorCheckBox->setChecked( force );
128}
129
131{
132 return mForceVectorCheckBox->isChecked();
133}
134
136{
137 mAppendGeoreferenceCheckbox->setEnabled( enabled );
138}
139
141{
142 mAppendGeoreferenceCheckbox->setChecked( enabled );
143}
144
146{
147 return mAppendGeoreferenceCheckbox->isChecked();
148}
149
151{
152 mIncludeMetadataCheckbox->setChecked( enabled );
153}
154
156{
157 return mIncludeMetadataCheckbox->isChecked();
158}
159
161{
162 mDisableRasterTilingCheckBox->setChecked( disabled );
163}
164
166{
167 return mDisableRasterTilingCheckBox->isChecked();
168}
169
171{
172 mSimplifyGeometriesCheckbox->setChecked( enabled );
173}
174
176{
177 return mSimplifyGeometriesCheckbox->isChecked();
178}
179
181{
182 mComboImageCompression->setCurrentIndex( mComboImageCompression->findData( enabled ) );
183}
184
186{
187 return mComboImageCompression->currentData().toBool();
188}
189
191{
192 if ( !mGeospatialPdfAvailable )
193 return;
194
195 mGeospatialPDFGroupBox->setChecked( enabled );
196}
197
199{
200 if ( !mGeospatialPdfAvailable )
201 return false;
202
203 return mGeospatialPDFGroupBox->isChecked();
204}
205
207{
208 if ( !mGeospatialPdfAvailable )
209 return;
210
211 mIncludeMapThemesCheck->setChecked( !themes.isEmpty() );
212 for ( int i = 0; i < mThemesList->count(); ++i )
213 {
214 QListWidgetItem *item = mThemesList->item( i );
215 item->setCheckState( themes.contains( item->text() ) ? Qt::Checked : Qt::Unchecked );
216 }
217}
218
220{
221 QStringList res;
222 if ( !mGeospatialPdfAvailable )
223 return res;
224
225 if ( !mIncludeMapThemesCheck || !mIncludeMapThemesCheck->isChecked() )
226 return res;
227
228 res.reserve( mThemesList->count() );
229 for ( int i = 0; i < mThemesList->count(); ++i )
230 {
231 QListWidgetItem *item = mThemesList->item( i );
232 if ( item->checkState() == Qt::Checked )
233 res << item->text();
234 }
235 return res;
236}
237
239{
240 QStringList order;
241 for ( int row = 0; row < mGeospatialPdfStructureProxyModel->rowCount(); ++row )
242 {
243 order << mGeospatialPdfStructureProxyModel->data( mGeospatialPdfStructureProxyModel->index( row, 0 ), static_cast<int>( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
244 }
245 return order;
246}
247
249{
250 // we don't explicitly expose a "group order" widget in the dialog -- rather
251 // we use the ordering of the layers, and build the group ordering based
252 // on grouped layers which appear first
253 QStringList groupOrder;
254 for ( int row = 0; row < mGeospatialPdfStructureProxyModel->rowCount(); ++row )
255 {
256 const QString group = mGeospatialPdfStructureProxyModel->data( mGeospatialPdfStructureProxyModel->index( row, QgsGeospatialPdfLayerTreeModel::GroupColumn ), Qt::DisplayRole ).toString().trimmed();
257 if ( !group.isEmpty() && !groupOrder.contains( group ) )
258 groupOrder << group;
259 }
260 return groupOrder;
261}
262
264{
265 mOpenAfterExportingCheckBox->setChecked( enabled );
266}
267
269{
270 return mOpenAfterExportingCheckBox->isChecked();
271}
272
273void QgsLayoutPdfExportOptionsDialog::showHelp()
274{
275 QgsHelp::openHelp( u"print_composer/create_output.html"_s );
276}
277
278void QgsLayoutPdfExportOptionsDialog::showContextMenuForGeospatialPdfStructure( QPoint point, const QModelIndex &index )
279{
280 mGeospatialPdfStructureTreeMenu->clear();
281
282 switch ( index.column() )
283 {
286 {
287 QAction *selectAll = new QAction( tr( "Select All" ), mGeospatialPdfStructureTreeMenu );
288 mGeospatialPdfStructureTreeMenu->addAction( selectAll );
289 connect( selectAll, &QAction::triggered, this, [this, index] {
290 mGeospatialPdfStructureModel->checkAll( true, QModelIndex(), index.column() );
291 } );
292 QAction *deselectAll = new QAction( tr( "Deselect All" ), mGeospatialPdfStructureTreeMenu );
293 mGeospatialPdfStructureTreeMenu->addAction( deselectAll );
294 connect( deselectAll, &QAction::triggered, this, [this, index] {
295 mGeospatialPdfStructureModel->checkAll( false, QModelIndex(), index.column() );
296 } );
297 break;
298 }
299
300 default:
301 break;
302 }
303
304 if ( !mGeospatialPdfStructureTreeMenu->actions().empty() )
305 {
306 mGeospatialPdfStructureTreeMenu->exec( mGeospatialPdfStructureTree->mapToGlobal( point ) );
307 }
308}
TextRenderFormat
Options for rendering text.
Definition qgis.h:2884
@ PreferText
Render text as text objects, unless doing so results in rendering artifacts or poor quality rendering...
Definition qgis.h:2887
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
Definition qgis.h:2885
@ AlwaysText
Always render text as text objects. While this mode preserves text objects as text for post-processin...
Definition qgis.h:2886
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.
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:224
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
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 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.
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:122
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.