30
30
#include < QLineEdit>
31
31
#include < QDockWidget>
32
32
#include < QPushButton>
33
+ #include < QDoubleSpinBox>
33
34
34
35
35
36
class QgsSnappingDock : public QDockWidget
@@ -84,11 +85,6 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
84
85
}
85
86
86
87
mLayerTreeWidget ->setHeaderLabels ( QStringList () << " " );
87
- mLayerTreeWidget ->resizeColumnToContents ( 0 );
88
- mLayerTreeWidget ->setColumnWidth ( 1 , 200 ); // hardcoded for now
89
- mLayerTreeWidget ->setColumnWidth ( 2 , 200 ); // hardcoded for now
90
- mLayerTreeWidget ->resizeColumnToContents ( 3 );
91
- mLayerTreeWidget ->resizeColumnToContents ( 4 );
92
88
mLayerTreeWidget ->setSortingEnabled ( true );
93
89
94
90
connect ( QgsProject::instance (), SIGNAL ( snapSettingsChanged () ), this , SLOT ( reload () ) );
@@ -174,7 +170,7 @@ void QgsSnappingDialog::apply()
174
170
snapToList << " to_vertex_and_segment" ;
175
171
}
176
172
177
- toleranceList << QString::number ( qobject_cast<QLineEdit *>( mLayerTreeWidget ->itemWidget ( currentItem, 3 ) )->text (). toDouble (), ' f' );
173
+ toleranceList << QString::number ( qobject_cast<QDoubleSpinBox *>( mLayerTreeWidget ->itemWidget ( currentItem, 3 ) )->value (), ' f' );
178
174
toleranceUnitList << QString::number ( qobject_cast<QComboBox*>( mLayerTreeWidget ->itemWidget ( currentItem, 4 ) )->currentIndex () );
179
175
180
176
QCheckBox *cbxAvoidIntersection = qobject_cast<QCheckBox*>( mLayerTreeWidget ->itemWidget ( currentItem, 5 ) );
@@ -262,12 +258,12 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
262
258
mLayerTreeWidget ->setItemWidget ( item, 2 , cbxSnapTo );
263
259
264
260
// snapping tolerance
265
- QLineEdit *leTolerance = new QLineEdit ( mLayerTreeWidget );
266
- QDoubleValidator *validator = new QDoubleValidator ( leTolerance );
267
- leTolerance-> setValidator ( validator );
268
- leTolerance-> setText ( QString::number ( defaultSnappingTolerance, ' f ' ) );
261
+ QDoubleSpinBox* sbTolerance = new QDoubleSpinBox ( mLayerTreeWidget );
262
+ sbTolerance-> setRange ( 0 ., 100000000 . );
263
+ sbTolerance-> setDecimals ( 5 );
264
+ sbTolerance-> setValue ( defaultSnappingTolerance );
269
265
270
- mLayerTreeWidget ->setItemWidget ( item, 3 , leTolerance );
266
+ mLayerTreeWidget ->setItemWidget ( item, 3 , sbTolerance );
271
267
272
268
// snap to vertex/ snap to segment
273
269
QComboBox *cbxUnits = new QComboBox ( mLayerTreeWidget );
@@ -283,14 +279,20 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
283
279
mLayerTreeWidget ->setItemWidget ( item, 5 , cbxAvoidIntersection );
284
280
}
285
281
282
+ // resize treewidget columns
283
+ for ( int i = 0 ; i < 4 ; ++i )
284
+ {
285
+ mLayerTreeWidget ->resizeColumnToContents ( i );
286
+ }
287
+
286
288
int idx = layerIdList.indexOf ( currentVectorLayer->id () );
287
289
if ( idx < 0 )
288
290
{
289
291
if ( myDockFlag )
290
292
{
291
293
connect ( cbxEnable, SIGNAL ( stateChanged ( int ) ), this , SLOT ( apply () ) );
292
294
connect ( cbxSnapTo, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
293
- connect ( leTolerance , SIGNAL ( textEdited ( const QString ) ), this , SLOT ( apply () ) );
295
+ connect ( sbTolerance , SIGNAL ( valueChanged ( double ) ), this , SLOT ( apply () ) );
294
296
connect ( cbxUnits, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
295
297
296
298
if ( cbxAvoidIntersection )
@@ -324,7 +326,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
324
326
}
325
327
326
328
cbxSnapTo->setCurrentIndex ( snappingStringIdx );
327
- leTolerance-> setText ( QString::number ( toleranceList[idx].toDouble (), ' f ' ) );
329
+ sbTolerance-> setValue ( toleranceList[idx].toDouble () );
328
330
cbxUnits->setCurrentIndex ( toleranceUnitList[idx].toInt () );
329
331
if ( cbxAvoidIntersection )
330
332
{
@@ -335,7 +337,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
335
337
{
336
338
connect ( cbxEnable, SIGNAL ( stateChanged ( int ) ), this , SLOT ( apply () ) );
337
339
connect ( cbxSnapTo, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
338
- connect ( leTolerance , SIGNAL ( textEdited ( const QString ) ), this , SLOT ( apply () ) );
340
+ connect ( sbTolerance , SIGNAL ( valueChanged ( double ) ), this , SLOT ( apply () ) );
339
341
connect ( cbxUnits, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( apply () ) );
340
342
341
343
if ( cbxAvoidIntersection )
@@ -384,3 +386,4 @@ void QgsSnappingDialog::setIntersectionSnappingState()
384
386
cbxEnableIntersectionSnappingCheckBox->setChecked ( intersectionSnapping );
385
387
cbxEnableIntersectionSnappingCheckBox->blockSignals ( false );
386
388
}
389
+
0 commit comments