Skip to content

Commit

Permalink
More const correctness, fix crash with atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 2, 2014
1 parent 14abd45 commit a64e7b1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions python/core/composer/qgsatlascomposition.sip
Expand Up @@ -177,12 +177,12 @@ public:
/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( int i );
bool prepareForFeature( const int i );

/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( QgsFeature * feat );
bool prepareForFeature( const QgsFeature * feat );

/** Returns the current filename. Must be called after prepareForFeature( i ) */
const QString& currentFilename() const;
Expand Down
6 changes: 3 additions & 3 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -3531,7 +3531,7 @@ void QgsComposer::writeWorldFile( QString worldFileName, double a, double b, dou
}


void QgsComposer::setAtlasFeature( QgsMapLayer* layer, QgsFeature * feat )
void QgsComposer::setAtlasFeature( QgsMapLayer* layer, const QgsFeature * feat )
{
//update expression variables
QgsExpression::setSpecialColumn( "$atlasfeatureid", feat->id() );
Expand Down Expand Up @@ -3581,7 +3581,7 @@ void QgsComposer::updateAtlasMapLayerAction( QgsVectorLayer *coverageLayer )
{
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, coverageLayer, QgsMapLayerAction::SingleFeature );
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, const QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, const QgsFeature* ) ) );
}
}

Expand Down Expand Up @@ -3626,7 +3626,7 @@ void QgsComposer::updateAtlasMapLayerAction( bool atlasEnabled )
QgsAtlasComposition& atlas = mComposition->atlasComposition();
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, atlas.coverageLayer(), QgsMapLayerAction::SingleFeature );
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, const QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, const QgsFeature* ) ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.h
Expand Up @@ -620,7 +620,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

//! Sets the specified feature as the current atlas feature
//! @note added in 2.1
void setAtlasFeature( QgsMapLayer* layer, QgsFeature * feat );
void setAtlasFeature( QgsMapLayer* layer, const QgsFeature *feat );

//! Updates the "set as atlas feature" map layer action when atlas coverage layer changes
void updateAtlasMapLayerAction( QgsVectorLayer* coverageLayer );
Expand Down
10 changes: 8 additions & 2 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -333,13 +333,19 @@ void QgsAtlasComposition::lastFeature()
prepareForFeature( mFeatureIds.size() - 1 );
}

bool QgsAtlasComposition::prepareForFeature( QgsFeature * feat )
bool QgsAtlasComposition::prepareForFeature( const QgsFeature * feat )
{
int featureI = mFeatureIds.indexOf( feat->id() );
if ( featureI < 0 )
{
//feature not found
return false;
}

return prepareForFeature( featureI );
}

bool QgsAtlasComposition::prepareForFeature( int featureI )
bool QgsAtlasComposition::prepareForFeature( const int featureI )
{
if ( !mCoverageLayer )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgsatlascomposition.h
Expand Up @@ -205,12 +205,12 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( int i );
bool prepareForFeature( const int i );

/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( QgsFeature * feat );
bool prepareForFeature( const QgsFeature *feat );

/** Returns the current filename. Must be called after prepareForFeature( i ) */
const QString& currentFilename() const;
Expand Down

0 comments on commit a64e7b1

Please sign in to comment.