Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bring composition to front and automatically activate atlas preview w…
…hen running the "set as atlas feature" action (sponsored by SIGE)
  • Loading branch information
nyalldawson committed Apr 8, 2014
1 parent cfc8303 commit 00b1f2c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
23 changes: 20 additions & 3 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -3112,16 +3112,33 @@ void QgsComposer::setAtlasFeature( QgsMapLayer* layer, QgsFeature * feat )

emit atlasPreviewFeatureChanged();

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

if ( mComposition->atlasMode() != QgsComposition::PreviewAtlas )
{
mComposition->setAtlasMode( QgsComposition::PreviewAtlas );
//update gui controls
mActionAtlasPreview->blockSignals( true );
mActionAtlasPreview->setChecked( true );
mActionAtlasPreview->blockSignals( false );
mActionAtlasFirst->setEnabled( true );
mActionAtlasLast->setEnabled( true );
mActionAtlasNext->setEnabled( true );
mActionAtlasPrev->setEnabled( true );
}

//bring composer window to foreground
activate();

//set current preview feature id
atlas.prepareForFeature( feat );
emit( atlasPreviewFeatureChanged() );
}

void QgsComposer::updateAtlasMapLayerAction( QgsVectorLayer *coverageLayer )
Expand Down
24 changes: 12 additions & 12 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -350,36 +350,34 @@ int QgsAtlasComposition::numFeatures() const

void QgsAtlasComposition::nextFeature()
{
mCurrentFeatureNo++;
if ( mCurrentFeatureNo >= mFeatureIds.size() )
int newFeatureNo = mCurrentFeatureNo + 1;
if ( newFeatureNo >= mFeatureIds.size() )
{
mCurrentFeatureNo = mFeatureIds.size() - 1;
newFeatureNo = mFeatureIds.size() - 1;
}

prepareForFeature( mCurrentFeatureNo );
prepareForFeature( newFeatureNo );
}

void QgsAtlasComposition::prevFeature()
{
mCurrentFeatureNo--;
if ( mCurrentFeatureNo < 0 )
int newFeatureNo = mCurrentFeatureNo - 1;
if ( newFeatureNo < 0 )
{
mCurrentFeatureNo = 0;
newFeatureNo = 0;
}

prepareForFeature( mCurrentFeatureNo );
prepareForFeature( newFeatureNo );
}

void QgsAtlasComposition::firstFeature()
{
mCurrentFeatureNo = 0;
prepareForFeature( mCurrentFeatureNo );
prepareForFeature( 0 );
}

void QgsAtlasComposition::lastFeature()
{
mCurrentFeatureNo = mFeatureIds.size() - 1;
prepareForFeature( mCurrentFeatureNo );
prepareForFeature( mFeatureIds.size() - 1 );
}

void QgsAtlasComposition::prepareForFeature( QgsFeature * feat )
Expand All @@ -401,6 +399,8 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
return;
}

mCurrentFeatureNo = featureI;

// retrieve the next feature, based on its id
mCoverageLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureIds[ featureI ] ) ).nextFeature( mCurrentFeature );

Expand Down

0 comments on commit 00b1f2c

Please sign in to comment.