Skip to content

Commit

Permalink
[api] Add signal to QgsLayoutDesignerInterface which is emitted
Browse files Browse the repository at this point in the history
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 ccb4146
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/layout/qgslayoutitemmap.sip.in
Expand Up @@ -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:
Expand Down
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 >();
Expand Down
7 changes: 7 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -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;
Expand Down Expand Up @@ -410,6 +415,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB
void updateWindowTitle();

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

private:

Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -1971,6 +1971,7 @@ void QgsLayoutItemMap::painterJobFinished()
mLastRenderedImageOffsetY = 0;
emit backgroundTaskCountChanged( 0 );
update();
emit previewRefreshed();
}

void QgsLayoutItemMap::shapeChanged()
Expand Down
7 changes: 7 additions & 0 deletions src/core/layout/qgslayoutitemmap.h
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/gui/layout/qgslayoutdesignerinterface.h
Expand Up @@ -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.