Skip to content
Permalink
Browse files

[snapping] fix default snapping type settings

  • Loading branch information
nirvn committed Dec 7, 2016
1 parent 60ad5c6 commit 6b0bf49cd8619d725d12e6dd37431a6f6abc8ffd
Showing with 29 additions and 7 deletions.
  1. +6 −6 src/app/qgsoptions.cpp
  2. +23 −1 src/gui/qgsmapcanvassnapper.cpp
@@ -852,10 +852,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )

//default snap mode
mSnappingEnabledDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool() );
mDefaultSnapModeComboBox->insertItem( 0, tr( "To vertex" ), "to vertex" );
mDefaultSnapModeComboBox->insertItem( 1, tr( "To segment" ), "to segment" );
mDefaultSnapModeComboBox->insertItem( 2, tr( "To vertex and segment" ), "to vertex and segment" );
QString defaultSnapString = mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_mode" ), "to vertex" ).toString();
mDefaultSnapModeComboBox->insertItem( 0, tr( "To vertex" ), QgsSnappingConfig::Vertex );
mDefaultSnapModeComboBox->insertItem( 1, tr( "To segment" ), QgsSnappingConfig::Segment );
mDefaultSnapModeComboBox->insertItem( 2, tr( "To vertex and segment" ), QgsSnappingConfig::VertexAndSegment );
int defaultSnapString = mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_type" ), QgsSnappingConfig::Vertex ).toInt();
mDefaultSnapModeComboBox->setCurrentIndex( mDefaultSnapModeComboBox->findData( defaultSnapString ) );
mDefaultSnappingToleranceSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), 0 ).toDouble() );
mSearchRadiusVertexEditSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit" ), 10 ).toDouble() );
@@ -1360,8 +1360,8 @@ void QgsOptions::saveOptions()

//default snap mode
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), mSnappingEnabledDefault->isChecked() );
QString defaultSnapModeString = mDefaultSnapModeComboBox->currentData().toString();
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_mode" ), defaultSnapModeString );
int defaultSnapModeString = mDefaultSnapModeComboBox->currentData().toInt();
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), defaultSnapModeString );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), mDefaultSnappingToleranceSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit" ), mSearchRadiusVertexEditSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ),
@@ -169,10 +169,32 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QgsPoint& point, QList<Qg
QSettings settings;
QString snappingMode = QgsProject::instance()->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/SnappingMode" ), QStringLiteral( "current_layer" ), &snappingDefinedInProject );
QString defaultSnapToleranceUnit = snappingDefinedInProject ? QgsProject::instance()->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapToleranceUnit" ) ) : settings.value( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ), "0" ).toString();
QString defaultSnapType = snappingDefinedInProject ? QgsProject::instance()->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ) ) : settings.value( QStringLiteral( "/qgis/digitizing/default_snap_mode" ), "to vertex" ).toString();
QString defaultSnapTolerance = snappingDefinedInProject ? QString::number( QgsProject::instance()->readDoubleEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapTolerance" ) ) ) : settings.value( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), "0" ).toString();
bool defaultSnapEnabled = settings.value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool();

QString defaultSnapType;
if ( snappingDefinedInProject )
{
defaultSnapType = QgsProject::instance()->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ) );
}
else
{
int dst;
dst = settings.value( QStringLiteral( "/qgis/digitizing/default_snap_mode" ), QgsSnappingConfig::Vertex ).toInt();
switch ( dst )
{
case QgsSnappingConfig::Segment:
defaultSnapType = QStringLiteral( "to segment" );
break;
case QgsSnappingConfig::VertexAndSegment:
defaultSnapType = QStringLiteral( "to vertex and segment" );
break;
default:
defaultSnapType = QStringLiteral( "to vertex" );
break;
}
}

if ( !snappingDefinedInProject && defaultSnapEnabled == false )
{
return 0;

0 comments on commit 6b0bf49

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