Skip to content

Commit 00b1f2c

Browse files
committed
Bring composition to front and automatically activate atlas preview when running the "set as atlas feature" action (sponsored by SIGE)
1 parent cfc8303 commit 00b1f2c

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/app/composer/qgscomposer.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -3112,16 +3112,33 @@ void QgsComposer::setAtlasFeature( QgsMapLayer* layer, QgsFeature * feat )
31123112

31133113
emit atlasPreviewFeatureChanged();
31143114

3115-
//check if composition has atlas preview
3115+
//check if composition atlas settings match
31163116
QgsAtlasComposition& atlas = mComposition->atlasComposition();
3117-
if ( ! atlas.enabled() || !( mComposition->atlasMode() == QgsComposition::PreviewAtlas ) || atlas.coverageLayer() != layer )
3117+
if ( ! atlas.enabled() || atlas.coverageLayer() != layer )
31183118
{
3119-
//either atlas preview isn't enabled, or layer doesn't match
3119+
//either atlas isn't enabled, or layer doesn't match
31203120
return;
31213121
}
31223122

3123+
if ( mComposition->atlasMode() != QgsComposition::PreviewAtlas )
3124+
{
3125+
mComposition->setAtlasMode( QgsComposition::PreviewAtlas );
3126+
//update gui controls
3127+
mActionAtlasPreview->blockSignals( true );
3128+
mActionAtlasPreview->setChecked( true );
3129+
mActionAtlasPreview->blockSignals( false );
3130+
mActionAtlasFirst->setEnabled( true );
3131+
mActionAtlasLast->setEnabled( true );
3132+
mActionAtlasNext->setEnabled( true );
3133+
mActionAtlasPrev->setEnabled( true );
3134+
}
3135+
3136+
//bring composer window to foreground
3137+
activate();
3138+
31233139
//set current preview feature id
31243140
atlas.prepareForFeature( feat );
3141+
emit( atlasPreviewFeatureChanged() );
31253142
}
31263143

31273144
void QgsComposer::updateAtlasMapLayerAction( QgsVectorLayer *coverageLayer )

src/core/composer/qgsatlascomposition.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -350,36 +350,34 @@ int QgsAtlasComposition::numFeatures() const
350350

351351
void QgsAtlasComposition::nextFeature()
352352
{
353-
mCurrentFeatureNo++;
354-
if ( mCurrentFeatureNo >= mFeatureIds.size() )
353+
int newFeatureNo = mCurrentFeatureNo + 1;
354+
if ( newFeatureNo >= mFeatureIds.size() )
355355
{
356-
mCurrentFeatureNo = mFeatureIds.size() - 1;
356+
newFeatureNo = mFeatureIds.size() - 1;
357357
}
358358

359-
prepareForFeature( mCurrentFeatureNo );
359+
prepareForFeature( newFeatureNo );
360360
}
361361

362362
void QgsAtlasComposition::prevFeature()
363363
{
364-
mCurrentFeatureNo--;
365-
if ( mCurrentFeatureNo < 0 )
364+
int newFeatureNo = mCurrentFeatureNo - 1;
365+
if ( newFeatureNo < 0 )
366366
{
367-
mCurrentFeatureNo = 0;
367+
newFeatureNo = 0;
368368
}
369369

370-
prepareForFeature( mCurrentFeatureNo );
370+
prepareForFeature( newFeatureNo );
371371
}
372372

373373
void QgsAtlasComposition::firstFeature()
374374
{
375-
mCurrentFeatureNo = 0;
376-
prepareForFeature( mCurrentFeatureNo );
375+
prepareForFeature( 0 );
377376
}
378377

379378
void QgsAtlasComposition::lastFeature()
380379
{
381-
mCurrentFeatureNo = mFeatureIds.size() - 1;
382-
prepareForFeature( mCurrentFeatureNo );
380+
prepareForFeature( mFeatureIds.size() - 1 );
383381
}
384382

385383
void QgsAtlasComposition::prepareForFeature( QgsFeature * feat )
@@ -401,6 +399,8 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
401399
return;
402400
}
403401

402+
mCurrentFeatureNo = featureI;
403+
404404
// retrieve the next feature, based on its id
405405
mCoverageLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureIds[ featureI ] ) ).nextFeature( mCurrentFeature );
406406

0 commit comments

Comments
 (0)