Skip to content

Commit

Permalink
Avoid multiple map/legend renders while loading compositions
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent ce3c854 commit 77706a6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 36 deletions.
38 changes: 20 additions & 18 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -544,26 +544,28 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
*/
void setIsGroupMember( const bool isGroupMember );

/** Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
* @note this method was added in version 2.4
* @see setCurrentExportLayer
*/
int numberExportLayers() const;

/** Sets the current layer to draw for exporting
* @param layerIdx can be set to -1 to draw all item layers, and must be less than numberExportLayers()
* @note this method was added in version 2.4
* @see numberExportLayers
*/
void setCurrentExportLayer( const int layerIdx = -1 );

/** Creates an expression context relating to the item's current state. The context includes
* scopes for global, project, composition, atlas and item properties.
* @note added in QGIS 2.12
*/
QgsExpressionContext createExpressionContext() const;




virtual int numberExportLayers() const;






virtual void setCurrentExportLayer( const int layerIdx = -1 );





virtual QgsExpressionContext createExpressionContext() const;
void setUpdatesEnabled( bool enabled );
bool updatesEnabled() const;

public slots:

Expand Down
6 changes: 0 additions & 6 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -318,12 +318,6 @@ class QgsComposerMap : QgsComposerItem
*/
void setAtlasMargin( double margin );

/** Sets whether updates to the composer map are enabled. */
void setUpdatesEnabled( bool enabled );

/** Returns whether updates to the composer map are enabled. */
bool updatesEnabled() const;

/** Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
Expand Down
8 changes: 8 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -571,6 +571,14 @@ double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const
return valueType == QgsComposerObject::EvaluatedValue ? mEvaluatedItemRotation : mItemRotation;
}

void QgsComposerItem::updateItem()
{
if ( !mUpdatesEnabled )
return;

QGraphicsRectItem::update();
}

void QgsComposerItem::move( double dx, double dy )
{
QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
Expand Down
34 changes: 32 additions & 2 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -432,8 +432,12 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/
double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;

//! Updates item, with the possibility to do custom update for subclasses
virtual void updateItem() { QGraphicsRectItem::update(); }
/**
* Updates (redraws) the item, with the possibility to do custom update for subclasses.
* Subclasses should check updatesEnabled() to determine whether updates are
* currently permitted for the item.
*/
virtual void updateItem();

/** Get item's id (which is not necessarly unique)
* @returns item id
Expand Down Expand Up @@ -524,6 +528,26 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/
virtual QgsExpressionContext createExpressionContext() const override;

/**
* Sets whether updates to the item are enabled. If false,
* the item will not be redrawn. This can be used to prevent
* multiple item updates when many settings for an item are
* changed sequentially.
* @note added in QGIS 3.0
* @see updatesEnabled()
*/
void setUpdatesEnabled( bool enabled ) { mUpdatesEnabled = enabled; }

/**
* Returns whether updates to the item are enabled. If false,
* the item will not be redrawn. This can be used to prevent
* multiple item updates when many settings for an item are
* changed sequentially.
* @note added in QGIS 3.0
* @see setUpdatesEnabled()
*/
bool updatesEnabled() const { return mUpdatesEnabled; }

public slots:

/** Sets the item rotation
Expand Down Expand Up @@ -694,6 +718,12 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
// true if composition manages the z value for this item
bool mCompositionManagesZValue;

/**
* Whether updates to the item are enabled. If false,
* the item should not be redrawn.
*/
bool mUpdatesEnabled = true;

/** Refresh item's rotation, considering data defined rotation setting
*@param updateItem set to false to prevent the item being automatically updated
*@param rotateAroundCenter set to true to rotate the item around its center rather
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -348,6 +348,9 @@ void QgsComposerLegend::updateLegend()

void QgsComposerLegend::updateItem()
{
if ( !updatesEnabled() )
return;

updateFilterByMap( false );
QgsComposerItem::updateItem();
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -1024,7 +1024,7 @@ void QgsComposerMap::refreshMapExtents( const QgsExpressionContext *context )

void QgsComposerMap::updateItem()
{
if ( !mUpdatesEnabled )
if ( !updatesEnabled() )
{
return;
}
Expand Down Expand Up @@ -1247,6 +1247,8 @@ bool QgsComposerMap::readXml( const QDomElement &itemElem, const QDomDocument &d
return false;
}

setUpdatesEnabled( false );

QString idRead = itemElem.attribute( QStringLiteral( "id" ), QStringLiteral( "not found" ) );
if ( idRead != QLatin1String( "not found" ) )
{
Expand Down Expand Up @@ -1489,6 +1491,8 @@ bool QgsComposerMap::readXml( const QDomElement &itemElem, const QDomDocument &d
}

updateBoundingRect();
setUpdatesEnabled( true );

emit itemChanged();
return true;
}
Expand Down
9 changes: 0 additions & 9 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -425,12 +425,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
*/
void setAtlasMargin( double margin ) { mAtlasMargin = margin; }

//! Sets whether updates to the composer map are enabled.
void setUpdatesEnabled( bool enabled ) { mUpdatesEnabled = enabled; }

//! Returns whether updates to the composer map are enabled.
bool updatesEnabled() const { return mUpdatesEnabled; }

/** Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
Expand Down Expand Up @@ -562,9 +556,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
* is true. May be overridden by data-defined expression. */
QString mFollowVisibilityPresetName;

//! Whether updates to the map are enabled
bool mUpdatesEnabled = true;

//! Establishes signal/slot connection for update in case of layer change
void connectUpdateSlot();

Expand Down

0 comments on commit 77706a6

Please sign in to comment.