From 3613ba5701a6bd672a5a3edbf19fa0277d9901e8 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Sat, 26 Sep 2015 13:21:56 +0200 Subject: [PATCH] QgsPointLocator::Type : Type safety --- python/core/qgspointlocator.sip | 2 ++ python/core/qgssnappingutils.sip | 4 ++-- src/core/qgspointlocator.h | 11 ++++++++++- src/core/qgssnappingutils.cpp | 8 +++++--- src/core/qgssnappingutils.h | 11 +++++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/python/core/qgspointlocator.sip b/python/core/qgspointlocator.sip index 909355cd664e..9a8040518494 100644 --- a/python/core/qgspointlocator.sip +++ b/python/core/qgspointlocator.sip @@ -16,6 +16,8 @@ class QgsPointLocator : QObject enum Type { Invalid, Vertex, Edge, Area, All }; + typedef QFlags Types; + /** Prepare the index for queries. Does nothing if the index already exists. * If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped * to make sure we do not run out of memory. If maxFeaturesToIndex is -1, no limits are used. Returns diff --git a/python/core/qgssnappingutils.sip b/python/core/qgssnappingutils.sip index d34ae3c9306d..e269047159de 100644 --- a/python/core/qgssnappingutils.sip +++ b/python/core/qgssnappingutils.sip @@ -66,10 +66,10 @@ class QgsSnappingUtils : QObject struct LayerConfig { - LayerConfig( QgsVectorLayer* l, int t, double tol, QgsTolerance::UnitType u ); + LayerConfig( QgsVectorLayer* l, QgsPointLocator::Types t, double tol, QgsTolerance::UnitType u ); QgsVectorLayer* layer; - int type; + QgsPointLocator::Types type; double tolerance; QgsTolerance::UnitType unit; }; diff --git a/src/core/qgspointlocator.h b/src/core/qgspointlocator.h index 459feb8c8096..d5a67b85dc82 100644 --- a/src/core/qgspointlocator.h +++ b/src/core/qgspointlocator.h @@ -57,7 +57,16 @@ class CORE_EXPORT QgsPointLocator : public QObject ~QgsPointLocator(); - enum Type { Invalid = 0, Vertex = 1, Edge = 2, Area = 4, All = Vertex | Edge | Area }; + enum Type + { + Invalid = 0, + Vertex = 1, + Edge = 2, + Area = 4, + All = Vertex | Edge | Area + }; + + Q_DECLARE_FLAGS( Types, Type ) /** Prepare the index for queries. Does nothing if the index already exists. * If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped diff --git a/src/core/qgssnappingutils.cpp b/src/core/qgssnappingutils.cpp index 5ae3ff02b499..93fc25de3708 100644 --- a/src/core/qgssnappingutils.cpp +++ b/src/core/qgssnappingutils.cpp @@ -455,9 +455,11 @@ void QgsSnappingUtils::readConfigFromProject() if ( !vlayer || !vlayer->hasGeometryType() ) continue; - int t = ( *snapIt == "to_vertex" ? QgsPointLocator::Vertex : - ( *snapIt == "to_segment" ? QgsPointLocator::Edge : - QgsPointLocator::Vertex | QgsPointLocator::Edge ) ); + QgsPointLocator::Types t( *snapIt == "to_vertex" ? QgsPointLocator::Vertex : + ( *snapIt == "to_segment" ? QgsPointLocator::Edge : + QgsPointLocator::Vertex | QgsPointLocator::Edge + ) + ); mLayers.append( LayerConfig( vlayer, t, tolIt->toDouble(), ( QgsTolerance::UnitType ) tolUnitIt->toInt() ) ); } diff --git a/src/core/qgssnappingutils.h b/src/core/qgssnappingutils.h index 7e1ed52ac2f2..55995a1a4bcb 100644 --- a/src/core/qgssnappingutils.h +++ b/src/core/qgssnappingutils.h @@ -100,13 +100,20 @@ class CORE_EXPORT QgsSnappingUtils : public QObject /** Query options used when the mode is snap to current layer */ void defaultSettings( int& type, double& tolerance, QgsTolerance::UnitType& unit ); + /** + * Configures how a certain layer should be handled in a snapping operation + */ struct LayerConfig { - LayerConfig( QgsVectorLayer* l, int t, double tol, QgsTolerance::UnitType u ) : layer( l ), type( t ), tolerance( tol ), unit( u ) {} + LayerConfig( QgsVectorLayer* l, QgsPointLocator::Types t, double tol, QgsTolerance::UnitType u ) : layer( l ), type( t ), tolerance( tol ), unit( u ) {} + //! The layer to configure. QgsVectorLayer* layer; - int type; + //! To which geometry properties of this layers a snapping should happen. + QgsPointLocator::Types type; + //! The range around snapping targets in which snapping should occur. double tolerance; + //! The units in which the tolerance is specified. QgsTolerance::UnitType unit; };