Skip to content

Commit a64e7b1

Browse files
committed
More const correctness, fix crash with atlas
1 parent 14abd45 commit a64e7b1

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

python/core/composer/qgsatlascomposition.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ public:
177177
/**Prepare the atlas map for the given feature. Sets the extent and context variables
178178
* @returns true if feature was successfully prepared
179179
*/
180-
bool prepareForFeature( int i );
180+
bool prepareForFeature( const int i );
181181

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

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

src/app/composer/qgscomposer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3531,7 +3531,7 @@ void QgsComposer::writeWorldFile( QString worldFileName, double a, double b, dou
35313531
}
35323532

35333533

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

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

src/app/composer/qgscomposer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
620620

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

625625
//! Updates the "set as atlas feature" map layer action when atlas coverage layer changes
626626
void updateAtlasMapLayerAction( QgsVectorLayer* coverageLayer );

src/core/composer/qgsatlascomposition.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,19 @@ void QgsAtlasComposition::lastFeature()
333333
prepareForFeature( mFeatureIds.size() - 1 );
334334
}
335335

336-
bool QgsAtlasComposition::prepareForFeature( QgsFeature * feat )
336+
bool QgsAtlasComposition::prepareForFeature( const QgsFeature * feat )
337337
{
338338
int featureI = mFeatureIds.indexOf( feat->id() );
339+
if ( featureI < 0 )
340+
{
341+
//feature not found
342+
return false;
343+
}
344+
339345
return prepareForFeature( featureI );
340346
}
341347

342-
bool QgsAtlasComposition::prepareForFeature( int featureI )
348+
bool QgsAtlasComposition::prepareForFeature( const int featureI )
343349
{
344350
if ( !mCoverageLayer )
345351
{

src/core/composer/qgsatlascomposition.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
205205
/**Prepare the atlas map for the given feature. Sets the extent and context variables
206206
* @returns true if feature was successfully prepared
207207
*/
208-
bool prepareForFeature( int i );
208+
bool prepareForFeature( const int i );
209209

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

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

0 commit comments

Comments
 (0)