Skip to content
Permalink
Browse files
[api] Add method for plugins to retrieve results of last layout export
operation from a layout designer window
  • Loading branch information
nyalldawson committed Jun 9, 2021
1 parent 2a57287 commit e62714484fc4f7ea07e955f7d92505669dd0b8ec
@@ -413,6 +413,34 @@ Removes the specified ``dock`` widget from layout designer (without deleting it)
Activates a standard layout designer ``tool``.

.. versionadded:: 3.6
%End

class ExportResults
{
%Docstring(signature="appended")
Encapsulates the results of an export operation performed in the designer.

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgslayoutdesignerinterface.h"
%End
public:

QgsLayoutExporter::ExportResult result;

QMap< QString, QgsLabelingResults * > labelingResults;

};

virtual QgsLayoutDesignerInterface::ExportResults *lastExportResults() const = 0 /Factory/;
%Docstring
Returns the results of the last export operation performed in the designer.

May be ``None`` if no export has been performed in the designer.

.. versionadded:: 3.20
%End

public slots:
@@ -247,6 +247,11 @@ void QgsAppLayoutDesignerInterface::activateTool( QgsLayoutDesignerInterface::St
}
}

QgsLayoutDesignerInterface::ExportResults *QgsAppLayoutDesignerInterface::lastExportResults() const
{
return mDesigner->lastExportResults().release();
}

void QgsAppLayoutDesignerInterface::close()
{
mDesigner->close();
@@ -1010,6 +1015,9 @@ QgsLayoutDesignerDialog::~QgsLayoutDesignerDialog()
settings.remove( QStringLiteral( "LayoutDesigner/hiddenDocksTitle" ), QgsSettings::App );
settings.remove( QStringLiteral( "LayoutDesigner/hiddenDocksActive" ), QgsSettings::App );
}

qDeleteAll( mLastExportLabelingResults );
mLastExportLabelingResults.clear();
}

QgsAppLayoutDesignerInterface *QgsLayoutDesignerDialog::iface()
@@ -1103,6 +1111,11 @@ void QgsLayoutDesignerDialog::showGuideDock( bool show )
mGuideDock->setUserVisible( show );
}

std::unique_ptr<QgsLayoutDesignerInterface::ExportResults> QgsLayoutDesignerDialog::lastExportResults() const
{
return mLastExportResults ? std::make_unique< QgsLayoutDesignerInterface::ExportResults>( *mLastExportResults ) : nullptr;
}

QgsLayout *QgsLayoutDesignerDialog::currentLayout()
{
return mLayout;
@@ -2097,6 +2110,7 @@ void QgsLayoutDesignerDialog::print()
QgsLayoutExporter::ExportResult result = exporter.print( *p, printSettings );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result, &exporter );

switch ( result )
{
@@ -2211,6 +2225,7 @@ void QgsLayoutDesignerDialog::exportToRaster()
QgsLayoutExporter::ExportResult result = exporter.exportToImage( fileNExt.first, settings );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result, &exporter );

switch ( result )
{
@@ -2324,6 +2339,7 @@ void QgsLayoutDesignerDialog::exportToPdf()
QgsLayoutExporter::ExportResult result = exporter.exportToPdf( outputFileName, pdfSettings );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result, &exporter );

switch ( result )
{
@@ -2435,6 +2451,7 @@ void QgsLayoutDesignerDialog::exportToSvg()
QgsLayoutExporter::ExportResult result = exporter.exportToSvg( outputFileName, svgSettings );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result, &exporter );

switch ( result )
{
@@ -2709,6 +2726,7 @@ void QgsLayoutDesignerDialog::printAtlas()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::print( printAtlas, *p, printSettings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );

switch ( result )
{
@@ -2914,6 +2932,7 @@ void QgsLayoutDesignerDialog::exportAtlasToRaster()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToImage( printAtlas, fileName, fileExt, settings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );

cursorOverride.release();

@@ -3079,6 +3098,7 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToSvg( printAtlas, filename, svgSettings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );

cursorOverride.release();
switch ( result )
@@ -3317,6 +3337,7 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
}

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );

cursorOverride.release();
switch ( result )
@@ -3446,6 +3467,7 @@ void QgsLayoutDesignerDialog::exportReportToRaster()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToImage( static_cast< QgsReport * >( mMasterLayout ), fileName, fileNExt.second, settings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );
cursorOverride.release();

switch ( result )
@@ -3563,6 +3585,7 @@ void QgsLayoutDesignerDialog::exportReportToSvg()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToSvg( static_cast< QgsReport * >( mMasterLayout ), outFile, svgSettings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );
cursorOverride.release();
switch ( result )
{
@@ -3696,6 +3719,7 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToPdf( static_cast< QgsReport * >( mMasterLayout ), outputFileName, pdfSettings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );
cursorOverride.release();

switch ( result )
@@ -3804,6 +3828,7 @@ void QgsLayoutDesignerDialog::printReport()
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::print( static_cast< QgsReport * >( mMasterLayout ), *p, printSettings, error, feedback.get() );

proxyTask->finalize( result == QgsLayoutExporter::Success );
storeExportResults( result );

switch ( result )
{
@@ -4864,6 +4889,23 @@ void QgsLayoutDesignerDialog::backgroundTaskCountChanged( int total )
}
}

void QgsLayoutDesignerDialog::storeExportResults( QgsLayoutExporter::ExportResult result, QgsLayoutExporter *exporter )
{
mLastExportResults = std::make_unique< QgsLayoutDesignerInterface::ExportResults >();
mLastExportResults->result = result;

if ( exporter )
{
mLastExportLabelingResults = exporter->takeLabelingResults();
mLastExportResults->labelingResults = mLastExportLabelingResults;
}
else
{
qDeleteAll( mLastExportLabelingResults );
mLastExportLabelingResults.clear();
}
}

void QgsLayoutDesignerDialog::selectItems( const QList<QgsLayoutItem *> &items )
{
for ( QGraphicsItem *item : items )
@@ -81,7 +81,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) override;
void removeDockWidget( QDockWidget *dock ) override;
void activateTool( StandardTool tool ) override;

QgsLayoutDesignerInterface::ExportResults *lastExportResults() const override;
public slots:

void close() override;
@@ -203,6 +203,13 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
*/
void showGuideDock( bool show );

/**
* Returns the results of the last export operation performed in the designer.
*
* May be NULLPTR if no export has been performed in the designer.
*/
std::unique_ptr< QgsLayoutDesignerInterface::ExportResults > lastExportResults() const;

public slots:

/**
@@ -492,6 +499,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
QgsLayoutGuideWidget *mGuideWidget = nullptr;

bool mIsExportingAtlas = false;
void storeExportResults( QgsLayoutExporter::ExportResult result, QgsLayoutExporter *exporter = nullptr );
std::unique_ptr< QgsLayoutDesignerInterface::ExportResults> mLastExportResults;
QMap< QString, QgsLabelingResults *> mLastExportLabelingResults;

//! Save window state
void saveWindowState();
@@ -18,6 +18,7 @@

#include "qgis_gui.h"
#include "qgis_sip.h"
#include "qgslayoutexporter.h"
#include <QObject>

class QgsLayout;
@@ -351,6 +352,38 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject
*/
virtual void activateTool( StandardTool tool ) = 0;

/**
* \ingroup gui
* \brief Encapsulates the results of an export operation performed in the designer.
* \since QGIS 3.20
*/
class ExportResults
{
public:

/**
* Result/error code of export.
*/
QgsLayoutExporter::ExportResult result;

/**
* Returns the labeling results for all map items included in the export. Map keys are the item UUIDs (see QgsLayoutItem::uuid()).
*
* Ownership of the results remains with the layout designer.
*/
QMap< QString, QgsLabelingResults * > labelingResults;

};

/**
* Returns the results of the last export operation performed in the designer.
*
* May be NULLPTR if no export has been performed in the designer.
*
* \since QGIS 3.20
*/
virtual QgsLayoutDesignerInterface::ExportResults *lastExportResults() const = 0 SIP_FACTORY;

public slots:

/**

0 comments on commit e627144

Please sign in to comment.