Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove/Add layers to snapping dialog. Fixes #5318
  • Loading branch information
NathanW2 committed Apr 7, 2012
1 parent 6403ebd commit a82a243
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
37 changes: 24 additions & 13 deletions src/app/qgssnappingdialog.cpp
Expand Up @@ -69,8 +69,8 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( mButtonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
}
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer * ) ), this, SLOT( addLayer( QgsMapLayer * ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layerWillBeRemoved( QString ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer * > ) ), this, SLOT( addLayers( QList<QgsMapLayer * > ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) );
connect( cbxEnableTopologicalEditingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableTopologicalEditingCheckBox_stateChanged( int ) ) );

mLayerTreeWidget->clear();
Expand Down Expand Up @@ -180,6 +180,14 @@ void QgsSnappingDialog::show()
QDialog::show();
}

void QgsSnappingDialog::addLayers( QList<QgsMapLayer *> layers )
{
foreach( QgsMapLayer* layer, layers )
{
addLayer( layer );
}
}

void QgsSnappingDialog::addLayer( QgsMapLayer * theMapLayer )
{
QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( theMapLayer );
Expand Down Expand Up @@ -298,20 +306,23 @@ void QgsSnappingDialog::addLayer( QgsMapLayer * theMapLayer )
}
}

void QgsSnappingDialog::layerWillBeRemoved( QString theLayerId )
void QgsSnappingDialog::layersWillBeRemoved( QStringList thelayers )
{
QTreeWidgetItem *item = 0;

for ( int i = 0; i < mLayerTreeWidget->topLevelItemCount(); ++i )
foreach( QString theLayerId, thelayers )
{
item = mLayerTreeWidget->topLevelItem( i );
if ( item && item->data( 0, Qt::UserRole ).toString() == theLayerId )
break;
item = 0;
}
QTreeWidgetItem *item = 0;

for ( int i = 0; i < mLayerTreeWidget->topLevelItemCount(); ++i )
{
item = mLayerTreeWidget->topLevelItem( i );
if ( item && item->data( 0, Qt::UserRole ).toString() == theLayerId )
break;
item = 0;
}

if ( item )
delete item;
if ( item )
delete item;
}
}

void QgsSnappingDialog::setTopologicalEditingState()
Expand Down
6 changes: 4 additions & 2 deletions src/app/qgssnappingdialog.h
Expand Up @@ -48,8 +48,10 @@ class QgsSnappingDialog: public QDialog, private Ui::QgsSnappingDialogBase
//! add layer to tree
void addLayer( QgsMapLayer* theMapLayer );

//! layer removed
void layerWillBeRemoved( QString );
void addLayers( QList<QgsMapLayer * > layers );

//! layers removed
void layersWillBeRemoved( QStringList );

void on_cbxEnableTopologicalEditingCheckBox_stateChanged( int );

Expand Down

0 comments on commit a82a243

Please sign in to comment.