Skip to content

Commit 5537e23

Browse files
committed
[composer] Keep atlas page combo in sync when atlas feature changes
1 parent dfff125 commit 5537e23

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
633633
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
634634
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
635635
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );
636+
connect( atlasMap, SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( atlasFeatureChanged( QgsFeature* ) ) );
636637

637638
//default printer page setup
638639
setPrinterPageDefaults();
@@ -1007,6 +1008,27 @@ void QgsComposer::updateAtlasPageComboBox( int pageCount )
10071008
mAtlasPageComboBox->blockSignals( false );
10081009
}
10091010

1011+
void QgsComposer::atlasFeatureChanged( QgsFeature *feature )
1012+
{
1013+
Q_UNUSED( feature );
1014+
1015+
if ( !mComposition )
1016+
return;
1017+
1018+
mAtlasPageComboBox->blockSignals( true );
1019+
//prefer to set index of current atlas page, if combo box is showing enough page items
1020+
if ( mComposition->atlasComposition().currentFeatureNumber() < mAtlasPageComboBox->count() )
1021+
{
1022+
mAtlasPageComboBox->setCurrentIndex( mComposition->atlasComposition().currentFeatureNumber() );
1023+
}
1024+
else
1025+
{
1026+
//fallback to setting the combo text to the page number
1027+
mAtlasPageComboBox->setEditText( QString::number( mComposition->atlasComposition().currentFeatureNumber() + 1 ) );
1028+
}
1029+
mAtlasPageComboBox->blockSignals( false );
1030+
}
1031+
10101032
void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
10111033
{
10121034
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -1134,7 +1156,7 @@ void QgsComposer::atlasPageComboEditingFinished()
11341156
QString text = mAtlasPageComboBox->lineEdit()->text();
11351157
bool ok = false;
11361158
int page = text.toInt( &ok );
1137-
if ( !ok || page >= mComposition->atlasComposition().numFeatures() )
1159+
if ( !ok || page >= mComposition->atlasComposition().numFeatures() || page < 1 )
11381160
{
11391161
mAtlasPageComboBox->blockSignals( true );
11401162
mAtlasPageComboBox->setCurrentIndex( mComposition->atlasComposition().currentFeatureNumber() );
@@ -1462,6 +1484,7 @@ void QgsComposer::setComposition( QgsComposition* composition )
14621484
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
14631485
connect( atlasMap, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateAtlasMapLayerAction( QgsVectorLayer * ) ) );
14641486
connect( atlasMap, SIGNAL( numberFeaturesChanged( int ) ), this, SLOT( updateAtlasPageComboBox( int ) ) );
1487+
connect( atlasMap, SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( atlasFeatureChanged( QgsFeature* ) ) );
14651488

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

32853309
//default printer page setup
32863310
setPrinterPageDefaults();

src/app/composer/qgscomposer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
657657
/** Repopulates the atlas page combo box with valid items.
658658
*/
659659
void updateAtlasPageComboBox( int pageCount );
660+
661+
void atlasFeatureChanged( QgsFeature* feature );
660662
};
661663

662664
#endif

0 commit comments

Comments
 (0)