Skip to content

Commit

Permalink
API tidy ups for qgssnapper
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9542 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Oct 24, 2008
1 parent 1fab12a commit adc0124
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 62 deletions.
20 changes: 10 additions & 10 deletions python/core/qgssnapper.sip
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ class QgsSnapper

public:
/**Snap to vertex, to segment or both*/
enum SNAP_TO
enum SnappingType
{
SNAP_TO_VERTEX,
SNAP_TO_SEGMENT,
SnapToVertex,
SnapToSegment,
//snap to vertex and also to segment if no vertex is within the search tolerance
SNAP_TO_VERTEX_AND_SEGMENT
SnapToVertexAndSegment
};

enum SNAP_MODE
enum SnappingMode
{
/**Only one snapping result is retured*/
ONE_RESULT,
SnapWithOneResult,
/**Several snapping results which have the same position are returned. This is usefull for topological
editing*/
SEVERAL_RESULTS_SAME_POSITION,
SnapWithResultsForSamePosition,
/**All results within the given layer tolerances are returned*/
ALL_RESULTS_WITHIN_GIVEN_TOLERANCES
SnapWithResultsWithinTolerances
};

QgsSnapper(QgsMapRenderer* mapRender);
Expand All @@ -68,7 +68,7 @@ public:
//setters
void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);
void setTolerances(const QList<double>& toleranceList);
// TODO wrap void setSnapToList(const QList<QgsSnapper::SNAP_TO>& snapToList);
void setSnapMode(QgsSnapper::SNAP_MODE snapMode);
// TODO wrap void setSnapToList(const QList<QgsSnapper::SnappingType>& snapToList);
void setSnapMode(QgsSnapper::SnappingMode snapMode);

};
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public:
@return 0 in case of success
*/
int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap<double, QgsSnappingResult>& snappingResults /Out/,
QgsSnapper::SNAP_TO snap_to);
QgsSnapper::SnappingType snap_to);

/** Draws the layer using coordinate transformation
* @return FALSE if an error occurred during drawing
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdvertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void QgsMapToolAddVertex::canvasPressEvent( QMouseEvent * e )
mRubberBand = 0;

//snap to segments of the current layer
if ( mSnapper.snapToCurrentLayer( e->pos(), mRecentSnappingResults, QgsSnapper::SNAP_TO_SEGMENT ) != 0 )
if ( mSnapper.snapToCurrentLayer( e->pos(), mRecentSnappingResults, QgsSnapper::SnapToSegment ) != 0 )
{
//error
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooldeletevertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void QgsMapToolDeleteVertex::canvasPressEvent( QMouseEvent * e )

mRecentSnappingResults.clear();
//do snap -> new recent snapping results
if ( mSnapper.snapToCurrentLayer( e->pos(), mRecentSnappingResults, QgsSnapper::SNAP_TO_VERTEX ) != 0 )
if ( mSnapper.snapToCurrentLayer( e->pos(), mRecentSnappingResults, QgsSnapper::SnapToVertex ) != 0 )
{
//error
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolmovevertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void QgsMapToolMoveVertex::canvasPressEvent( QMouseEvent * e )
mRubberBandMovingPoints.clear();

//do snap -> new recent snapping results
if ( mSnapper.snapToCurrentLayer( e->pos(), mRecentSnappingResults, QgsSnapper::SNAP_TO_VERTEX ) != 0 )
if ( mSnapper.snapToCurrentLayer( e->pos(), mRecentSnappingResults, QgsSnapper::SnapToVertex ) != 0 )
{
//error
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgssnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int QgsSnapper::snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& s

QList<QgsVectorLayer*>::iterator layerIt = mLayersToSnap.begin();
QList<double>::const_iterator toleranceIt = mSnappingTolerances.constBegin();
QList<QgsSnapper::SNAP_TO>::const_iterator snapToIt = mSnapToList.constBegin();
QList<QgsSnapper::SnappingType>::const_iterator snapToIt = mSnapToList.constBegin();

QMultiMap<double, QgsSnappingResult> snappingResultList;//all snapping results
QMultiMap<double, QgsSnappingResult> currentResultList; //snapping results of examined layer
Expand Down Expand Up @@ -95,12 +95,12 @@ int QgsSnapper::snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& s
return 0;
}

if ( mSnapMode == QgsSnapper::ONE_RESULT )
if ( mSnapMode == QgsSnapper::SnapWithOneResult )
{
//return only closest result
snappingResult.push_back( evalIt.value() );
}
else if ( mSnapMode == QgsSnapper::SEVERAL_RESULTS_SAME_POSITION )
else if ( mSnapMode == QgsSnapper::SnapWithResultsForSamePosition )
{
//take all snapping Results within a certain tolerance because rounding differences may occur
double tolerance = 0.000001;
Expand Down Expand Up @@ -138,12 +138,12 @@ void QgsSnapper::setTolerances( const QList<double>& toleranceList )
mSnappingTolerances = toleranceList;
}

void QgsSnapper::setSnapToList( const QList<QgsSnapper::SNAP_TO>& snapToList )
void QgsSnapper::setSnapToList( const QList<QgsSnapper::SnappingType>& snapToList )
{
mSnapToList = snapToList;
}

void QgsSnapper::setSnapMode( QgsSnapper::SNAP_MODE snapMode )
void QgsSnapper::setSnapMode( QgsSnapper::SnappingMode snapMode )
{
mSnapMode = snapMode;
}
Expand Down
24 changes: 12 additions & 12 deletions src/core/qgssnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ class CORE_EXPORT QgsSnapper
{
public:
/**Snap to vertex, to segment or both*/
enum SNAP_TO
enum SnappingType
{
SNAP_TO_VERTEX,
SNAP_TO_SEGMENT,
SnapToVertex,
SnapToSegment,
//snap to vertex and also to segment if no vertex is within the search tolerance
SNAP_TO_VERTEX_AND_SEGMENT
SnapToVertexAndSegment
};

enum SNAP_MODE
enum SnappingMode
{
/**Only one snapping result is retured*/
ONE_RESULT,
SnapWithOneResult,
/**Several snapping results which have the same position are returned. This is usefull for topological
editing*/
SEVERAL_RESULTS_SAME_POSITION,
SnapWithResultsForSamePosition,
/**All results within the given layer tolerances are returned*/
ALL_RESULTS_WITHIN_GIVEN_TOLERANCES
SnapWithResultsWithinTolerances
};

QgsSnapper( QgsMapRenderer* mapRender );
Expand All @@ -90,8 +90,8 @@ class CORE_EXPORT QgsSnapper
//setters
void setLayersToSnap( const QList<QgsVectorLayer*>& layerList );
void setTolerances( const QList<double>& toleranceList );
void setSnapToList( const QList<QgsSnapper::SNAP_TO>& snapToList );
void setSnapMode( QgsSnapper::SNAP_MODE snapMode );
void setSnapToList( const QList<QgsSnapper::SnappingType>& snapToList );
void setSnapMode( QgsSnapper::SnappingMode snapMode );

private:
/**Don't use the default constructor*/
Expand All @@ -104,14 +104,14 @@ class CORE_EXPORT QgsSnapper
of the map and about the relationship between pixel space and map space*/
QgsMapRenderer* mMapRenderer;
/**Snap mode to apply*/
QgsSnapper::SNAP_MODE mSnapMode;
QgsSnapper::SnappingMode mSnapMode;
/**The layers to which snapping is applied*/
QList<QgsVectorLayer*> mLayersToSnap;
/**The snapping tolerances for the layers. The order must correspond to the layer list.
Note that the tolerances are always in source coordinate systems of the layers*/
QList<double> mSnappingTolerances;
/**List if snap to segment of to vertex. The order must correspond to the layer list*/
QList<QgsSnapper::SNAP_TO> mSnapToList;
QList<QgsSnapper::SnappingType> mSnapToList;
};

#endif
14 changes: 7 additions & 7 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ int QgsVectorLayer::addTopologicalPoints( const QgsPoint& p )
}


if ( snapWithContext( p, threshold, snapResults, QgsSnapper::SNAP_TO_SEGMENT ) != 0 )
if ( snapWithContext( p, threshold, snapResults, QgsSnapper::SnapToSegment ) != 0 )
{
return 2;
}
Expand All @@ -1939,7 +1939,7 @@ int QgsVectorLayer::addTopologicalPoints( const QgsPoint& p )
{
//test if p is already a vertex of this geometry. If yes, don't insert it
bool vertexAlreadyExists = false;
if ( snapWithContext( p, threshold, vertexSnapResults, QgsSnapper::SNAP_TO_VERTEX ) != 0 )
if ( snapWithContext( p, threshold, vertexSnapResults, QgsSnapper::SnapToVertex ) != 0 )
{
continue;
}
Expand Down Expand Up @@ -3107,7 +3107,7 @@ bool QgsVectorLayer::hasCompatibleSymbology( const QgsMapLayer& other ) const
bool QgsVectorLayer::snapPoint( QgsPoint& point, double tolerance )
{
QMultiMap<double, QgsSnappingResult> snapResults;
int result = snapWithContext( point, tolerance, snapResults, QgsSnapper::SNAP_TO_VERTEX );
int result = snapWithContext( point, tolerance, snapResults, QgsSnapper::SnapToVertex );

if ( result != 0 )
{
Expand All @@ -3128,7 +3128,7 @@ bool QgsVectorLayer::snapPoint( QgsPoint& point, double tolerance )

int QgsVectorLayer::snapWithContext( const QgsPoint& startPoint, double snappingTolerance,
QMultiMap<double, QgsSnappingResult>& snappingResults,
QgsSnapper::SNAP_TO snap_to )
QgsSnapper::SnappingType snap_to )
{
if ( snappingTolerance <= 0 || !mDataProvider )
{
Expand All @@ -3154,7 +3154,7 @@ int QgsVectorLayer::snapWithContext( const QgsPoint& startPoint, double snapping
}

void QgsVectorLayer::snapToGeometry( const QgsPoint& startPoint, int featureId, QgsGeometry* geom, double sqrSnappingTolerance,
QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SNAP_TO snap_to ) const
QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SnappingType snap_to ) const
{
if ( !geom )
{
Expand All @@ -3167,7 +3167,7 @@ void QgsVectorLayer::snapToGeometry( const QgsPoint& startPoint, int featureId,
QgsSnappingResult snappingResultVertex;
QgsSnappingResult snappingResultSegment;

if ( snap_to == QgsSnapper::SNAP_TO_VERTEX || snap_to == QgsSnapper::SNAP_TO_VERTEX_AND_SEGMENT )
if ( snap_to == QgsSnapper::SnapToVertex || snap_to == QgsSnapper::SnapToVertexAndSegment )
{
snappedPoint = geom->closestVertex( startPoint, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
if ( sqrDistVertexSnap < sqrSnappingTolerance )
Expand All @@ -3190,7 +3190,7 @@ void QgsVectorLayer::snapToGeometry( const QgsPoint& startPoint, int featureId,
return;
}
}
if ( snap_to == QgsSnapper::SNAP_TO_SEGMENT || snap_to == QgsSnapper::SNAP_TO_VERTEX_AND_SEGMENT ) // snap to segment
if ( snap_to == QgsSnapper::SnapToSegment || snap_to == QgsSnapper::SnapToVertexAndSegment ) // snap to segment
{
if ( geometryType() != QGis::Point ) // cannot snap to segment for points/multipoints
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
double snappingTolerance,
QMultiMap < double,
QgsSnappingResult > & snappingResults,
QgsSnapper::SNAP_TO snap_to );
QgsSnapper::SnappingType snap_to );

/** Draws the layer
* @return FALSE if an error occurred during drawing
Expand Down Expand Up @@ -534,7 +534,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@param snap_to snap to vertex or to segment
*/
void snapToGeometry( const QgsPoint& startPoint, int featureId, QgsGeometry* geom, double sqrSnappingTolerance,
QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SNAP_TO snap_to ) const;
QMultiMap<double, QgsSnappingResult>& snappingResults, QgsSnapper::SnappingType snap_to ) const;

/**Little helper function that gives bounding box from a list of points.
@return 0 in case of success*/
Expand Down
26 changes: 13 additions & 13 deletions src/gui/qgsmapcanvassnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void QgsMapCanvasSnapper::setMapCanvas( QgsMapCanvas* canvas )
}
}

int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol, const QList<QgsPoint>& excludePoints )
int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SnappingType snap_to, double snappingTol, const QList<QgsPoint>& excludePoints )
{
results.clear();

Expand All @@ -70,11 +70,11 @@ int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingR
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
if ( topologicalEditing == 0 )
{
mSnapper->setSnapMode( QgsSnapper::ONE_RESULT );
mSnapper->setSnapMode( QgsSnapper::SnapWithOneResult );
}
else
{
mSnapper->setSnapMode( QgsSnapper::SEVERAL_RESULTS_SAME_POSITION );
mSnapper->setSnapMode( QgsSnapper::SnapWithResultsForSamePosition );
}

//current vector layer
Expand All @@ -91,7 +91,7 @@ int QgsMapCanvasSnapper::snapToCurrentLayer( const QPoint& p, QList<QgsSnappingR

QList<QgsVectorLayer*> layerList;
QList<double> toleranceList;
QList<QgsSnapper::SNAP_TO> snapToList;
QList<QgsSnapper::SnappingType> snapToList;

layerList.push_back( vlayer );
snapToList.push_back( snap_to );
Expand Down Expand Up @@ -136,11 +136,11 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
if ( topologicalEditing == 0 )
{
mSnapper->setSnapMode( QgsSnapper::ONE_RESULT );
mSnapper->setSnapMode( QgsSnapper::SnapWithOneResult );
}
else
{
mSnapper->setSnapMode( QgsSnapper::SEVERAL_RESULTS_SAME_POSITION );
mSnapper->setSnapMode( QgsSnapper::SnapWithResultsForSamePosition );
}

//read snapping settings from project
Expand All @@ -162,7 +162,7 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp

QList<QgsVectorLayer*> vectorLayerList;
QList<double> toleranceDoubleList;
QList<QgsSnapper::SNAP_TO> snapTo;
QList<QgsSnapper::SnappingType> snapTo;

//Use snapping information from the project
if ( snappingDefinedInProject )
Expand Down Expand Up @@ -200,15 +200,15 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
//segment or vertex
if (( *snapIt ) == "to_vertex" )
{
snapTo.push_back( QgsSnapper::SNAP_TO_VERTEX );
snapTo.push_back( QgsSnapper::SnapToVertex );
}
else if (( *snapIt ) == "to_segment" )
{
snapTo.push_back( QgsSnapper::SNAP_TO_SEGMENT );
snapTo.push_back( QgsSnapper::SnapToSegment );
}
else //to vertex and segment
{
snapTo.push_back( QgsSnapper::SNAP_TO_VERTEX_AND_SEGMENT );
snapTo.push_back( QgsSnapper::SnapToVertexAndSegment );
}

}
Expand All @@ -234,15 +234,15 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
QString defaultSnapString = settings.value( "/qgis/digitizing/default_snap_mode", "to vertex" ).toString();
if ( defaultSnapString == "to segment" )
{
snapTo.push_back( QgsSnapper::SNAP_TO_SEGMENT );
snapTo.push_back( QgsSnapper::SnapToSegment );
}
else if ( defaultSnapString == "to vertex and segment" )
{
snapTo.push_back( QgsSnapper::SNAP_TO_VERTEX_AND_SEGMENT );
snapTo.push_back( QgsSnapper::SnapToVertexAndSegment );
}
else
{
snapTo.push_back( QgsSnapper::SNAP_TO_VERTEX );
snapTo.push_back( QgsSnapper::SnapToVertex );
}

//default snapping tolerance
Expand Down
8 changes: 4 additions & 4 deletions src/gui/qgsmapcanvassnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ class GUI_EXPORT QgsMapCanvasSnapper
~QgsMapCanvasSnapper();

/**Does a snap to the current layer. Uses snap mode
QgsSnapper::SEVERAL_RESULTS_SAME_POSITION if topological editing is enabled
and QgsSnapper::ONE_RESULT_BY_SEGMENT if not. As this method is usually used to
QgsSnapper::SnapWithResultsForSamePosition if topological editing is enabled
and QgsSnapper::SnapWithOneResult_BY_SEGMENT if not. As this method is usually used to
find vertices/segments for editing operations, it uses the search radius for vertex
editing from the qgis options.
@param p start point of the snap (in pixel coordinates)
@param results list to which the results are appended
@param snap_to snap to vertex or to segment
@param snappingTol snapping tolerance. -1 means that the search radius for vertex edits is taken
@param excludePoints a list with (map coordinate) points that should be excluded in the snapping result. Useful e.g. for vertex moves where a vertex should not be snapped to its original position*/
int snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() );
int snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SnappingType snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() );
/**Snaps to the background layers. This method is usefull to align the features of the
edited layers to those of other layers (as described in the project properties).
Uses snap mode QgsSnapper::ONE_RESULT. Therefore, only the
Uses snap mode QgsSnapper::SnapWithOneResult. Therefore, only the
closest result is returned.
@param p start point of the snap (in pixel coordinates)
@param result snapped point
Expand Down
Loading

0 comments on commit adc0124

Please sign in to comment.