QgsPointLocator::Type : Type safety

This commit is contained in:
Matthias Kuhn 2015-09-26 13:21:56 +02:00
parent dd9b37b4c9
commit 3613ba5701
5 changed files with 28 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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

View File

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