@@ -68,10 +68,18 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
68
68
connect ( mButtonBox , SIGNAL ( accepted () ), this , SLOT ( apply () ) );
69
69
connect ( mButtonBox ->button ( QDialogButtonBox::Apply ), SIGNAL ( clicked () ), this , SLOT ( apply () ) );
70
70
}
71
- connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer * ) ), this , SLOT ( connectUpdate ( QgsMapLayer * ) ) );
71
+ connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer * ) ), this , SLOT ( addLayer ( QgsMapLayer * ) ) );
72
+ connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWillBeRemoved ( QString ) ), this , SLOT ( layerWillBeRemoved ( QString ) ) );
72
73
connect ( cbxEnableTopologicalEditingCheckBox, SIGNAL ( stateChanged ( int ) ), this , SLOT ( on_cbxEnableTopologicalEditingCheckBox_stateChanged ( int ) ) );
73
74
74
- update ();
75
+ mLayerTreeWidget ->clear ();
76
+
77
+ QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance ()->mapLayers ();
78
+ QMap< QString, QgsMapLayer *>::iterator it;
79
+ for ( it = mapLayers.begin (); it != mapLayers.end () ; ++it )
80
+ {
81
+ addLayer ( it.value () );
82
+ }
75
83
76
84
mLayerTreeWidget ->setHeaderLabels ( QStringList () << " " );
77
85
mLayerTreeWidget ->resizeColumnToContents ( 0 );
@@ -80,6 +88,17 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
80
88
mLayerTreeWidget ->resizeColumnToContents ( 3 );
81
89
mLayerTreeWidget ->resizeColumnToContents ( 4 );
82
90
mLayerTreeWidget ->setSortingEnabled ( true );
91
+
92
+ // read the digitizing settings
93
+ int topologicalEditing = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /TopologicalEditing" , 0 );
94
+ if ( topologicalEditing != 0 )
95
+ {
96
+ cbxEnableTopologicalEditingCheckBox->setCheckState ( Qt::Checked );
97
+ }
98
+ else
99
+ {
100
+ cbxEnableTopologicalEditingCheckBox->setCheckState ( Qt::Unchecked );
101
+ }
83
102
}
84
103
85
104
QgsSnappingDialog::QgsSnappingDialog ()
@@ -108,150 +127,6 @@ void QgsSnappingDialog::closeEvent( QCloseEvent* event )
108
127
}
109
128
110
129
111
- void QgsSnappingDialog::update ()
112
- {
113
- if ( !mMapCanvas )
114
- return ;
115
-
116
- QSettings myQsettings;
117
- bool myDockFlag = myQsettings.value ( " /qgis/dockSnapping" , false ).toBool ();
118
-
119
- double defaultSnappingTolerance = myQsettings.value ( " /qgis/digitizing/default_snapping_tolerance" , 0 ).toDouble ();
120
- int defaultSnappingUnit = myQsettings.value ( " /qgis/digitizing/default_snapping_tolerance_unit" , 0 ).toInt ();
121
- QString defaultSnappingString = myQsettings.value ( " /qgis/digitizing/default_snap_mode" , " to vertex" ).toString ();
122
-
123
- int defaultSnappingStringIdx = 0 ;
124
- if ( defaultSnappingString == " to vertex" )
125
- {
126
- defaultSnappingStringIdx = 0 ;
127
- }
128
- else if ( defaultSnappingString == " to segment" )
129
- {
130
- defaultSnappingStringIdx = 1 ;
131
- }
132
- else // to vertex and segment
133
- {
134
- defaultSnappingStringIdx = 2 ;
135
- }
136
-
137
- bool layerIdListOk, enabledListOk, toleranceListOk, toleranceUnitListOk, snapToListOk, avoidIntersectionListOk;
138
- QStringList layerIdList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingList" , &layerIdListOk );
139
- QStringList enabledList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingEnabledList" , &enabledListOk );
140
- QStringList toleranceList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingToleranceList" , & toleranceListOk );
141
- QStringList toleranceUnitList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingToleranceUnitList" , & toleranceUnitListOk );
142
- QStringList snapToList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnapToList" , &snapToListOk );
143
- QStringList avoidIntersectionsList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /AvoidIntersectionsList" , &avoidIntersectionListOk );
144
-
145
- mLayerTreeWidget ->clear ();
146
-
147
- QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance ()->mapLayers ();
148
- QMap< QString, QgsMapLayer *>::iterator it;
149
- for ( it = mapLayers.begin (); it != mapLayers.end () ; ++it )
150
- {
151
- QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( it.value () );
152
- if ( !currentVectorLayer || currentVectorLayer->geometryType () == QGis::NoGeometry )
153
- continue ;
154
-
155
- // snap to layer yes/no
156
- QTreeWidgetItem *item = new QTreeWidgetItem ( mLayerTreeWidget );
157
-
158
- QCheckBox *cbxEnable = new QCheckBox ( mLayerTreeWidget );
159
- mLayerTreeWidget ->setItemWidget ( item, 0 , cbxEnable );
160
- item->setData ( 0 , Qt::UserRole, currentVectorLayer->id () );
161
-
162
- item->setText ( 1 , currentVectorLayer->name () );
163
-
164
- // snap to vertex/ snap to segment
165
- QComboBox *cbxSnapTo = new QComboBox ( mLayerTreeWidget );
166
- cbxSnapTo->insertItem ( 0 , tr ( " to vertex" ) );
167
- cbxSnapTo->insertItem ( 1 , tr ( " to segment" ) );
168
- cbxSnapTo->insertItem ( 2 , tr ( " to vertex and segment" ) );
169
- cbxSnapTo->setCurrentIndex ( defaultSnappingStringIdx );
170
- mLayerTreeWidget ->setItemWidget ( item, 2 , cbxSnapTo );
171
-
172
- // snapping tolerance
173
- QLineEdit *leTolerance = new QLineEdit ( mLayerTreeWidget );
174
- QDoubleValidator *validator = new QDoubleValidator ( leTolerance );
175
- leTolerance->setValidator ( validator );
176
- leTolerance->setText ( QString::number ( defaultSnappingTolerance, ' f' ) );
177
-
178
- mLayerTreeWidget ->setItemWidget ( item, 3 , leTolerance );
179
-
180
- // snap to vertex/ snap to segment
181
- QComboBox *cbxUnits = new QComboBox ( mLayerTreeWidget );
182
- cbxUnits->insertItem ( 0 , tr ( " map units" ) );
183
- cbxUnits->insertItem ( 1 , tr ( " pixels" ) );
184
- cbxUnits->setCurrentIndex ( defaultSnappingUnit );
185
- mLayerTreeWidget ->setItemWidget ( item, 4 , cbxUnits );
186
-
187
- QCheckBox *cbxAvoidIntersection = 0 ;
188
- if ( currentVectorLayer->geometryType () == QGis::Polygon )
189
- {
190
- cbxAvoidIntersection = new QCheckBox ( mLayerTreeWidget );
191
- mLayerTreeWidget ->setItemWidget ( item, 5 , cbxAvoidIntersection );
192
- }
193
-
194
- int idx = layerIdList.indexOf ( currentVectorLayer->id () );
195
- if ( idx < 0 )
196
- {
197
- // no settings for this layer yet
198
- continue ;
199
- }
200
-
201
- cbxEnable->setChecked ( enabledList[ idx ] == " enabled" );
202
-
203
- int snappingStringIdx = 0 ;
204
- if ( snapToList[idx] == " to_vertex" )
205
- {
206
- snappingStringIdx = 0 ;
207
- }
208
- else if ( snapToList[idx] == " to_segment" )
209
- {
210
- snappingStringIdx = 1 ;
211
- }
212
- else // to vertex and segment
213
- {
214
- snappingStringIdx = 2 ;
215
- }
216
- cbxSnapTo->setCurrentIndex ( snappingStringIdx );
217
- leTolerance->setText ( QString::number ( toleranceList[idx].toDouble (), ' f' ) );
218
- cbxUnits->setCurrentIndex ( toleranceUnitList[idx].toInt () );
219
- if ( cbxAvoidIntersection )
220
- {
221
- cbxAvoidIntersection->setChecked ( avoidIntersectionsList.contains ( currentVectorLayer->id () ) );
222
- }
223
- }
224
-
225
- // read the digitizing settings
226
- int topologicalEditing = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /TopologicalEditing" , 0 );
227
- if ( topologicalEditing != 0 )
228
- {
229
- cbxEnableTopologicalEditingCheckBox->setCheckState ( Qt::Checked );
230
- }
231
- else
232
- {
233
- cbxEnableTopologicalEditingCheckBox->setCheckState ( Qt::Unchecked );
234
- }
235
-
236
- if ( myDockFlag )
237
- {
238
- for ( int i = 0 ; i < mLayerTreeWidget ->topLevelItemCount (); ++i )
239
- {
240
- QTreeWidgetItem *item = mLayerTreeWidget ->topLevelItem ( i );
241
- connect ( mLayerTreeWidget ->itemWidget ( item, 0 ), SIGNAL ( stateChanged ( int ) ), this , SLOT ( apply () ) );
242
- connect ( mLayerTreeWidget ->itemWidget ( item, 2 ), SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
243
- connect ( mLayerTreeWidget ->itemWidget ( item, 3 ), SIGNAL ( textEdited ( const QString ) ), this , SLOT ( apply () ) );
244
- connect ( mLayerTreeWidget ->itemWidget ( item, 4 ), SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
245
-
246
- QCheckBox *cbxAvoidIntersection = qobject_cast<QCheckBox*>( mLayerTreeWidget ->itemWidget ( item, 5 ) );
247
- if ( cbxAvoidIntersection )
248
- {
249
- connect ( cbxAvoidIntersection, SIGNAL ( stateChanged ( int ) ), this , SLOT ( apply () ) );
250
- }
251
- }
252
- }
253
- }
254
-
255
130
void QgsSnappingDialog::apply ()
256
131
{
257
132
QStringList layerIdList;
@@ -312,9 +187,136 @@ void QgsSnappingDialog::show()
312
187
QDialog::show ();
313
188
}
314
189
190
+ void QgsSnappingDialog::addLayer ( QgsMapLayer * theMapLayer )
191
+ {
192
+ QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( theMapLayer );
193
+ if ( !currentVectorLayer || currentVectorLayer->geometryType () == QGis::NoGeometry )
194
+ return ;
195
+
196
+ QSettings myQsettings;
197
+ bool myDockFlag = myQsettings.value ( " /qgis/dockSnapping" , false ).toBool ();
198
+
199
+ double defaultSnappingTolerance = myQsettings.value ( " /qgis/digitizing/default_snapping_tolerance" , 0 ).toDouble ();
200
+ int defaultSnappingUnit = myQsettings.value ( " /qgis/digitizing/default_snapping_tolerance_unit" , 0 ).toInt ();
201
+ QString defaultSnappingString = myQsettings.value ( " /qgis/digitizing/default_snap_mode" , " to vertex" ).toString ();
202
+
203
+ int defaultSnappingStringIdx = 0 ;
204
+ if ( defaultSnappingString == " to vertex" )
205
+ {
206
+ defaultSnappingStringIdx = 0 ;
207
+ }
208
+ else if ( defaultSnappingString == " to segment" )
209
+ {
210
+ defaultSnappingStringIdx = 1 ;
211
+ }
212
+ else // to vertex and segment
213
+ {
214
+ defaultSnappingStringIdx = 2 ;
215
+ }
216
+
217
+ bool layerIdListOk, enabledListOk, toleranceListOk, toleranceUnitListOk, snapToListOk, avoidIntersectionListOk;
218
+ QStringList layerIdList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingList" , &layerIdListOk );
219
+ QStringList enabledList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingEnabledList" , &enabledListOk );
220
+ QStringList toleranceList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingToleranceList" , & toleranceListOk );
221
+ QStringList toleranceUnitList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnappingToleranceUnitList" , & toleranceUnitListOk );
222
+ QStringList snapToList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /LayerSnapToList" , &snapToListOk );
223
+ QStringList avoidIntersectionsList = QgsProject::instance ()->readListEntry ( " Digitizing" , " /AvoidIntersectionsList" , &avoidIntersectionListOk );
224
+
225
+ // snap to layer yes/no
226
+ QTreeWidgetItem *item = new QTreeWidgetItem ( mLayerTreeWidget );
227
+
228
+ QCheckBox *cbxEnable = new QCheckBox ( mLayerTreeWidget );
229
+ mLayerTreeWidget ->setItemWidget ( item, 0 , cbxEnable );
230
+ item->setData ( 0 , Qt::UserRole, currentVectorLayer->id () );
231
+
232
+ item->setText ( 1 , currentVectorLayer->name () );
233
+
234
+ // snap to vertex/ snap to segment
235
+ QComboBox *cbxSnapTo = new QComboBox ( mLayerTreeWidget );
236
+ cbxSnapTo->insertItem ( 0 , tr ( " to vertex" ) );
237
+ cbxSnapTo->insertItem ( 1 , tr ( " to segment" ) );
238
+ cbxSnapTo->insertItem ( 2 , tr ( " to vertex and segment" ) );
239
+ cbxSnapTo->setCurrentIndex ( defaultSnappingStringIdx );
240
+ mLayerTreeWidget ->setItemWidget ( item, 2 , cbxSnapTo );
241
+
242
+ // snapping tolerance
243
+ QLineEdit *leTolerance = new QLineEdit ( mLayerTreeWidget );
244
+ QDoubleValidator *validator = new QDoubleValidator ( leTolerance );
245
+ leTolerance->setValidator ( validator );
246
+ leTolerance->setText ( QString::number ( defaultSnappingTolerance, ' f' ) );
247
+
248
+ mLayerTreeWidget ->setItemWidget ( item, 3 , leTolerance );
249
+
250
+ // snap to vertex/ snap to segment
251
+ QComboBox *cbxUnits = new QComboBox ( mLayerTreeWidget );
252
+ cbxUnits->insertItem ( 0 , tr ( " map units" ) );
253
+ cbxUnits->insertItem ( 1 , tr ( " pixels" ) );
254
+ cbxUnits->setCurrentIndex ( defaultSnappingUnit );
255
+ mLayerTreeWidget ->setItemWidget ( item, 4 , cbxUnits );
256
+
257
+ QCheckBox *cbxAvoidIntersection = 0 ;
258
+ if ( currentVectorLayer->geometryType () == QGis::Polygon )
259
+ {
260
+ cbxAvoidIntersection = new QCheckBox ( mLayerTreeWidget );
261
+ mLayerTreeWidget ->setItemWidget ( item, 5 , cbxAvoidIntersection );
262
+ }
263
+
264
+ if ( myDockFlag )
265
+ {
266
+ connect ( cbxEnable, SIGNAL ( stateChanged ( int ) ), this , SLOT ( apply () ) );
267
+ connect ( cbxSnapTo, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
268
+ connect ( leTolerance, SIGNAL ( textEdited ( const QString ) ), this , SLOT ( apply () ) );
269
+ connect ( cbxUnits, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
270
+
271
+ if ( cbxAvoidIntersection )
272
+ {
273
+ connect ( cbxAvoidIntersection, SIGNAL ( stateChanged ( int ) ), this , SLOT ( apply () ) );
274
+ }
275
+ }
315
276
316
- void QgsSnappingDialog::connectUpdate ( QgsMapLayer * theMapLayer )
277
+ int idx = layerIdList.indexOf ( currentVectorLayer->id () );
278
+ if ( idx < 0 )
279
+ {
280
+ // no settings for this layer yet
281
+ return ;
282
+ }
283
+
284
+ cbxEnable->setChecked ( enabledList[ idx ] == " enabled" );
285
+
286
+ int snappingStringIdx = 0 ;
287
+ if ( snapToList[idx] == " to_vertex" )
288
+ {
289
+ snappingStringIdx = 0 ;
290
+ }
291
+ else if ( snapToList[idx] == " to_segment" )
292
+ {
293
+ snappingStringIdx = 1 ;
294
+ }
295
+ else // to vertex and segment
296
+ {
297
+ snappingStringIdx = 2 ;
298
+ }
299
+ cbxSnapTo->setCurrentIndex ( snappingStringIdx );
300
+ leTolerance->setText ( QString::number ( toleranceList[idx].toDouble (), ' f' ) );
301
+ cbxUnits->setCurrentIndex ( toleranceUnitList[idx].toInt () );
302
+ if ( cbxAvoidIntersection )
303
+ {
304
+ cbxAvoidIntersection->setChecked ( avoidIntersectionsList.contains ( currentVectorLayer->id () ) );
305
+ }
306
+ }
307
+
308
+ void QgsSnappingDialog::layerWillBeRemoved ( QString theLayerId )
317
309
{
318
- connect ( theMapLayer, SIGNAL ( destroyed () ), this , SLOT ( update () ) );
319
- update ();
310
+ QTreeWidgetItem *item;
311
+
312
+ for ( int i = 0 ; i < mLayerTreeWidget ->topLevelItemCount (); ++i )
313
+ {
314
+ item = mLayerTreeWidget ->topLevelItem ( i );
315
+ if ( item && item->data ( 0 , Qt::UserRole ).toString () == theLayerId )
316
+ break ;
317
+ item = 0 ;
318
+ }
319
+
320
+ if ( item )
321
+ delete item;
320
322
}
0 commit comments