Skip to content

Commit

Permalink
Run layout validity checks before export
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 2, 2019
1 parent 7ccaa3d commit 102f075
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
Expand Up @@ -23,9 +23,17 @@ context, containing a reference to the QgsLayout to be checked.

%TypeHeaderCode
#include "qgsvaliditycheckcontext.h"
%End
%ConvertToSubClassCode
if ( dynamic_cast<QgsLayoutValidityCheckContext *>( sipCpp ) != NULL )
sipType = sipType_QgsLayoutValidityCheckContext;
else
sipType = 0;
%End
public:

virtual ~QgsValidityCheckContext();

};

class QgsLayoutValidityCheckContext : QgsValidityCheckContext
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -671,6 +671,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/scalebar
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/validity
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/symbology
${CMAKE_SOURCE_DIR}/src/gui/attributetable
Expand Down
46 changes: 46 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -67,6 +67,9 @@
#include "ui_qgssvgexportoptions.h"
#include "ui_qgspdfexportoptions.h"
#include "qgsproxyprogresstask.h"
#include "qgsvaliditycheckresultswidget.h"
#include "qgsabstractvaliditycheck.h"
#include "qgsvaliditycheckcontext.h"
#include "ui_defaults.h"

#include <QShortcut>
Expand Down Expand Up @@ -1835,6 +1838,9 @@ void QgsLayoutDesignerDialog::deleteLayout()

void QgsLayoutDesignerDialog::print()
{
if ( !checkBeforeExport() )
return;

if ( containsWmsLayers() )
{
showWmsPrintingWarning();
Expand Down Expand Up @@ -1941,6 +1947,9 @@ void QgsLayoutDesignerDialog::print()

void QgsLayoutDesignerDialog::exportToRaster()
{
if ( !checkBeforeExport() )
return;

if ( containsWmsLayers() )
showWmsPrintingWarning();

Expand Down Expand Up @@ -2032,6 +2041,9 @@ void QgsLayoutDesignerDialog::exportToRaster()

void QgsLayoutDesignerDialog::exportToPdf()
{
if ( !checkBeforeExport() )
return;

if ( containsWmsLayers() )
{
showWmsPrintingWarning();
Expand Down Expand Up @@ -2150,6 +2162,9 @@ void QgsLayoutDesignerDialog::exportToPdf()

void QgsLayoutDesignerDialog::exportToSvg()
{
if ( !checkBeforeExport() )
return;

if ( containsWmsLayers() )
{
showWmsPrintingWarning();
Expand Down Expand Up @@ -2406,6 +2421,9 @@ void QgsLayoutDesignerDialog::atlasLast()

void QgsLayoutDesignerDialog::printAtlas()
{
if ( !checkBeforeExport() )
return;

QgsLayoutAtlas *printAtlas = atlas();
if ( !printAtlas || !printAtlas->enabled() )
return;
Expand Down Expand Up @@ -2551,6 +2569,9 @@ void QgsLayoutDesignerDialog::printAtlas()

void QgsLayoutDesignerDialog::exportAtlasToRaster()
{
if ( !checkBeforeExport() )
return;

QgsLayoutAtlas *printAtlas = atlas();
if ( !printAtlas || !printAtlas->enabled() )
return;
Expand Down Expand Up @@ -2709,6 +2730,9 @@ void QgsLayoutDesignerDialog::exportAtlasToRaster()

void QgsLayoutDesignerDialog::exportAtlasToSvg()
{
if ( !checkBeforeExport() )
return;

QgsLayoutAtlas *printAtlas = atlas();
if ( !printAtlas || !printAtlas->enabled() )
return;
Expand Down Expand Up @@ -2877,6 +2901,9 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()

void QgsLayoutDesignerDialog::exportAtlasToPdf()
{
if ( !checkBeforeExport() )
return;

QgsLayoutAtlas *printAtlas = atlas();
if ( !printAtlas || !printAtlas->enabled() )
return;
Expand Down Expand Up @@ -3102,6 +3129,9 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()

void QgsLayoutDesignerDialog::exportReportToRaster()
{
if ( !checkBeforeExport() )
return;

QString outputFileName = QgsFileUtils::stringToSafeFilename( mMasterLayout->name() );

QPair<QString, QString> fileNExt = QgsGuiUtils::getSaveAsImageName( this, tr( "Save Report As" ), outputFileName );
Expand Down Expand Up @@ -3209,6 +3239,9 @@ void QgsLayoutDesignerDialog::exportReportToRaster()

void QgsLayoutDesignerDialog::exportReportToSvg()
{
if ( !checkBeforeExport() )
return;

showSvgExportWarning();

const QString defaultPath = defaultExportPath();
Expand Down Expand Up @@ -3337,6 +3370,9 @@ void QgsLayoutDesignerDialog::exportReportToSvg()

void QgsLayoutDesignerDialog::exportReportToPdf()
{
if ( !checkBeforeExport() )
return;

const QString defaultPath = defaultExportPath();

QString outputFileName = defaultPath + '/' + QgsFileUtils::stringToSafeFilename( mMasterLayout->name() ) + QStringLiteral( ".pdf" );
Expand Down Expand Up @@ -3466,6 +3502,9 @@ void QgsLayoutDesignerDialog::exportReportToPdf()

void QgsLayoutDesignerDialog::printReport()
{
if ( !checkBeforeExport() )
return;

QPrintDialog printDialog( printer(), nullptr );
if ( printDialog.exec() != QDialog::Accepted )
{
Expand Down Expand Up @@ -4409,6 +4448,13 @@ void QgsLayoutDesignerDialog::setLastExportPath( const QString &path ) const
QgsSettings().setValue( QStringLiteral( "lastLayoutExportDir" ), savePath, QgsSettings::App );
}

bool QgsLayoutDesignerDialog::checkBeforeExport()
{
QgsLayoutValidityCheckContext context( mLayout );
return QgsValidityCheckResultsWidget::runChecks( QgsAbstractValidityCheck::TypeLayoutCheck, &context, tr( "Checking Layout" ),
tr( "The layout generated the following warnings. Please review and address these before proceeding with the layout export." ), this );
}

void QgsLayoutDesignerDialog::updateWindowTitle()
{
QString title;
Expand Down
1 change: 1 addition & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -538,6 +538,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
QString defaultExportPath() const;
void setLastExportPath( const QString &path ) const;

bool checkBeforeExport();
};

#endif // QGSLAYOUTDESIGNERDIALOG_H
Expand Down
12 changes: 12 additions & 0 deletions src/core/validity/qgsvaliditycheckcontext.h
Expand Up @@ -34,9 +34,21 @@ class QgsLayout;
*/
class CORE_EXPORT QgsValidityCheckContext
{

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast<QgsLayoutValidityCheckContext *>( sipCpp ) != NULL )
sipType = sipType_QgsLayoutValidityCheckContext;
else
sipType = 0;
SIP_END
#endif

public:
// initially nothing in the base class!

virtual ~QgsValidityCheckContext() = default;

};

/**
Expand Down

0 comments on commit 102f075

Please sign in to comment.