QGIS API Documentation  3.12.1-București (121cc00ff0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
24 #include "qgsmapthemecollection.h"
26 
27 #include <QCheckBox>
28 #include <QPushButton>
29 
31  : QDialog( parent, flags )
32 {
33  setupUi( this );
34 
35  mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
36  mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText );
37 
39  mGeoPDFGroupBox->setEnabled( mGeopdfAvailable );
40  mGeoPDFGroupBox->setChecked( false );
41  if ( !mGeopdfAvailable )
42  {
43  mGeoPDFOptionsStackedWidget->setCurrentIndex( 0 );
44  mGeoPdfUnavailableReason->setText( QgsAbstractGeoPdfExporter::geoPDFAvailabilityExplanation() );
45  // avoid showing reason in disabled text color - we want it to stand out
46  QPalette p = mGeoPdfUnavailableReason->palette();
47  p.setColor( QPalette::Disabled, QPalette::WindowText, QPalette::WindowText );
48  mGeoPdfUnavailableReason->setPalette( p );
49  mGeoPDFOptionsStackedWidget->removeWidget( mGeoPDFOptionsStackedWidget->widget( 1 ) );
50  }
51  else
52  {
53  mGeoPDFOptionsStackedWidget->setCurrentIndex( 1 );
54  mGeoPdfFormatComboBox->addItem( tr( "ISO 32000 Extension (recommended)" ) );
55  mGeoPdfFormatComboBox->addItem( tr( "OGC Best Practice" ) );
56  }
57 
58  const QStringList themes = QgsProject::instance()->mapThemeCollection()->mapThemes();
59  for ( const QString &theme : themes )
60  {
61  QListWidgetItem *item = new QListWidgetItem( theme );
62  item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
63  item->setCheckState( Qt::Unchecked );
64  mThemesList->addItem( item );
65  }
66 
67  QgsGeoPdfLayerTreeModel *model = new QgsGeoPdfLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
68  mGeoPdfStructureTree->setModel( model );
69  mGeoPdfStructureTree->resizeColumnToContents( 0 );
70  mGeoPdfStructureTree->header()->show();
71  mGeoPdfStructureTree->setSelectionMode( QAbstractItemView::NoSelection );
72 
73  connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutPdfExportOptionsDialog::showHelp );
75 }
76 
78 {
79  mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( format ) );
80 }
81 
83 {
84  return static_cast< QgsRenderContext::TextRenderFormat >( mTextRenderFormatComboBox->currentData().toInt() );
85 }
86 
88 {
89  mForceVectorCheckBox->setChecked( force );
90 }
91 
93 {
94  return mForceVectorCheckBox->isChecked();
95 }
96 
98 {
99  mAppendGeoreferenceCheckbox->setEnabled( enabled );
100 }
101 
103 {
104  mAppendGeoreferenceCheckbox->setChecked( enabled );
105 }
106 
108 {
109  return mAppendGeoreferenceCheckbox->isChecked();;
110 }
111 
113 {
114  mIncludeMetadataCheckbox->setChecked( enabled );
115 }
116 
118 {
119  return mIncludeMetadataCheckbox->isChecked();
120 }
121 
123 {
124  mDisableRasterTilingCheckBox->setChecked( disabled );
125 }
126 
128 {
129  return mDisableRasterTilingCheckBox->isChecked();
130 }
131 
133 {
134  mSimplifyGeometriesCheckbox->setChecked( enabled );
135 }
136 
138 {
139  return mSimplifyGeometriesCheckbox->isChecked();
140 }
141 
143 {
144  if ( !mGeopdfAvailable )
145  return;
146 
147  mGeoPDFGroupBox->setChecked( enabled );
148 }
149 
151 {
152  if ( !mGeopdfAvailable )
153  return false;
154 
155  return mGeoPDFGroupBox->isChecked();
156 }
157 
159 {
160  if ( !mGeopdfAvailable )
161  return;
162 
163  if ( enabled )
164  mGeoPdfFormatComboBox->setCurrentIndex( 1 );
165  else
166  mGeoPdfFormatComboBox->setCurrentIndex( 0 );
167 }
168 
170 {
171  if ( !mGeopdfAvailable )
172  return false;
173 
174  return mGeoPdfFormatComboBox->currentIndex() == 1;
175 }
176 
178 {
179  if ( !mGeopdfAvailable )
180  return;
181 
182  mExportGeoPdfFeaturesCheckBox->setChecked( enabled );
183 }
184 
186 {
187  if ( !mGeopdfAvailable )
188  return false;
189 
190  return mExportGeoPdfFeaturesCheckBox->isChecked();
191 }
192 
193 void QgsLayoutPdfExportOptionsDialog::setExportThemes( const QStringList &themes )
194 {
195  if ( !mGeopdfAvailable )
196  return;
197 
198  mIncludeMapThemesCheck->setChecked( !themes.isEmpty() );
199  for ( int i = 0; i < mThemesList->count(); ++i )
200  {
201  QListWidgetItem *item = mThemesList->item( i );
202  item->setCheckState( themes.contains( item->text() ) ? Qt::Checked : Qt::Unchecked );
203  }
204 }
205 
207 {
208  QStringList res;
209  if ( !mGeopdfAvailable )
210  return res;
211 
212  if ( !mIncludeMapThemesCheck || !mIncludeMapThemesCheck->isChecked() )
213  return res;
214 
215  res.reserve( mThemesList->count() );
216  for ( int i = 0; i < mThemesList->count(); ++i )
217  {
218  QListWidgetItem *item = mThemesList->item( i );
219  if ( item->checkState() == Qt::Checked )
220  res << item->text();
221  }
222  return res;
223 }
224 
225 void QgsLayoutPdfExportOptionsDialog::showHelp()
226 {
227  QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
228 }
bool exportGeoPdfFeatures() const
Returns whether export of Geo-PDF features is enabled.
Always render text as text objects.
QgsLayoutPdfExportOptionsDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=nullptr)
Constructor for QgsLayoutPdfExportOptionsDialog.
void setGeometriesSimplified(bool enabled)
Sets whether to simplify geometries.
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the current text render format.
bool forceVector() const
Returns whether vector output is being forced.
void setExportGeoPdfFeatures(bool enabled)
Sets whether to export Geo-PDF features.
bool metadataEnabled() const
Returns whether metadata is enabled.
void setUseOgcBestPracticeFormat(bool enabled)
Sets whether to use OGC best-practice format.
bool rasterTilingDisabled() const
Returns whether raster tiling is disabled.
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format.
QgsMapThemeCollection mapThemeCollection
Definition: qgsproject.h:100
Always render text using path objects (AKA outlines/curves).
void setRasterTilingDisabled(bool disabled)
Sets whether to disable raster tiling.
void setGeoreferencingEnabled(bool enabled)
Sets whether to enable georeferencing.
void enableGeoreferencingOptions(bool enabled)
Sets whether to enable georeferencing options.
bool useOgcBestPracticeFormat() const
Returns whether use of OGC best-practice format is enabled.
TextRenderFormat
Options for rendering text.
bool georeferencingEnabled() const
Returns whether georeferencing is enabled.
bool geometriesSimplified() const
Returns whether geometry simplification is enabled.
void setExportGeoPdf(bool enabled)
Sets whether to export a Geo-PDF.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:450
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:133
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
void setExportThemes(const QStringList &themes)
Sets the list of export themes.
QStringList exportThemes() const
Returns the list of export themes.
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.
void setMetadataEnabled(bool enabled)
Sets whether to enable metadata.
void setForceVector(bool force)
Set whether to force vector output.
bool exportGeoPdf() const
Returns whether Geo-PDF export is enabled.
static bool geoPDFCreationAvailable()
Returns true if the current QGIS build is capable of GeoPDF support.