Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add refresh action for layouts
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent c0b63a6 commit ce79ff3
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/core/layout/qgslayout.sip
Expand Up @@ -419,6 +419,16 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb

public slots:

void refresh();
%Docstring
Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw
and rebuild cached images, html items to reload their source url, and attribute tables
to refresh their contents. Calling this also triggers a recalculation of all data defined
attributes within the layout.

.. seealso:: refreshed()
%End

void updateBounds();
%Docstring
Updates the scene bounds of the layout.
Expand All @@ -437,6 +447,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
If None, no item is selected.
%End

void refreshed();
%Docstring
Is emitted when the layout has been refreshed and items should also be refreshed
and updated.
%End

};


Expand Down
24 changes: 24 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -142,6 +142,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mHorizontalRuler->setContextMenu( rulerMenu );
mVerticalRuler->setContextMenu( rulerMenu );

connect( mActionRefreshView, &QAction::triggered, this, &QgsLayoutDesignerDialog::refreshLayout );

connect( mActionShowGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGrid );
connect( mActionSnapGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGrid );

Expand Down Expand Up @@ -809,6 +811,28 @@ void QgsLayoutDesignerDialog::moveSelectedItemsToBottom()
mView->moveSelectedItemsToBottom();
}

void QgsLayoutDesignerDialog::refreshLayout()
{
if ( !currentLayout() )
{
return;
}

#if 0 //TODO
//refresh atlas feature first, to update attributes
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//block signals from atlas, since the later call to mComposition->refreshItems() will
//also trigger items to refresh atlas dependent properties
mComposition->atlasComposition().blockSignals( true );
mComposition->atlasComposition().refreshFeature();
mComposition->atlasComposition().blockSignals( false );
}
#endif

currentLayout()->refresh();
}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
{
emit aboutToClose();
Expand Down
8 changes: 8 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -205,6 +205,14 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void moveSelectedItemsToBottom();

/**
* Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw
* and rebuild cached images, html items to reload their source url, and attribute tables
* to refresh their contents. Calling this also triggers a recalculation of all data defined
* attributes within the layout.
*/
void refreshLayout();

signals:

/**
Expand Down
6 changes: 6 additions & 0 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -518,6 +518,12 @@ QList<QgsLayoutItem *> QgsLayout::ungroupItems( QgsLayoutItemGroup *group )
return ungroupedItems;
}

void QgsLayout::refresh()
{
emit refreshed();
update();
}

void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &document, const QgsReadWriteContext & ) const
{
mCustomProperties.writeXml( element, document );
Expand Down
16 changes: 16 additions & 0 deletions src/core/layout/qgslayout.h
Expand Up @@ -467,6 +467,16 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext

public slots:

/**
* Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw
* and rebuild cached images, html items to reload their source url, and attribute tables
* to refresh their contents. Calling this also triggers a recalculation of all data defined
* attributes within the layout.
*
* \see refreshed()
*/
void refresh();

/**
* Updates the scene bounds of the layout.
*/
Expand All @@ -485,6 +495,12 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*/
void selectedItemChanged( QgsLayoutItem *selected );

/**
* Is emitted when the layout has been refreshed and items should also be refreshed
* and updated.
*/
void refreshed();

private:

QgsProject *mProject = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutobject.cpp
Expand Up @@ -88,6 +88,11 @@ QgsLayoutObject::QgsLayoutObject( QgsLayout *layout )
, mLayout( layout )
{
initPropertyDefinitions();

if ( mLayout )
{
connect( mLayout, &QgsLayout::refreshed, this, &QgsLayoutObject::refresh );
}
}

const QgsLayout *QgsLayoutObject::layout() const
Expand Down
17 changes: 17 additions & 0 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -124,6 +124,7 @@
<addaction name="mActionPreviewProtanope"/>
<addaction name="mActionPreviewDeuteranope"/>
</widget>
<addaction name="mActionRefreshView"/>
<addaction name="menuPreview"/>
<addaction name="separator"/>
<addaction name="mActionZoomIn"/>
Expand Down Expand Up @@ -238,6 +239,7 @@
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActual"/>
<addaction name="mActionZoomAll"/>
<addaction name="mActionRefreshView"/>
</widget>
<widget class="QToolBar" name="mActionsToolbar">
<property name="windowTitle">
Expand Down Expand Up @@ -992,6 +994,21 @@
<string>Ctrl+Shift+G</string>
</property>
</action>
<action name="mActionRefreshView">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDraw.svg</normaloff>:/images/themes/default/mActionDraw.svg</iconset>
</property>
<property name="text">
<string>&amp;Refresh</string>
</property>
<property name="toolTip">
<string>Refresh view</string>
</property>
<property name="shortcut">
<string>F5</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down

0 comments on commit ce79ff3

Please sign in to comment.