Skip to content

Commit

Permalink
Add synchronization between canvas layers addition / removal and atla…
Browse files Browse the repository at this point in the history
…s GUI
  • Loading branch information
Hugo Mercier committed Oct 4, 2012
1 parent ce6ae6e commit 371efa0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -965,6 +965,14 @@ void QgsComposerMapWidget::on_mIsAtlasCheckBox_stateChanged( int state )
}
}

// Connect to addition / removal of layers
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
if ( layerRegistry )
{
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( onLayerRemoved( QString ) ) );
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerAdded( QgsMapLayer* ) ) );
}

mAtlasFrame->setEnabled( true );
updateGuiElements();
}
Expand All @@ -976,10 +984,40 @@ void QgsComposerMapWidget::on_mIsAtlasCheckBox_stateChanged( int state )
if ( composition->atlasMap() == mComposerMap )
{
composition->setAtlasMap( 0 );

QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
if ( layerRegistry )
{
disconnect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( onLayerRemoved( QString ) ) );
disconnect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerAdded( QgsMapLayer* ) ) );
}
}
}
}

void QgsComposerMapWidget::onLayerRemoved( QString layerName )
{
// update the atlas coverage layer combo box
for ( int i = 0; i < mAtlasCoverageLayerComboBox->count(); ++i )
{
if ( mAtlasCoverageLayerComboBox->itemText( i ) == layerName )
{
mAtlasCoverageLayerComboBox->removeItem( i );
break;
}
}
}

void QgsComposerMapWidget::onLayerAdded( QgsMapLayer* map )
{
// update the atlas coverage layer combo box
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( map );
if ( vectorLayer )
{
mAtlasCoverageLayerComboBox->addItem( map->id(), qVariantFromValue( (void*)map ) );
}
}

void QgsComposerMapWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index )
{
if ( !mComposerMap )
Expand Down
5 changes: 5 additions & 0 deletions src/app/composer/qgscomposermapwidget.h
Expand Up @@ -20,6 +20,7 @@

#include "ui_qgscomposermapwidgetbase.h"
#include "qgscomposermap.h"
class QgsMapLayer;

/** \ingroup MapComposer
* Input widget for the configuration of QgsComposerMap
Expand Down Expand Up @@ -104,6 +105,10 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
/**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues();

/** Updates atlas' coverage layer combobox on layer addition / removal */
void onLayerRemoved( QString );
void onLayerAdded( QgsMapLayer* );

private:
QgsComposerMap* mComposerMap;

Expand Down

0 comments on commit 371efa0

Please sign in to comment.