Skip to content
Permalink
Browse files
Avoid multiple map/legend renders while loading compositions
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent ce3c854 commit 77706a6447810a3e182270b857d9b88970432414
@@ -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:

@@ -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
@@ -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() );
@@ -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
@@ -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
@@ -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
@@ -348,6 +348,9 @@ void QgsComposerLegend::updateLegend()

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

updateFilterByMap( false );
QgsComposerItem::updateItem();
}
@@ -1024,7 +1024,7 @@ void QgsComposerMap::refreshMapExtents( const QgsExpressionContext *context )

void QgsComposerMap::updateItem()
{
if ( !mUpdatesEnabled )
if ( !updatesEnabled() )
{
return;
}
@@ -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" ) )
{
@@ -1489,6 +1491,8 @@ bool QgsComposerMap::readXml( const QDomElement &itemElem, const QDomDocument &d
}

updateBoundingRect();
setUpdatesEnabled( true );

emit itemChanged();
return true;
}
@@ -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
@@ -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();

0 comments on commit 77706a6

Please sign in to comment.