Skip to content
Permalink
Browse files

[layouts] Prevent GeoPDF export if map items do not have a valid CRS set

And show a friendly message explaining this

Fixes #35242
  • Loading branch information
nyalldawson committed May 28, 2020
1 parent 8632bf6 commit 5c1aa4fce26386cd261599347f30de7d601a65ef
@@ -4353,7 +4353,23 @@ bool QgsLayoutDesignerDialog::getPdfExportSettings( QgsLayoutExporter::PdfExport
}

// open options dialog
QgsLayoutPdfExportOptionsDialog dialog( this );

QList< QgsLayoutItemMap * > maps;
if ( mLayout )
mLayout->layoutItems( maps );
bool allowGeoPdfExport = true;
QString geoPdfReason;
for ( const QgsLayoutItemMap *map : maps )
{
if ( !map->crs().isValid() )
{
allowGeoPdfExport = false;
geoPdfReason = tr( "One or more map items do not have a valid CRS set. This is required for GeoPDF export." );
break;
}
}

QgsLayoutPdfExportOptionsDialog dialog( this, allowGeoPdfExport, geoPdfReason );

dialog.setTextRenderFormat( prevTextRenderFormat );
dialog.setForceVector( forceVector );
@@ -28,7 +28,7 @@
#include <QPushButton>
#include <QMenu>

QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, Qt::WindowFlags flags )
QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *parent, bool allowGeoPdfExport, const QString &geoPdfReason, Qt::WindowFlags flags )
: QDialog( parent, flags )
{
setupUi( this );
@@ -38,13 +38,13 @@ QgsLayoutPdfExportOptionsDialog::QgsLayoutPdfExportOptionsDialog( QWidget *paren
mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText );

mGeopdfAvailable = QgsAbstractGeoPdfExporter::geoPDFCreationAvailable();
mGeopdfAvailable = allowGeoPdfExport && QgsAbstractGeoPdfExporter::geoPDFCreationAvailable();
mGeoPDFGroupBox->setEnabled( mGeopdfAvailable );
mGeoPDFGroupBox->setChecked( false );
if ( !mGeopdfAvailable )
{
mGeoPDFOptionsStackedWidget->setCurrentIndex( 0 );
mGeoPdfUnavailableReason->setText( QgsAbstractGeoPdfExporter::geoPDFAvailabilityExplanation() );
mGeoPdfUnavailableReason->setText( geoPdfReason.isEmpty() ? QgsAbstractGeoPdfExporter::geoPDFAvailabilityExplanation() : geoPdfReason );
// avoid showing reason in disabled text color - we want it to stand out
QPalette p = mGeoPdfUnavailableReason->palette();
p.setColor( QPalette::Disabled, QPalette::WindowText, QPalette::WindowText );
@@ -46,9 +46,14 @@ class GUI_EXPORT QgsLayoutPdfExportOptionsDialog: public QDialog, private Ui::Qg
/**
* Constructor for QgsLayoutPdfExportOptionsDialog
* \param parent parent widget
* \param allowGeoPdfExport set to FALSE if geoPdf export is blocked
* \param geoPdfReason set to a descriptive translated string explaining why geopdf export is not available if applicable
* \param flags window flags
*/
QgsLayoutPdfExportOptionsDialog( QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr );
QgsLayoutPdfExportOptionsDialog( QWidget *parent = nullptr,
bool allowGeoPdfExport = true,
const QString &geoPdfReason = QString(),
Qt::WindowFlags flags = nullptr );

//! Sets the text render format
void setTextRenderFormat( QgsRenderContext::TextRenderFormat format );

0 comments on commit 5c1aa4f

Please sign in to comment.
You can’t perform that action at this time.