Skip to content

Commit 3613ba5

Browse files
committed
QgsPointLocator::Type : Type safety
1 parent dd9b37b commit 3613ba5

5 files changed

Lines changed: 28 additions & 8 deletions

File tree

python/core/qgspointlocator.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class QgsPointLocator : QObject
1616

1717
enum Type { Invalid, Vertex, Edge, Area, All };
1818

19+
typedef QFlags<QgsPointLocator::Type> Types;
20+
1921
/** Prepare the index for queries. Does nothing if the index already exists.
2022
* If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped
2123
* to make sure we do not run out of memory. If maxFeaturesToIndex is -1, no limits are used. Returns

python/core/qgssnappingutils.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class QgsSnappingUtils : QObject
6666

6767
struct LayerConfig
6868
{
69-
LayerConfig( QgsVectorLayer* l, int t, double tol, QgsTolerance::UnitType u );
69+
LayerConfig( QgsVectorLayer* l, QgsPointLocator::Types t, double tol, QgsTolerance::UnitType u );
7070

7171
QgsVectorLayer* layer;
72-
int type;
72+
QgsPointLocator::Types type;
7373
double tolerance;
7474
QgsTolerance::UnitType unit;
7575
};

src/core/qgspointlocator.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ class CORE_EXPORT QgsPointLocator : public QObject
5757

5858
~QgsPointLocator();
5959

60-
enum Type { Invalid = 0, Vertex = 1, Edge = 2, Area = 4, All = Vertex | Edge | Area };
60+
enum Type
61+
{
62+
Invalid = 0,
63+
Vertex = 1,
64+
Edge = 2,
65+
Area = 4,
66+
All = Vertex | Edge | Area
67+
};
68+
69+
Q_DECLARE_FLAGS( Types, Type )
6170

6271
/** Prepare the index for queries. Does nothing if the index already exists.
6372
* If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped

src/core/qgssnappingutils.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,11 @@ void QgsSnappingUtils::readConfigFromProject()
455455
if ( !vlayer || !vlayer->hasGeometryType() )
456456
continue;
457457

458-
int t = ( *snapIt == "to_vertex" ? QgsPointLocator::Vertex :
459-
( *snapIt == "to_segment" ? QgsPointLocator::Edge :
460-
QgsPointLocator::Vertex | QgsPointLocator::Edge ) );
458+
QgsPointLocator::Types t( *snapIt == "to_vertex" ? QgsPointLocator::Vertex :
459+
( *snapIt == "to_segment" ? QgsPointLocator::Edge :
460+
QgsPointLocator::Vertex | QgsPointLocator::Edge
461+
)
462+
);
461463
mLayers.append( LayerConfig( vlayer, t, tolIt->toDouble(), ( QgsTolerance::UnitType ) tolUnitIt->toInt() ) );
462464
}
463465

src/core/qgssnappingutils.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,20 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
100100
/** Query options used when the mode is snap to current layer */
101101
void defaultSettings( int& type, double& tolerance, QgsTolerance::UnitType& unit );
102102

103+
/**
104+
* Configures how a certain layer should be handled in a snapping operation
105+
*/
103106
struct LayerConfig
104107
{
105-
LayerConfig( QgsVectorLayer* l, int t, double tol, QgsTolerance::UnitType u ) : layer( l ), type( t ), tolerance( tol ), unit( u ) {}
108+
LayerConfig( QgsVectorLayer* l, QgsPointLocator::Types t, double tol, QgsTolerance::UnitType u ) : layer( l ), type( t ), tolerance( tol ), unit( u ) {}
106109

110+
//! The layer to configure.
107111
QgsVectorLayer* layer;
108-
int type;
112+
//! To which geometry properties of this layers a snapping should happen.
113+
QgsPointLocator::Types type;
114+
//! The range around snapping targets in which snapping should occur.
109115
double tolerance;
116+
//! The units in which the tolerance is specified.
110117
QgsTolerance::UnitType unit;
111118
};
112119

0 commit comments

Comments
 (0)