Skip to content

Commit c87f2c8

Browse files
author
wonder
committedApr 5, 2009
Added possibility to express tolerances for digitising also in pixels in addition to map units. Patch contributed by Richard Kostecky.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10478 c8812cc2-4d05-0410-92ff-de0c093fc19c

16 files changed

+287
-12
lines changed
 

‎python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
%Include qgscoordinatereferencesystem.sip
6565
%Include qgssymbol.sip
6666
%Include qgssymbologyutils.sip
67+
%Include qgstolerance.sip
6768
%Include qgsuniquevaluerenderer.sip
6869
%Include qgsvectordataprovider.sip
6970
%Include qgsvectorfilewriter.sip

‎python/core/qgssnapper.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public:
6565
double mTolerance;
6666
/**What snapping type to use (snap to segment or to vertex)*/
6767
QgsSnapper::SnappingType mSnapTo;
68+
/**What unit is used for tolerance*/
69+
QgsTolerance::UnitType mUnitType;
6870
};
6971

7072
QgsSnapper(QgsMapRenderer* mapRender);

‎python/core/qgstolerance.sip

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
class QgsTolerance
3+
{
4+
%TypeHeaderCode
5+
#include <qgstolerance.h>
6+
%End
7+
8+
public:
9+
/**Type of unit of tolerance value from settings*/
10+
enum UnitType
11+
{
12+
/**Map unit value*/
13+
MapUnits,
14+
/**Pixels unit of tolerance*/
15+
Pixels
16+
};
17+
18+
/**
19+
* Static function to get vertex tolerance value from settings
20+
* @param mapUnitsPerPixel number of map units per pixel
21+
* @return value of vertex tolerance in map units
22+
*/
23+
static double vertexSearchRadius( double mapUnitsPerPixel );
24+
25+
/**
26+
* Static function to get default tolerance value from settings
27+
* @param mapUnitsPerPixel number of map units per pixel
28+
* @return value of default tolerance in map units
29+
*/
30+
static double defaultTolerance( double mapUnitsPerPixel );
31+
32+
/**
33+
* Static function to translate tolerance value into current map unit value
34+
* @param tolerace tolerance value to be translated
35+
* @param mapUnitsPerPixel number of map units per pixel
36+
* @param units type of units to be translated
37+
* @return value of tolerance in map units
38+
*/
39+
static double toleranceInMapUnits(double tolerance, double mapUnitsPerPixel, UnitType units = MapUnits);
40+
41+
};
42+

‎src/app/qgsmaptoolmovefeature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsrubberband.h"
2222
#include "qgsvectordataprovider.h"
2323
#include "qgsvectorlayer.h"
24+
#include "qgstolerance.h"
2425
#include <QMessageBox>
2526
#include <QMouseEvent>
2627
#include <QSettings>
@@ -71,7 +72,7 @@ void QgsMapToolMoveFeature::canvasPressEvent( QMouseEvent * e )
7172
//find first geometry under mouse cursor and store iterator to it
7273
QgsPoint layerCoords = toLayerCoordinates(( QgsMapLayer* )vlayer, e->pos() );
7374
QSettings settings;
74-
double searchRadius = settings.value( "/qgis/digitizing/search_radius_vertex_edit", 10 ).toDouble();
75+
double searchRadius = QgsTolerance::vertexSearchRadius( mCanvas->mapUnitsPerPixel() );
7576
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
7677
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );
7778

‎src/app/qgsoptions.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgisapp.h"
2323
#include "qgsgenericprojectionselector.h"
2424
#include "qgscoordinatereferencesystem.h"
25+
#include "qgstolerance.h"
2526

2627
#include <QFileDialog>
2728
#include <QSettings>
@@ -196,6 +197,25 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
196197
mDefaultSnapModeComboBox->setCurrentIndex( mDefaultSnapModeComboBox->findData( defaultSnapString ) );
197198
mDefaultSnappingToleranceSpinBox->setValue( settings.value( "/qgis/digitizing/default_snapping_tolerance", 0 ).toDouble() );
198199
mSearchRadiusVertexEditSpinBox->setValue( settings.value( "/qgis/digitizing/search_radius_vertex_edit", 10 ).toDouble() );
200+
int index;
201+
if (settings.value( "/qgis/digitizing/default_snapping_tolerance_unit", 0 ).toInt() == QgsTolerance::MapUnits)
202+
{
203+
index = mDefaultSnappingToleranceComboBox->findText( tr( "map units" ) );
204+
}
205+
else
206+
{
207+
index = mDefaultSnappingToleranceComboBox->findText( tr( "pixels" ) );
208+
}
209+
mDefaultSnappingToleranceComboBox->setCurrentIndex( index );
210+
if (settings.value( "/qgis/digitizing/search_radius_vertex_edit_unit", 0 ).toInt() == QgsTolerance::MapUnits)
211+
{
212+
index = mSearchRadiusVertexEditComboBox->findText( tr( "map units" ) );
213+
}
214+
else
215+
{
216+
index = mSearchRadiusVertexEditComboBox->findText( tr( "pixels" ) );
217+
}
218+
mSearchRadiusVertexEditComboBox->setCurrentIndex( settings.value( "/qgis/digitizing/search_radius_vertex_edit_unit", 0 ).toInt() );
199219

200220
//vertex marker
201221
mMarkerStyleComboBox->addItem( tr( "Semi transparent circle" ) );
@@ -374,6 +394,11 @@ void QgsOptions::saveOptions()
374394
settings.setValue( "/qgis/digitizing/default_snap_mode", defaultSnapModeString );
375395
settings.setValue( "/qgis/digitizing/default_snapping_tolerance", mDefaultSnappingToleranceSpinBox->value() );
376396
settings.setValue( "/qgis/digitizing/search_radius_vertex_edit", mSearchRadiusVertexEditSpinBox->value() );
397+
settings.setValue( "/qgis/digitizing/default_snapping_tolerance_unit",
398+
(mDefaultSnappingToleranceComboBox->currentIndex() == 0 ? QgsTolerance::MapUnits : QgsTolerance::Pixels ) );
399+
settings.setValue( "/qgis/digitizing/search_radius_vertex_edit_unit",
400+
(mSearchRadiusVertexEditComboBox->currentIndex() == 0 ? QgsTolerance::MapUnits : QgsTolerance::Pixels ) );
401+
377402

378403
QString markerComboText = mMarkerStyleComboBox->currentText();
379404
if ( markerComboText == tr( "Semi transparent circle" ) )

‎src/app/qgsprojectproperties.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
122122
QStringList layerIdList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingList", &ok );
123123
QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", &ok );
124124
QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", &ok );
125+
QStringList toleranceUnitList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList", &ok );
125126
QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", &ok );
126127

127128
QStringList::const_iterator idIter = layerIdList.constBegin();
128129
QStringList::const_iterator enabledIter = enabledList.constBegin();
129130
QStringList::const_iterator tolIter = toleranceList.constBegin();
131+
QStringList::const_iterator tolUnitIter = toleranceUnitList.constBegin();
130132
QStringList::const_iterator snapToIter = snapToList.constBegin();
131133

132134
QgsMapLayer* currentLayer = 0;
@@ -160,6 +162,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
160162
newEntry.snapTo = 2;
161163
}
162164
newEntry.tolerance = tolIter->toDouble();
165+
newEntry.toleranceUnit = tolUnitIter->toInt();
163166
mSnappingLayerSettings.insert( *idIter, newEntry );
164167
}
165168
}
@@ -306,11 +309,13 @@ void QgsProjectProperties::apply()
306309
QStringList snapToList;
307310
QStringList toleranceList;
308311
QStringList enabledList;
312+
QStringList toleranceUnitList;
309313

310314
for ( layerEntryIt = mSnappingLayerSettings.constBegin(); layerEntryIt != mSnappingLayerSettings.constEnd(); ++layerEntryIt )
311315
{
312316
layerIdList << layerEntryIt.key();
313317
toleranceList << QString::number( layerEntryIt->tolerance, 'f' );
318+
toleranceUnitList << QString::number( (int)layerEntryIt->toleranceUnit );
314319
if ( layerEntryIt->checked )
315320
{
316321
enabledList << "enabled";
@@ -338,6 +343,7 @@ void QgsProjectProperties::apply()
338343
QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingList", layerIdList );
339344
QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnapToList", snapToList );
340345
QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingToleranceList", toleranceList );
346+
QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingToleranceUnitList", toleranceUnitList );
341347
QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingEnabledList", enabledList );
342348
}
343349

‎src/app/qgssnappingdialog.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ QgsSnappingDialog::QgsSnappingDialog( QgsMapCanvas* canvas, const QMap<QString,
7171
snappingToleranceEdit->setValidator( validator );
7272
mLayerTreeWidget->setItemWidget( newItem, 2, snappingToleranceEdit );
7373

74+
//snap to vertex/ snap to segment
75+
QComboBox* toleranceUnitsComboBox = new QComboBox( mLayerTreeWidget );
76+
toleranceUnitsComboBox->insertItem( 0, tr( "map units" ) );
77+
toleranceUnitsComboBox->insertItem( 1, tr( "pixels" ) );
78+
mLayerTreeWidget->setItemWidget( newItem, 3, toleranceUnitsComboBox );
79+
7480
settingIt = settings.find( currentVectorLayer->getLayerID() );
7581
if ( settingIt != settings.constEnd() )
7682
{
@@ -89,6 +95,15 @@ QgsSnappingDialog::QgsSnappingDialog( QgsMapCanvas* canvas, const QMap<QString,
8995
index = snapToComboBox->findText( tr( "to vertex and segment" ) );
9096
}
9197
snapToComboBox->setCurrentIndex( index );
98+
if ( settingIt.value().toleranceUnit == 0 )//map units
99+
{
100+
index = toleranceUnitsComboBox->findText( tr( "map units" ) );
101+
}
102+
else
103+
{
104+
index = toleranceUnitsComboBox->findText( tr( "pixels" ) );
105+
}
106+
toleranceUnitsComboBox->setCurrentIndex( index );
92107
if ( settingIt.value().checked )
93108
{
94109
newItem->setCheckState( 0, Qt::Checked );
@@ -103,8 +118,9 @@ QgsSnappingDialog::QgsSnappingDialog( QgsMapCanvas* canvas, const QMap<QString,
103118
}
104119
}
105120
mLayerTreeWidget->resizeColumnToContents( 0 );
106-
mLayerTreeWidget->setColumnWidth( 1, 300 ); //hardcoded for now
121+
mLayerTreeWidget->setColumnWidth( 1, 200 ); //hardcoded for now
107122
mLayerTreeWidget->resizeColumnToContents( 2 );
123+
mLayerTreeWidget->resizeColumnToContents( 3 );
108124
}
109125
}
110126

@@ -127,7 +143,9 @@ void QgsSnappingDialog::layerSettings( QMap<QString, LayerEntry>& settings ) con
127143
QString layerId;
128144
QString layerName;
129145
QString snapToItemText;
146+
QString toleranceItemText;
130147
int snapTo;
148+
int toleranceUnit;
131149
double tolerance;
132150
bool checked = false;
133151

@@ -144,6 +162,7 @@ void QgsSnappingDialog::layerSettings( QMap<QString, LayerEntry>& settings ) con
144162
layerId = mLayerIds.at( i );
145163
checked = ( currentItem->checkState( 0 ) == Qt::Checked );
146164
snapToItemText = (( QComboBox* )( mLayerTreeWidget->itemWidget( currentItem, 1 ) ) )->currentText();
165+
toleranceItemText = (( QComboBox* )( mLayerTreeWidget->itemWidget( currentItem, 3 ) ) )->currentText();
147166
if ( snapToItemText == tr( "to vertex" ) )
148167
{
149168
snapTo = 0;
@@ -156,10 +175,18 @@ void QgsSnappingDialog::layerSettings( QMap<QString, LayerEntry>& settings ) con
156175
{
157176
snapTo = 2;
158177
}
178+
if ( toleranceItemText == tr( "map units" ) )
179+
{
180+
toleranceUnit = 0;
181+
}
182+
else //to vertex and segment
183+
{
184+
toleranceUnit = 1;
185+
}
159186
tolerance = (( QLineEdit* )( mLayerTreeWidget->itemWidget( currentItem, 2 ) ) )->text().toDouble();
160187
LayerEntry newEntry;
161188
newEntry.checked = checked; newEntry.snapTo = snapTo; newEntry.layerName = layerName;
162-
newEntry.tolerance = tolerance;
189+
newEntry.tolerance = tolerance; newEntry.toleranceUnit = toleranceUnit;
163190
settings.insert( layerId, newEntry );
164191
}
165192
}

‎src/app/qgssnappingdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct LayerEntry
2828
int snapTo; //0 = to vertex, 1 = to segment, 2 = to vertex and to segment
2929
QString layerName;
3030
double tolerance;
31+
int toleranceUnit;
3132
};
3233

3334
/**A dialog to enter advanced editing properties, e.g. topological editing, snapping settings

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SET(QGIS_CORE_SRCS
4343
qgssearchtreenode.cpp
4444
qgssnapper.cpp
4545
qgscoordinatereferencesystem.cpp
46+
qgstolerance.cpp
4647
qgsvectordataprovider.cpp
4748
qgsvectorfilewriter.cpp
4849
qgsvectorlayer.cpp

‎src/core/qgssnapper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ int QgsSnapper::snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& s
5656
{
5757
//transform point from map coordinates to layer coordinates
5858
layerCoordPoint = mMapRenderer->mapToLayerCoordinates( snapLayerIt->mLayer, mapCoordPoint );
59-
if ( snapLayerIt->mLayer->snapWithContext( layerCoordPoint, snapLayerIt->mTolerance,
59+
60+
double tolerance = QgsTolerance::toleranceInMapUnits( snapLayerIt->mTolerance, mMapRenderer->mapUnitsPerPixel(), snapLayerIt->mUnitType );
61+
if ( snapLayerIt->mLayer->snapWithContext( layerCoordPoint, tolerance,
6062
currentResultList, snapLayerIt->mSnapTo ) != 0 )
6163
{
6264
//error

‎src/core/qgssnapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define QGSSNAPPER_H
2020

2121
#include "qgspoint.h"
22+
#include "qgstolerance.h"
2223
#include <QList>
2324
#include <QMultiMap>
2425

@@ -86,6 +87,8 @@ class CORE_EXPORT QgsSnapper
8687
double mTolerance;
8788
/**What snapping type to use (snap to segment or to vertex)*/
8889
QgsSnapper::SnappingType mSnapTo;
90+
/**What unit is used for tolerance*/
91+
QgsTolerance::UnitType mUnitType;
8992
};
9093

9194
QgsSnapper( QgsMapRenderer* mapRender );

‎src/core/qgstolerance.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/***************************************************************************
2+
qgstolerance.cpp - wrapper for tolerance handling
3+
----------------------
4+
begin : March 2009
5+
copyright : (C) 2009 by Richard Kostecky
6+
email : csf.kostej at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgstolerance.h"
17+
#include <QSettings>
18+
19+
20+
double QgsTolerance::toleranceInMapUnits(double tolerance, double mapUnitsPerPixel, UnitType units)
21+
{
22+
if (units == MapUnits)
23+
{
24+
return tolerance;
25+
}
26+
return tolerance * mapUnitsPerPixel;
27+
}
28+
29+
double QgsTolerance::vertexSearchRadius( double mapUnitsPerPixel )
30+
{
31+
QSettings settings;
32+
double tolerance = settings.value( "/qgis/digitizing/search_radius_vertex_edit", 10 ).toDouble();
33+
UnitType units = (QgsTolerance::UnitType) settings.value( "/qgis/digitizing/search_radius_vertex_edit_unit", 0 ).toInt();
34+
return toleranceInMapUnits(tolerance, mapUnitsPerPixel, units);
35+
}
36+
37+
double QgsTolerance::defaultTolerance( double mapUnitsPerPixel )
38+
{
39+
QSettings settings;
40+
double tolerance = settings.value( "/qgis/digitizing/default_snapping_tolerance", 0 ).toDouble();
41+
UnitType units = (QgsTolerance::UnitType) settings.value( "/qgis/digitizing/default_snapping_tolerance_unit", 0 ).toInt();
42+
return toleranceInMapUnits(tolerance, mapUnitsPerPixel, units);
43+
}

‎src/core/qgstolerance.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/***************************************************************************
2+
qgstolerance.h - wrapper for tolerance handling
3+
----------------------
4+
begin : March 2009
5+
copyright : (C) 2009 by Richard Kostecky
6+
email : csf.kostej at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSTOLERANCE_H
17+
#define QGSTOLERANCE_H
18+
19+
20+
/** \ingroup core
21+
* This is the class is providing tolerance value in map unit values.
22+
*
23+
* \note This class has been added in version 1.1.
24+
*/
25+
class CORE_EXPORT QgsTolerance
26+
{
27+
28+
public:
29+
/**Type of unit of tolerance value from settings*/
30+
enum UnitType
31+
{
32+
/**Map unit value*/
33+
MapUnits,
34+
/**Pixels unit of tolerance*/
35+
Pixels
36+
};
37+
38+
/**
39+
* Static function to get vertex tolerance value from settings
40+
* @param mapUnitsPerPixel number of map units per pixel
41+
* @return value of vertex tolerance in map units
42+
*/
43+
static double vertexSearchRadius( double mapUnitsPerPixel );
44+
45+
/**
46+
* Static function to get default tolerance value from settings
47+
* @param mapUnitsPerPixel number of map units per pixel
48+
* @return value of default tolerance in map units
49+
*/
50+
static double defaultTolerance( double mapUnitsPerPixel );
51+
52+
/**
53+
* Static function to translate tolerance value into current map unit value
54+
* @param tolerace tolerance value to be translated
55+
* @param mapUnitsPerPixel number of map units per pixel
56+
* @param units type of units to be translated
57+
* @return value of tolerance in map units
58+
*/
59+
static double toleranceInMapUnits(double tolerance, double mapUnitsPerPixel, UnitType units = MapUnits);
60+
61+
};
62+
63+
#endif

‎src/gui/qgsmapcanvassnapper.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#include "qgsmaptopixel.h"
2222
#include "qgsproject.h"
2323
#include "qgsvectorlayer.h"
24+
#include "qgstolerance.h"
2425
#include <QSettings>
2526

27+
2628
QgsMapCanvasSnapper::QgsMapCanvasSnapper( QgsMapCanvas* canvas ): mMapCanvas( canvas ), mSnapper( 0 )
2729
{
2830
if ( canvas )
@@ -92,13 +94,14 @@ int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingR
9294
QgsSnapper::SnapLayer snapLayer;
9395
snapLayer.mLayer = vlayer;
9496
snapLayer.mSnapTo = snap_to;
97+
snapLayer.mUnitType = QgsTolerance::MapUnits;
9598

9699
QSettings settings;
97100

98101
if ( snappingTol < 0 )
99102
{
100103
//use search tolerance for vertex editing
101-
snapLayer.mTolerance = settings.value( "/qgis/digitizing/search_radius_vertex_edit", 50 ).toDouble();
104+
snapLayer.mTolerance = QgsTolerance::vertexSearchRadius(mMapCanvas->mapUnitsPerPixel());
102105
}
103106
else
104107
{
@@ -149,9 +152,10 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
149152
}
150153
QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", &ok );
151154
QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", &ok );
155+
QStringList toleranceUnitList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList", &ok );
152156
QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", &ok );
153157

154-
if ( !( layerIdList.size() == enabledList.size() && layerIdList.size() == toleranceList.size() && layerIdList.size() == snapToList.size() ) )
158+
if ( !( layerIdList.size() == enabledList.size() && layerIdList.size() == toleranceList.size() && layerIdList.size() == toleranceUnitList.size() && layerIdList.size() == snapToList.size() ) )
155159
{
156160
return 1; //lists must have the same size, otherwise something is wrong
157161
}
@@ -168,10 +172,11 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
168172

169173
QStringList::const_iterator layerIt = layerIdList.constBegin();
170174
QStringList::const_iterator tolIt = toleranceList.constBegin();
175+
QStringList::const_iterator tolUnitIt = toleranceUnitList.constBegin();
171176
QStringList::const_iterator snapIt = snapToList.constBegin();
172177
QStringList::const_iterator enabledIt = enabledList.constBegin();
173178

174-
for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++snapIt, ++enabledIt )
179+
for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
175180
{
176181
if (( *enabledIt ) != "enabled" ) //skip layer if snapping is not enabled
177182
{
@@ -191,6 +196,7 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
191196

192197
//tolerance
193198
snapLayer.mTolerance = tolIt->toDouble();
199+
snapLayer.mUnitType = (QgsTolerance::UnitType) tolUnitIt->toInt();
194200

195201
//segment or vertex
196202
if (( *snapIt ) == "to_vertex" )
@@ -241,8 +247,9 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
241247
snapLayer.mSnapTo = QgsSnapper::SnapToVertex;
242248
}
243249

244-
//default snapping tolerance
245-
snapLayer.mTolerance = settings.value( "/qgis/digitizing/default_snapping_tolerance", 0 ).toDouble();
250+
//default snapping tolerance (returned in map units)
251+
snapLayer.mTolerance = QgsTolerance::defaultTolerance(mMapCanvas->mapUnitsPerPixel());
252+
snapLayer.mUnitType = QgsTolerance::MapUnits;
246253

247254
snapLayers.append( snapLayer );
248255
}

‎src/ui/qgsoptionsbase.ui

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@
659659
</property>
660660
</spacer>
661661
</item>
662-
<item row="0" column="4" >
662+
<item row="0" column="4" colspan="2" >
663663
<widget class="QComboBox" name="mDefaultSnapModeComboBox" >
664664
<property name="sizePolicy" >
665665
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -729,6 +729,40 @@
729729
</property>
730730
</widget>
731731
</item>
732+
<item row="1" column="5" >
733+
<widget class="QComboBox" name="mDefaultSnappingToleranceComboBox" >
734+
<property name="sizePolicy" >
735+
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
736+
<horstretch>0</horstretch>
737+
<verstretch>0</verstretch>
738+
</sizepolicy>
739+
</property>
740+
<item>
741+
<property name="text" >
742+
<string>map units</string>
743+
</property>
744+
</item>
745+
<item>
746+
<property name="text" >
747+
<string>pixels</string>
748+
</property>
749+
</item>
750+
</widget>
751+
</item>
752+
<item row="2" column="5" >
753+
<widget class="QComboBox" name="mSearchRadiusVertexEditComboBox" >
754+
<item>
755+
<property name="text" >
756+
<string>map units</string>
757+
</property>
758+
</item>
759+
<item>
760+
<property name="text" >
761+
<string>pixels</string>
762+
</property>
763+
</item>
764+
</widget>
765+
</item>
732766
</layout>
733767
</widget>
734768
</item>

‎src/ui/qgssnappingdialogbase.ui

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@
1313
<string>Snapping options</string>
1414
</property>
1515
<layout class="QGridLayout" >
16-
<property name="margin" >
16+
<property name="leftMargin" >
1717
<number>9</number>
1818
</property>
19-
<property name="spacing" >
19+
<property name="topMargin" >
20+
<number>9</number>
21+
</property>
22+
<property name="rightMargin" >
23+
<number>9</number>
24+
</property>
25+
<property name="bottomMargin" >
26+
<number>9</number>
27+
</property>
28+
<property name="horizontalSpacing" >
29+
<number>6</number>
30+
</property>
31+
<property name="verticalSpacing" >
2032
<number>6</number>
2133
</property>
2234
<item row="0" column="0" >
@@ -36,6 +48,11 @@
3648
<string>Tolerance</string>
3749
</property>
3850
</column>
51+
<column>
52+
<property name="text" >
53+
<string>Units</string>
54+
</property>
55+
</column>
3956
</widget>
4057
</item>
4158
<item row="1" column="0" >

0 commit comments

Comments
 (0)
Please sign in to comment.