Skip to content
Permalink
Browse files

[composer] Keep atlas page combo in sync when atlas feature changes

  • Loading branch information
nyalldawson committed Aug 3, 2015
1 parent dfff125 commit 5537e23f35eacb4fd0499cdb84a4824710cc1c8b
Showing with 27 additions and 1 deletion.
  1. +25 −1 src/app/composer/qgscomposer.cpp
  2. +2 −0 src/app/composer/qgscomposer.h
@@ -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();
@@ -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

0 comments on commit 5537e23

Please sign in to comment.
You can’t perform that action at this time.