Skip to content
Permalink
Browse files
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 00b1f2c1729223dd28b964542cdafb698cb87d40
Showing with 32 additions and 15 deletions.
  1. +20 −3 src/app/composer/qgscomposer.cpp
  2. +12 −12 src/core/composer/qgsatlascomposition.cpp
@@ -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 )
@@ -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 )
@@ -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 );

0 comments on commit 00b1f2c

Please sign in to comment.