Skip to content

Commit 4426308

Browse files
author
jef
committed
apply #3232
git-svn-id: http://svn.osgeo.org/qgis/trunk@14777 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0e2ffec commit 4426308

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/app/qgssnappingdialog.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QComboBox>
2828
#include <QLineEdit>
2929
#include <QDockWidget>
30+
#include <QPushButton>
3031

3132

3233
class QgsSnappingDock : public QDockWidget
@@ -63,9 +64,9 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
6364
else
6465
{
6566
connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( apply() ) );
67+
connect( mButtonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
6668
}
67-
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer * ) ), this, SLOT( update() ) );
68-
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( update() ) );
69+
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer * ) ), this, SLOT( connectUpdate( QgsMapLayer * ) ) );
6970

7071
update();
7172

@@ -133,9 +134,11 @@ void QgsSnappingDialog::update()
133134

134135
mLayerTreeWidget->clear();
135136

136-
for ( int i = 0; i < mMapCanvas->layerCount(); ++i )
137+
QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
138+
QMap< QString, QgsMapLayer *>::iterator it;
139+
for ( it = mapLayers.begin(); it != mapLayers.end() ; ++it )
137140
{
138-
QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->layer( i ) );
141+
QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( it.value() );
139142
if ( !currentVectorLayer )
140143
continue;
141144

@@ -262,3 +265,10 @@ void QgsSnappingDialog::show()
262265
else
263266
QDialog::show();
264267
}
268+
269+
270+
void QgsSnappingDialog::connectUpdate( QgsMapLayer * theMapLayer )
271+
{
272+
connect( theMapLayer, SIGNAL( destroyed() ), this, SLOT( update() ) );
273+
update();
274+
}

src/app/qgssnappingdialog.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef QGSSNAPPINGDIALOG_H
1919
#define QGSSNAPPINGDIALOG_H
2020

21+
#include "qgsmaplayer.h"
2122
#include "ui_qgssnappingdialogbase.h"
2223

2324
class QDockWidget;
@@ -41,12 +42,12 @@ class QgsSnappingDialog: public QDialog, private Ui::QgsSnappingDialogBase
4142
//! apply the changes
4243
void apply();
4344

44-
//! update the Dialog
45-
void update();
46-
4745
//! show dialog or dock
4846
void show();
4947

48+
//! connect to the layers destroyed() and then update()
49+
void connectUpdate( QgsMapLayer* theMapLayer );
50+
5051
protected:
5152
/**Constructor
5253
@param canvas pointer to the map canvas (for detecting which vector layers are loaded
@@ -67,6 +68,10 @@ class QgsSnappingDialog: public QDialog, private Ui::QgsSnappingDialogBase
6768
QgsMapCanvas* mMapCanvas;
6869

6970
QDockWidget *mDock;
71+
72+
private slots:
73+
//! update the Dialog
74+
void update();
7075
};
7176

7277
#endif

src/core/qgsmaplayerregistry.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ void QgsMapLayerRegistry::removeAllMapLayers()
111111
{
112112
emit layerWillBeRemoved( it.key() );
113113
delete it.value(); // delete the map layer
114+
mMapLayers.remove( it.key() );
114115
}
115116
mMapLayers.clear();
116117

src/ui/qgssnappingdialogbase.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</property>
3131
<column>
3232
<property name="text">
33-
<string> </string>
33+
<string/>
3434
</property>
3535
</column>
3636
<column>
@@ -61,7 +61,7 @@
6161
<enum>Qt::Horizontal</enum>
6262
</property>
6363
<property name="standardButtons">
64-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
64+
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
6565
</property>
6666
</widget>
6767
</item>

0 commit comments

Comments
 (0)