Skip to content
Permalink
Browse files

Add refresh action for layouts

  • Loading branch information
nyalldawson committed Oct 13, 2017
1 parent c0b63a6 commit ce79ff30c83b2d34b58b2b9b3dd612f733ea1269
@@ -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.
@@ -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

};


@@ -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 );

@@ -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();
@@ -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:

/**
@@ -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 );
@@ -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.
*/
@@ -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;
@@ -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
@@ -124,6 +124,7 @@
<addaction name="mActionPreviewProtanope"/>
<addaction name="mActionPreviewDeuteranope"/>
</widget>
<addaction name="mActionRefreshView"/>
<addaction name="menuPreview"/>
<addaction name="separator"/>
<addaction name="mActionZoomIn"/>
@@ -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">
@@ -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"/>

0 comments on commit ce79ff3

Please sign in to comment.
You can’t perform that action at this time.