Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Keep atlas page combo in sync when atlas feature changes
  • Loading branch information
nyalldawson committed Aug 3, 2015
1 parent dfff125 commit 5537e23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -633,6 +633,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );
connect( atlasMap, SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( atlasFeatureChanged( QgsFeature* ) ) );

//default printer page setup
setPrinterPageDefaults();
Expand Down Expand Up @@ -1007,6 +1008,27 @@ void QgsComposer::updateAtlasPageComboBox( int pageCount )
mAtlasPageComboBox->blockSignals( false );
}

void QgsComposer::atlasFeatureChanged( QgsFeature *feature )
{
Q_UNUSED( feature );

if ( !mComposition )
return;

mAtlasPageComboBox->blockSignals( true );
//prefer to set index of current atlas page, if combo box is showing enough page items
if ( mComposition->atlasComposition().currentFeatureNumber() < mAtlasPageComboBox->count() )
{
mAtlasPageComboBox->setCurrentIndex( mComposition->atlasComposition().currentFeatureNumber() );
}
else
{
//fallback to setting the combo text to the page number
mAtlasPageComboBox->setEditText( QString::number( mComposition->atlasComposition().currentFeatureNumber() + 1 ) );
}
mAtlasPageComboBox->blockSignals( false );
}

void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
Expand Down Expand Up @@ -1134,7 +1156,7 @@ void QgsComposer::atlasPageComboEditingFinished()
QString text = mAtlasPageComboBox->lineEdit()->text();
bool ok = false;
int page = text.toInt( &ok );
if ( !ok || page >= mComposition->atlasComposition().numFeatures() )
if ( !ok || page >= mComposition->atlasComposition().numFeatures() || page < 1 )
{
mAtlasPageComboBox->blockSignals( true );
mAtlasPageComboBox->setCurrentIndex( mComposition->atlasComposition().currentFeatureNumber() );
Expand Down Expand Up @@ -1462,6 +1484,7 @@ void QgsComposer::setComposition( QgsComposition* composition )
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );
connect( atlasMap, SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( atlasFeatureChanged( QgsFeature* ) ) );

//default printer page setup
setPrinterPageDefaults();
Expand Down Expand Up @@ -3281,6 +3304,7 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );
connect( atlasMap, SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( atlasFeatureChanged( QgsFeature* ) ) );

//default printer page setup
setPrinterPageDefaults();
Expand Down
2 changes: 2 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -657,6 +657,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
/** Repopulates the atlas page combo box with valid items.
*/
void updateAtlasPageComboBox( int pageCount );

void atlasFeatureChanged( QgsFeature* feature );
};

#endif
Expand Down

0 comments on commit 5537e23

Please sign in to comment.