Skip to content

Commit 6a309f5

Browse files
committed
Merge pull request #1304 from manisandro/replace_lineedit_with_combobox_snappingdialog
Use a spinbox instead of a lineedit for the snapping tolerance
2 parents e4f68b1 + c5f2f7e commit 6a309f5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/app/qgssnappingdialog.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QLineEdit>
3131
#include <QDockWidget>
3232
#include <QPushButton>
33+
#include <QDoubleSpinBox>
3334

3435

3536
class QgsSnappingDock : public QDockWidget
@@ -172,7 +173,7 @@ void QgsSnappingDialog::apply()
172173
snapToList << "to_vertex_and_segment";
173174
}
174175

175-
toleranceList << QString::number( qobject_cast<QLineEdit*>( mLayerTreeWidget->itemWidget( currentItem, 3 ) )->text().toDouble(), 'f' );
176+
toleranceList << QString::number( qobject_cast<QDoubleSpinBox*>( mLayerTreeWidget->itemWidget( currentItem, 3 ) )->value(), 'f' );
176177
toleranceUnitList << QString::number( qobject_cast<QComboBox*>( mLayerTreeWidget->itemWidget( currentItem, 4 ) )->currentIndex() );
177178

178179
QCheckBox *cbxAvoidIntersection = qobject_cast<QCheckBox*>( mLayerTreeWidget->itemWidget( currentItem, 5 ) );
@@ -274,12 +275,12 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
274275
mLayerTreeWidget->setItemWidget( item, 2, cbxSnapTo );
275276

276277
//snapping tolerance
277-
QLineEdit *leTolerance = new QLineEdit( mLayerTreeWidget );
278-
QDoubleValidator *validator = new QDoubleValidator( leTolerance );
279-
leTolerance->setValidator( validator );
280-
leTolerance->setText( QString::number( defaultSnappingTolerance, 'f' ) );
278+
QDoubleSpinBox* sbTolerance = new QDoubleSpinBox( mLayerTreeWidget );
279+
sbTolerance->setRange( 0., 100000000. );
280+
sbTolerance->setDecimals( 5 );
281+
sbTolerance->setValue( defaultSnappingTolerance );
281282

282-
mLayerTreeWidget->setItemWidget( item, 3, leTolerance );
283+
mLayerTreeWidget->setItemWidget( item, 3, sbTolerance );
283284

284285
//snap to vertex/ snap to segment
285286
QComboBox *cbxUnits = new QComboBox( mLayerTreeWidget );
@@ -295,14 +296,20 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
295296
mLayerTreeWidget->setItemWidget( item, 5, cbxAvoidIntersection );
296297
}
297298

299+
//resize treewidget columns
300+
for ( int i = 0 ; i < 4 ; ++i )
301+
{
302+
mLayerTreeWidget->resizeColumnToContents( i );
303+
}
304+
298305
int idx = layerIdList.indexOf( currentVectorLayer->id() );
299306
if ( idx < 0 )
300307
{
301308
if ( myDockFlag )
302309
{
303310
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
304311
connect( cbxSnapTo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
305-
connect( leTolerance, SIGNAL( textEdited( const QString ) ), this, SLOT( apply() ) );
312+
connect( sbTolerance, SIGNAL( valueChanged( double ) ), this, SLOT( apply() ) );
306313
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
307314

308315
if ( cbxAvoidIntersection )
@@ -336,7 +343,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
336343
}
337344

338345
cbxSnapTo->setCurrentIndex( snappingStringIdx );
339-
leTolerance->setText( QString::number( toleranceList[idx].toDouble(), 'f' ) );
346+
sbTolerance->setValue( toleranceList[idx].toDouble() );
340347
cbxUnits->setCurrentIndex( toleranceUnitList[idx].toInt() );
341348
if ( cbxAvoidIntersection )
342349
{
@@ -347,7 +354,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
347354
{
348355
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
349356
connect( cbxSnapTo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
350-
connect( leTolerance, SIGNAL( textEdited( const QString ) ), this, SLOT( apply() ) );
357+
connect( sbTolerance, SIGNAL( valueChanged( double ) ), this, SLOT( apply() ) );
351358
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
352359

353360
if ( cbxAvoidIntersection )

0 commit comments

Comments
 (0)