Skip to content
Permalink
Browse files

QgsPointLocator::Type : Type safety

  • Loading branch information
m-kuhn committed Sep 26, 2015
1 parent dd9b37b commit 3613ba5701a6bd672a5a3edbf19fa0277d9901e8
@@ -16,6 +16,8 @@ class QgsPointLocator : QObject

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

typedef QFlags<QgsPointLocator::Type> 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
@@ -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;
};
@@ -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
@@ -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() ) );
}

@@ -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;
};

0 comments on commit 3613ba5

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