Skip to content
Permalink
Browse files

Merge pull request #1304 from manisandro/replace_lineedit_with_combob…

…ox_snappingdialog

Use a spinbox instead of a lineedit for the snapping tolerance
  • Loading branch information
NathanW2 committed Sep 14, 2014
2 parents e4f68b1 + c5f2f7e commit 6a309f566aa470c963b75899366726d3480c3389
Showing with 16 additions and 9 deletions.
  1. +16 −9 src/app/qgssnappingdialog.cpp
@@ -30,6 +30,7 @@
#include <QLineEdit>
#include <QDockWidget>
#include <QPushButton>
#include <QDoubleSpinBox>


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

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

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

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

mLayerTreeWidget->setItemWidget( item, 3, leTolerance );
mLayerTreeWidget->setItemWidget( item, 3, sbTolerance );

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

//resize treewidget columns
for ( int i = 0 ; i < 4 ; ++i )
{
mLayerTreeWidget->resizeColumnToContents( i );
}

int idx = layerIdList.indexOf( currentVectorLayer->id() );
if ( idx < 0 )
{
if ( myDockFlag )
{
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
connect( cbxSnapTo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
connect( leTolerance, SIGNAL( textEdited( const QString ) ), this, SLOT( apply() ) );
connect( sbTolerance, SIGNAL( valueChanged( double ) ), this, SLOT( apply() ) );
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );

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

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

if ( cbxAvoidIntersection )

0 comments on commit 6a309f5

Please sign in to comment.
You can’t perform that action at this time.