Skip to content

Commit

Permalink
[composer] Refresh refetches atlas feature from provider, more remova…
Browse files Browse the repository at this point in the history
…l of duplicate map redraws
  • Loading branch information
nyalldawson committed Sep 30, 2014
1 parent f23e38d commit fb7415c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
21 changes: 15 additions & 6 deletions python/core/composer/qgsatlascomposition.sip
Expand Up @@ -175,9 +175,11 @@ public:
int numFeatures() const;

/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @param i feature number
* @param updateMaps set to true to redraw maps and recalculate their extent
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( const int i );
bool prepareForFeature( const int i, const bool updateMaps = true );

/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
Expand Down Expand Up @@ -212,17 +214,24 @@ public:
number of matching features. Must be called after prepareForFeature( i ) */
int updateFeatures();

void nextFeature();
void prevFeature();
void lastFeature();
void firstFeature();

/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
QgsFeature* currentFeature();

/** Recalculates the bounds of an atlas driven map */
void prepareMap( QgsComposerMap* map );

public slots:

/**Refreshes the current atlas feature, by refetching its attributes from the vector layer provider
* @note added in QGIS 2.5
*/
void refreshFeature();

void nextFeature();
void prevFeature();
void lastFeature();
void firstFeature();

signals:
/** emitted when one of the parameters changes */
void parameterChanged();
Expand Down
16 changes: 7 additions & 9 deletions src/app/composer/qgscomposer.cpp 100644 → 100755
Expand Up @@ -1119,16 +1119,14 @@ void QgsComposer::on_mActionRefreshView_triggered()
return;
}

//refresh preview of all composer maps
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
for ( ; it != mItemWidgetMap.end(); ++it )
//refresh atlas feature first, to update attributes
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( it.key() );
if ( map && !map->isDrawing() )
{
map->cache();
map->update();
}
//block signals from atlas, since the later call to mComposition->refreshItems() will
//also trigger items to refresh atlas dependant properties
mComposition->atlasComposition().blockSignals( true );
mComposition->atlasComposition().refreshFeature();
mComposition->atlasComposition().blockSignals( false );
}

mComposition->refreshItems();
Expand Down
13 changes: 12 additions & 1 deletion src/core/composer/qgsatlascomposition.cpp 100644 → 100755
Expand Up @@ -378,7 +378,12 @@ bool QgsAtlasComposition::prepareForFeature( const QgsFeature * feat )
return prepareForFeature( featureI );
}

bool QgsAtlasComposition::prepareForFeature( const int featureI )
void QgsAtlasComposition::refreshFeature()
{
prepareForFeature( mCurrentFeatureNo, false );
}

bool QgsAtlasComposition::prepareForFeature( const int featureI, const bool updateMaps )
{
if ( !mCoverageLayer )
{
Expand Down Expand Up @@ -417,6 +422,12 @@ bool QgsAtlasComposition::prepareForFeature( const int featureI )
return true;
}

if ( !updateMaps )
{
//nothing more to do
return true;
}

//update composer maps

//build a list of atlas-enabled composer maps
Expand Down
21 changes: 15 additions & 6 deletions src/core/composer/qgsatlascomposition.h
Expand Up @@ -204,9 +204,11 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
int numFeatures() const;

/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @param i feature number
* @param updateMaps set to true to redraw maps and recalculate their extent
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( const int i );
bool prepareForFeature( const int i, const bool updateMaps = true );

/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
Expand Down Expand Up @@ -241,17 +243,24 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
number of matching features. Must be called after prepareForFeature( i ) */
int updateFeatures();

void nextFeature();
void prevFeature();
void lastFeature();
void firstFeature();

/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
QgsFeature* currentFeature() { return &mCurrentFeature; }

/** Recalculates the bounds of an atlas driven map */
void prepareMap( QgsComposerMap* map );

public slots:

/**Refreshes the current atlas feature, by refetching its attributes from the vector layer provider
* @note added in QGIS 2.5
*/
void refreshFeature();

void nextFeature();
void prevFeature();
void lastFeature();
void firstFeature();

signals:
/** emitted when one of the parameters changes */
void parameterChanged();
Expand Down

0 comments on commit fb7415c

Please sign in to comment.