Skip to content
Permalink
Browse files
[api] Add signal to QgsLayoutDesignerInterface which is emitted
whenever a map item's preview image has been refreshed inside
the designer
  • Loading branch information
nyalldawson committed Jun 9, 2021
1 parent 309a2a6 commit ccb414620617f7034989ed445ab02d2e51105ed6
@@ -1009,6 +1009,13 @@ Emitted when the map's associated ``theme`` is changed.
Emitted when the map's coordinate reference system is changed.

.. versionadded:: 3.18
%End

void previewRefreshed();
%Docstring
Emitted whenever the item's map preview has been refreshed.

.. versionadded:: 3.20
%End

public slots:
@@ -465,6 +465,14 @@ Emitted whenever a layout is exported from the layout designer.

The results of the export can be retrieved by calling :py:func:`~QgsLayoutDesignerInterface.lastExportResults`.

.. versionadded:: 3.20
%End


void mapPreviewRefreshed( QgsLayoutItemMap *map );
%Docstring
Emitted when a ``map`` item's preview has been refreshed.

.. versionadded:: 3.20
%End

@@ -115,6 +115,7 @@ QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerD
, mDesigner( dialog )
{
connect( mDesigner, &QgsLayoutDesignerDialog::layoutExported, this, &QgsLayoutDesignerInterface::layoutExported );
connect( mDesigner, &QgsLayoutDesignerDialog::mapPreviewRefreshed, this, &QgsLayoutDesignerInterface::mapPreviewRefreshed );
}

QWidget *QgsAppLayoutDesignerInterface::window()
@@ -1210,6 +1211,13 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
if ( mLayout )
{
disconnect( mLayout, &QgsLayout::backgroundTaskCountChanged, this, &QgsLayoutDesignerDialog::backgroundTaskCountChanged );
QList< QgsLayoutItemMap * > maps;
mLayout->layoutItems( maps );
for ( QgsLayoutItemMap *map : std::as_const( maps ) )
{
disconnect( map, &QgsLayoutItemMap::previewRefreshed, this, &QgsLayoutDesignerDialog::onMapPreviewRefreshed );
}
disconnect( mLayout, &QgsLayout::itemAdded, this, &QgsLayoutDesignerDialog::onItemAdded );
}

layout->deselectAll();
@@ -1255,6 +1263,14 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )

connect( mLayout, &QgsLayout::backgroundTaskCountChanged, this, &QgsLayoutDesignerDialog::backgroundTaskCountChanged );

QList< QgsLayoutItemMap * > maps;
mLayout->layoutItems( maps );
for ( QgsLayoutItemMap *map : std::as_const( maps ) )
{
connect( map, &QgsLayoutItemMap::previewRefreshed, this, &QgsLayoutDesignerDialog::onMapPreviewRefreshed );
}
connect( mLayout, &QgsLayout::itemAdded, this, &QgsLayoutDesignerDialog::onItemAdded );

createLayoutPropertiesWidget();
toggleActions( true );
}
@@ -4891,6 +4907,23 @@ void QgsLayoutDesignerDialog::backgroundTaskCountChanged( int total )
}
}

void QgsLayoutDesignerDialog::onMapPreviewRefreshed()
{
QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( sender() );
if ( !map )
return;

emit mapPreviewRefreshed( map );
}

void QgsLayoutDesignerDialog::onItemAdded( QgsLayoutItem *item )
{
if ( QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item ) )
{
connect( map, &QgsLayoutItemMap::previewRefreshed, this, &QgsLayoutDesignerDialog::onMapPreviewRefreshed );
}
}

void QgsLayoutDesignerDialog::storeExportResults( QgsLayoutExporter::ExportResult result, QgsLayoutExporter *exporter )
{
mLastExportResults = std::make_unique< QgsLayoutDesignerInterface::ExportResults >();
@@ -344,6 +344,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
*/
void layoutExported();

/**
* Emitted when a \a map preview has been refreshed.
*/
void mapPreviewRefreshed( QgsLayoutItemMap *map );

protected:

void closeEvent( QCloseEvent * ) override;
@@ -410,6 +415,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
void updateWindowTitle();

void backgroundTaskCountChanged( int total );
void onMapPreviewRefreshed();
void onItemAdded( QgsLayoutItem *item );

private:

@@ -1971,6 +1971,7 @@ void QgsLayoutItemMap::painterJobFinished()
mLastRenderedImageOffsetY = 0;
emit backgroundTaskCountChanged( 0 );
update();
emit previewRefreshed();
}

void QgsLayoutItemMap::shapeChanged()
@@ -929,6 +929,13 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem, public QgsTemporalRan
*/
void crsChanged();

/**
* Emitted whenever the item's map preview has been refreshed.
*
* \since QGIS 3.20
*/
void previewRefreshed();

public slots:

void refresh() override;
@@ -409,6 +409,14 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject
*/
void layoutExported();


/**
* Emitted when a \a map item's preview has been refreshed.
*
* \since QGIS 3.20
*/
void mapPreviewRefreshed( QgsLayoutItemMap *map );

};

#endif // QGSLAYOUTDESIGNERINTERFACE_H

0 comments on commit ccb4146

Please sign in to comment.