Skip to content

Commit ce79ff3

Browse files
committedNov 7, 2017
Add refresh action for layouts
1 parent c0b63a6 commit ce79ff3

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed
 

‎python/core/layout/qgslayout.sip

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
419419

420420
public slots:
421421

422+
void refresh();
423+
%Docstring
424+
Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw
425+
and rebuild cached images, html items to reload their source url, and attribute tables
426+
to refresh their contents. Calling this also triggers a recalculation of all data defined
427+
attributes within the layout.
428+
429+
.. seealso:: refreshed()
430+
%End
431+
422432
void updateBounds();
423433
%Docstring
424434
Updates the scene bounds of the layout.
@@ -437,6 +447,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
437447
If None, no item is selected.
438448
%End
439449

450+
void refreshed();
451+
%Docstring
452+
Is emitted when the layout has been refreshed and items should also be refreshed
453+
and updated.
454+
%End
455+
440456
};
441457

442458

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
142142
mHorizontalRuler->setContextMenu( rulerMenu );
143143
mVerticalRuler->setContextMenu( rulerMenu );
144144

145+
connect( mActionRefreshView, &QAction::triggered, this, &QgsLayoutDesignerDialog::refreshLayout );
146+
145147
connect( mActionShowGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGrid );
146148
connect( mActionSnapGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGrid );
147149

@@ -809,6 +811,28 @@ void QgsLayoutDesignerDialog::moveSelectedItemsToBottom()
809811
mView->moveSelectedItemsToBottom();
810812
}
811813

814+
void QgsLayoutDesignerDialog::refreshLayout()
815+
{
816+
if ( !currentLayout() )
817+
{
818+
return;
819+
}
820+
821+
#if 0 //TODO
822+
//refresh atlas feature first, to update attributes
823+
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
824+
{
825+
//block signals from atlas, since the later call to mComposition->refreshItems() will
826+
//also trigger items to refresh atlas dependent properties
827+
mComposition->atlasComposition().blockSignals( true );
828+
mComposition->atlasComposition().refreshFeature();
829+
mComposition->atlasComposition().blockSignals( false );
830+
}
831+
#endif
832+
833+
currentLayout()->refresh();
834+
}
835+
812836
void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
813837
{
814838
emit aboutToClose();

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
205205
*/
206206
void moveSelectedItemsToBottom();
207207

208+
/**
209+
* Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw
210+
* and rebuild cached images, html items to reload their source url, and attribute tables
211+
* to refresh their contents. Calling this also triggers a recalculation of all data defined
212+
* attributes within the layout.
213+
*/
214+
void refreshLayout();
215+
208216
signals:
209217

210218
/**

‎src/core/layout/qgslayout.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,12 @@ QList<QgsLayoutItem *> QgsLayout::ungroupItems( QgsLayoutItemGroup *group )
518518
return ungroupedItems;
519519
}
520520

521+
void QgsLayout::refresh()
522+
{
523+
emit refreshed();
524+
update();
525+
}
526+
521527
void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &document, const QgsReadWriteContext & ) const
522528
{
523529
mCustomProperties.writeXml( element, document );

‎src/core/layout/qgslayout.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,16 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
467467

468468
public slots:
469469

470+
/**
471+
* Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw
472+
* and rebuild cached images, html items to reload their source url, and attribute tables
473+
* to refresh their contents. Calling this also triggers a recalculation of all data defined
474+
* attributes within the layout.
475+
*
476+
* \see refreshed()
477+
*/
478+
void refresh();
479+
470480
/**
471481
* Updates the scene bounds of the layout.
472482
*/
@@ -485,6 +495,12 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
485495
*/
486496
void selectedItemChanged( QgsLayoutItem *selected );
487497

498+
/**
499+
* Is emitted when the layout has been refreshed and items should also be refreshed
500+
* and updated.
501+
*/
502+
void refreshed();
503+
488504
private:
489505

490506
QgsProject *mProject = nullptr;

‎src/core/layout/qgslayoutobject.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ QgsLayoutObject::QgsLayoutObject( QgsLayout *layout )
8888
, mLayout( layout )
8989
{
9090
initPropertyDefinitions();
91+
92+
if ( mLayout )
93+
{
94+
connect( mLayout, &QgsLayout::refreshed, this, &QgsLayoutObject::refresh );
95+
}
9196
}
9297

9398
const QgsLayout *QgsLayoutObject::layout() const

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<addaction name="mActionPreviewProtanope"/>
125125
<addaction name="mActionPreviewDeuteranope"/>
126126
</widget>
127+
<addaction name="mActionRefreshView"/>
127128
<addaction name="menuPreview"/>
128129
<addaction name="separator"/>
129130
<addaction name="mActionZoomIn"/>
@@ -238,6 +239,7 @@
238239
<addaction name="mActionZoomOut"/>
239240
<addaction name="mActionZoomActual"/>
240241
<addaction name="mActionZoomAll"/>
242+
<addaction name="mActionRefreshView"/>
241243
</widget>
242244
<widget class="QToolBar" name="mActionsToolbar">
243245
<property name="windowTitle">
@@ -992,6 +994,21 @@
992994
<string>Ctrl+Shift+G</string>
993995
</property>
994996
</action>
997+
<action name="mActionRefreshView">
998+
<property name="icon">
999+
<iconset resource="../../../images/images.qrc">
1000+
<normaloff>:/images/themes/default/mActionDraw.svg</normaloff>:/images/themes/default/mActionDraw.svg</iconset>
1001+
</property>
1002+
<property name="text">
1003+
<string>&amp;Refresh</string>
1004+
</property>
1005+
<property name="toolTip">
1006+
<string>Refresh view</string>
1007+
</property>
1008+
<property name="shortcut">
1009+
<string>F5</string>
1010+
</property>
1011+
</action>
9951012
</widget>
9961013
<resources>
9971014
<include location="../../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.