Skip to content

Commit c5f2f7e

Browse files
committedApr 8, 2014
Use a QDoubleSpinBox instead of a QLineEdit for the snapping
tolerance, make the treeview columns adjust better to the size of the contents
1 parent e71930f commit c5f2f7e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed
 

‎src/app/qgssnappingdialog.cpp

Lines changed: 17 additions & 14 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
@@ -84,11 +85,6 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
8485
}
8586

8687
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 );
9288
mLayerTreeWidget->setSortingEnabled( true );
9389

9490
connect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) );
@@ -174,7 +170,7 @@ void QgsSnappingDialog::apply()
174170
snapToList << "to_vertex_and_segment";
175171
}
176172

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' );
178174
toleranceUnitList << QString::number( qobject_cast<QComboBox*>( mLayerTreeWidget->itemWidget( currentItem, 4 ) )->currentIndex() );
179175

180176
QCheckBox *cbxAvoidIntersection = qobject_cast<QCheckBox*>( mLayerTreeWidget->itemWidget( currentItem, 5 ) );
@@ -262,12 +258,12 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
262258
mLayerTreeWidget->setItemWidget( item, 2, cbxSnapTo );
263259

264260
//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 );
269265

270-
mLayerTreeWidget->setItemWidget( item, 3, leTolerance );
266+
mLayerTreeWidget->setItemWidget( item, 3, sbTolerance );
271267

272268
//snap to vertex/ snap to segment
273269
QComboBox *cbxUnits = new QComboBox( mLayerTreeWidget );
@@ -283,14 +279,20 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
283279
mLayerTreeWidget->setItemWidget( item, 5, cbxAvoidIntersection );
284280
}
285281

282+
//resize treewidget columns
283+
for ( int i = 0 ; i < 4 ; ++i )
284+
{
285+
mLayerTreeWidget->resizeColumnToContents( i );
286+
}
287+
286288
int idx = layerIdList.indexOf( currentVectorLayer->id() );
287289
if ( idx < 0 )
288290
{
289291
if ( myDockFlag )
290292
{
291293
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
292294
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() ) );
294296
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
295297

296298
if ( cbxAvoidIntersection )
@@ -324,7 +326,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
324326
}
325327

326328
cbxSnapTo->setCurrentIndex( snappingStringIdx );
327-
leTolerance->setText( QString::number( toleranceList[idx].toDouble(), 'f' ) );
329+
sbTolerance->setValue( toleranceList[idx].toDouble() );
328330
cbxUnits->setCurrentIndex( toleranceUnitList[idx].toInt() );
329331
if ( cbxAvoidIntersection )
330332
{
@@ -335,7 +337,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
335337
{
336338
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
337339
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() ) );
339341
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
340342

341343
if ( cbxAvoidIntersection )
@@ -384,3 +386,4 @@ void QgsSnappingDialog::setIntersectionSnappingState()
384386
cbxEnableIntersectionSnappingCheckBox->setChecked( intersectionSnapping );
385387
cbxEnableIntersectionSnappingCheckBox->blockSignals( false );
386388
}
389+

0 commit comments

Comments
 (0)
Please sign in to comment.