mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-22 00:06:57 -04:00
[layouts][needs-docs] Add a PDF export settings dialog which is shown
whenever exporting a layout to PDF This matches the behavior with SVG and raster exports, and allows users to set specific properties for the export (such as text rendering format) Fixes #8844
This commit is contained in:
parent
15abbcf86b
commit
8ea3889368
@ -65,6 +65,7 @@
|
|||||||
#include "qgsreportorganizerwidget.h"
|
#include "qgsreportorganizerwidget.h"
|
||||||
#include "qgsreadwritecontext.h"
|
#include "qgsreadwritecontext.h"
|
||||||
#include "ui_qgssvgexportoptions.h"
|
#include "ui_qgssvgexportoptions.h"
|
||||||
|
#include "ui_qgspdfexportoptions.h"
|
||||||
#include "qgsproxyprogresstask.h"
|
#include "qgsproxyprogresstask.h"
|
||||||
#include "ui_defaults.h"
|
#include "ui_defaults.h"
|
||||||
|
|
||||||
@ -2065,13 +2066,15 @@ void QgsLayoutDesignerDialog::exportToPdf()
|
|||||||
|
|
||||||
mView->setPaintingEnabled( false );
|
mView->setPaintingEnabled( false );
|
||||||
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
|
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
|
||||||
|
|
||||||
|
QgsLayoutExporter::PdfExportSettings pdfSettings;
|
||||||
|
if ( !getPdfExportSettings( pdfSettings ) )
|
||||||
|
return;
|
||||||
|
|
||||||
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
|
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
|
||||||
QgsApplication::taskManager()->addTask( proxyTask );
|
QgsApplication::taskManager()->addTask( proxyTask );
|
||||||
|
|
||||||
QgsLayoutExporter::PdfExportSettings pdfSettings;
|
|
||||||
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
|
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
|
||||||
pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
|
|
||||||
pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat();
|
|
||||||
|
|
||||||
// force a refresh, to e.g. update data defined properties, tables, etc
|
// force a refresh, to e.g. update data defined properties, tables, etc
|
||||||
mLayout->refresh();
|
mLayout->refresh();
|
||||||
@ -2968,9 +2971,10 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
|
|||||||
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
|
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
|
||||||
|
|
||||||
QgsLayoutExporter::PdfExportSettings pdfSettings;
|
QgsLayoutExporter::PdfExportSettings pdfSettings;
|
||||||
|
if ( !getPdfExportSettings( pdfSettings ) )
|
||||||
|
return;
|
||||||
|
|
||||||
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
|
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
|
||||||
pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
|
|
||||||
pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat();
|
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
|
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
|
||||||
@ -3345,17 +3349,15 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
|
|||||||
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
|
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
|
||||||
|
|
||||||
bool rasterize = false;
|
bool rasterize = false;
|
||||||
bool forceVectorOutput = false;
|
|
||||||
if ( mLayout )
|
if ( mLayout )
|
||||||
{
|
{
|
||||||
rasterize = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
|
rasterize = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
|
||||||
forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
|
|
||||||
}
|
}
|
||||||
QgsLayoutExporter::PdfExportSettings pdfSettings;
|
QgsLayoutExporter::PdfExportSettings pdfSettings;
|
||||||
// TODO - show a dialog allowing users to control these settings on a per-output basis
|
if ( !getPdfExportSettings( pdfSettings ) )
|
||||||
|
return;
|
||||||
|
|
||||||
pdfSettings.rasterizeWholeImage = rasterize;
|
pdfSettings.rasterizeWholeImage = rasterize;
|
||||||
pdfSettings.forceVectorOutput = forceVectorOutput;
|
|
||||||
pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat();
|
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
|
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
|
||||||
@ -4047,6 +4049,55 @@ bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsLayoutDesignerDialog::getPdfExportSettings( QgsLayoutExporter::PdfExportSettings &settings )
|
||||||
|
{
|
||||||
|
QgsRenderContext::TextRenderFormat prevTextRenderFormat = mMasterLayout->layoutProject()->labelingEngineSettings().defaultTextRenderFormat();
|
||||||
|
bool previousForceVector = false;
|
||||||
|
bool includeMetadata = true;
|
||||||
|
if ( mLayout )
|
||||||
|
{
|
||||||
|
mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
|
||||||
|
includeMetadata = mLayout->customProperty( QStringLiteral( "pdfIncludeMetadata" ), 1 ).toBool();
|
||||||
|
const int prevLayoutSettingLabelsAsOutlines = mLayout->customProperty( QStringLiteral( "pdfTextFormat" ), -1 ).toInt();
|
||||||
|
if ( prevLayoutSettingLabelsAsOutlines >= 0 )
|
||||||
|
{
|
||||||
|
// previous layout setting takes default over project setting
|
||||||
|
prevTextRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( prevLayoutSettingLabelsAsOutlines );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// open options dialog
|
||||||
|
QDialog dialog;
|
||||||
|
Ui::QgsPdfExportOptionsDialog options;
|
||||||
|
options.setupUi( &dialog );
|
||||||
|
|
||||||
|
options.mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
|
||||||
|
options.mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText );
|
||||||
|
|
||||||
|
options.mTextRenderFormatComboBox->setCurrentIndex( options.mTextRenderFormatComboBox->findData( prevTextRenderFormat ) );
|
||||||
|
options.mForceVectorCheckBox->setChecked( previousForceVector );
|
||||||
|
options.mIncludeMetadataCheckbox->setChecked( includeMetadata );
|
||||||
|
|
||||||
|
if ( dialog.exec() != QDialog::Accepted )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
includeMetadata = options.mIncludeMetadataCheckbox->isChecked();
|
||||||
|
QgsRenderContext::TextRenderFormat textRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( options.mTextRenderFormatComboBox->currentData().toInt() );
|
||||||
|
|
||||||
|
if ( mLayout )
|
||||||
|
{
|
||||||
|
//save dialog settings
|
||||||
|
mLayout->setCustomProperty( QStringLiteral( "pdfIncludeMetadata" ), includeMetadata ? 1 : 0 );
|
||||||
|
mLayout->setCustomProperty( QStringLiteral( "pdfTextFormat" ), static_cast< int >( textRenderFormat ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.forceVectorOutput = options.mForceVectorCheckBox->isChecked();
|
||||||
|
settings.exportMetadata = includeMetadata;
|
||||||
|
settings.textRenderFormat = textRenderFormat;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void QgsLayoutDesignerDialog::toggleAtlasControls( bool atlasEnabled )
|
void QgsLayoutDesignerDialog::toggleAtlasControls( bool atlasEnabled )
|
||||||
{
|
{
|
||||||
//preview defaults to unchecked
|
//preview defaults to unchecked
|
||||||
|
@ -505,6 +505,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
|
|||||||
bool showFileSizeWarning();
|
bool showFileSizeWarning();
|
||||||
bool getRasterExportSettings( QgsLayoutExporter::ImageExportSettings &settings, QSize &imageSize );
|
bool getRasterExportSettings( QgsLayoutExporter::ImageExportSettings &settings, QSize &imageSize );
|
||||||
bool getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings );
|
bool getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings );
|
||||||
|
bool getPdfExportSettings( QgsLayoutExporter::PdfExportSettings &settings );
|
||||||
|
|
||||||
void toggleAtlasActions( bool enabled );
|
void toggleAtlasActions( bool enabled );
|
||||||
|
|
||||||
|
129
src/ui/layout/qgspdfexportoptions.ui
Normal file
129
src/ui/layout/qgspdfexportoptions.ui
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QgsPdfExportOptionsDialog</class>
|
||||||
|
<widget class="QDialog" name="QgsPdfExportOptionsDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>489</width>
|
||||||
|
<height>190</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>PDF Export Options</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>PDF Options</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="mIncludeMetadataCheckbox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Export RDF metadata</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QComboBox" name="mTextRenderFormatComboBox"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>Text export</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="mForceVectorCheckBox">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>If checked, the layout will always be kept as vector objects when exported to a compatible format, even if the appearance of the resultant file does not match the layouts settings. If unchecked, some elements in the layout may be rasterized in order to keep their appearance intact.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Always export as vectors</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsCollapsibleGroupBoxBasic</class>
|
||||||
|
<extends>QGroupBox</extends>
|
||||||
|
<header location="global">qgscollapsiblegroupbox.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>mForceVectorCheckBox</tabstop>
|
||||||
|
<tabstop>mIncludeMetadataCheckbox</tabstop>
|
||||||
|
<tabstop>mTextRenderFormatComboBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>QgsPdfExportOptionsDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>QgsPdfExportOptionsDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user