Skip to content
Permalink
Browse files

Add synchronization between canvas layers addition / removal and atla…

…s GUI
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Oct 4, 2012
1 parent ce6ae6e commit 371efa07bb8921d0feb7abdf0e180a06867afe1b
Showing with 43 additions and 0 deletions.
  1. +38 −0 src/app/composer/qgscomposermapwidget.cpp
  2. +5 −0 src/app/composer/qgscomposermapwidget.h
@@ -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();
}
@@ -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 )
@@ -20,6 +20,7 @@

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

/** \ingroup MapComposer
* Input widget for the configuration of QgsComposerMap
@@ -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;

0 comments on commit 371efa0

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