Skip to content

Commit

Permalink
QgsPointLocator::Type : Type safety
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 26, 2015
1 parent dd9b37b commit 3613ba5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions python/core/qgspointlocator.sip
Expand Up @@ -16,6 +16,8 @@ class QgsPointLocator : QObject


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


typedef QFlags<QgsPointLocator::Type> Types;

/** Prepare the index for queries. Does nothing if the index already exists. /** 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 * 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 * to make sure we do not run out of memory. If maxFeaturesToIndex is -1, no limits are used. Returns
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgssnappingutils.sip
Expand Up @@ -66,10 +66,10 @@ class QgsSnappingUtils : QObject


struct LayerConfig 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; QgsVectorLayer* layer;
int type; QgsPointLocator::Types type;
double tolerance; double tolerance;
QgsTolerance::UnitType unit; QgsTolerance::UnitType unit;
}; };
Expand Down
11 changes: 10 additions & 1 deletion src/core/qgspointlocator.h
Expand Up @@ -57,7 +57,16 @@ class CORE_EXPORT QgsPointLocator : public QObject


~QgsPointLocator(); ~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. /** 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 * If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped
Expand Down
8 changes: 5 additions & 3 deletions src/core/qgssnappingutils.cpp
Expand Up @@ -455,9 +455,11 @@ void QgsSnappingUtils::readConfigFromProject()
if ( !vlayer || !vlayer->hasGeometryType() ) if ( !vlayer || !vlayer->hasGeometryType() )
continue; continue;


int t = ( *snapIt == "to_vertex" ? QgsPointLocator::Vertex : QgsPointLocator::Types t( *snapIt == "to_vertex" ? QgsPointLocator::Vertex :
( *snapIt == "to_segment" ? QgsPointLocator::Edge : ( *snapIt == "to_segment" ? QgsPointLocator::Edge :
QgsPointLocator::Vertex | QgsPointLocator::Edge ) ); QgsPointLocator::Vertex | QgsPointLocator::Edge
)
);
mLayers.append( LayerConfig( vlayer, t, tolIt->toDouble(), ( QgsTolerance::UnitType ) tolUnitIt->toInt() ) ); mLayers.append( LayerConfig( vlayer, t, tolIt->toDouble(), ( QgsTolerance::UnitType ) tolUnitIt->toInt() ) );
} }


Expand Down
11 changes: 9 additions & 2 deletions src/core/qgssnappingutils.h
Expand Up @@ -100,13 +100,20 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
/** Query options used when the mode is snap to current layer */ /** Query options used when the mode is snap to current layer */
void defaultSettings( int& type, double& tolerance, QgsTolerance::UnitType& unit ); void defaultSettings( int& type, double& tolerance, QgsTolerance::UnitType& unit );


/**
* Configures how a certain layer should be handled in a snapping operation
*/
struct LayerConfig 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; 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; double tolerance;
//! The units in which the tolerance is specified.
QgsTolerance::UnitType unit; QgsTolerance::UnitType unit;
}; };


Expand Down

0 comments on commit 3613ba5

Please sign in to comment.