From 5537e23f35eacb4fd0499cdb84a4824710cc1c8b Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 3 Aug 2015 16:05:29 +1000 Subject: [PATCH] [composer] Keep atlas page combo in sync when atlas feature changes --- src/app/composer/qgscomposer.cpp | 26 +++++++++++++++++++++++++- src/app/composer/qgscomposer.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app/composer/qgscomposer.cpp b/src/app/composer/qgscomposer.cpp index 2f3876b350c..cc0d1842783 100644 --- a/src/app/composer/qgscomposer.cpp +++ b/src/app/composer/qgscomposer.cpp @@ -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(); @@ -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(); @@ -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() ); @@ -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(); @@ -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(); diff --git a/src/app/composer/qgscomposer.h b/src/app/composer/qgscomposer.h index 0d12e9850c2..1e5881e28fa 100644 --- a/src/app/composer/qgscomposer.h +++ b/src/app/composer/qgscomposer.h @@ -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