Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 6a309f5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/app/qgssnappingdialog.cpp
Expand Up @@ -30,6 +30,7 @@
#include <QLineEdit>
#include <QDockWidget>
#include <QPushButton>
#include <QDoubleSpinBox>


class QgsSnappingDock : public QDockWidget
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
Expand Down

0 comments on commit 6a309f5

Please sign in to comment.