mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Fix for bug #1096 Snapping to currently moved vertex should be suppressed
git-svn-id: http://svn.osgeo.org/qgis/trunk@8477 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
61e3fe93a3
commit
b849af0745
@ -63,7 +63,7 @@ public:
|
|||||||
@param startPoint the start point for snapping (in pixel coordinates)
|
@param startPoint the start point for snapping (in pixel coordinates)
|
||||||
@param snappingResult the list where the results are inserted (everything in map coordinate system)
|
@param snappingResult the list where the results are inserted (everything in map coordinate system)
|
||||||
@return 0 in case of success*/
|
@return 0 in case of success*/
|
||||||
int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult);
|
int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludeList);
|
||||||
|
|
||||||
//setters
|
//setters
|
||||||
void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);
|
void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);
|
||||||
|
@ -34,6 +34,11 @@ QgsMapToolMoveVertex::~QgsMapToolMoveVertex()
|
|||||||
|
|
||||||
void QgsMapToolMoveVertex::canvasMoveEvent(QMouseEvent * e)
|
void QgsMapToolMoveVertex::canvasMoveEvent(QMouseEvent * e)
|
||||||
{
|
{
|
||||||
|
if(mRecentSnappingResults.size() < 1)
|
||||||
|
{
|
||||||
|
return ; //snapping not necessary
|
||||||
|
}
|
||||||
|
|
||||||
//list of rubber bands, snapping results and point index to move
|
//list of rubber bands, snapping results and point index to move
|
||||||
//must have equal size
|
//must have equal size
|
||||||
int rbSize = mRubberBands.size();
|
int rbSize = mRubberBands.size();
|
||||||
@ -51,7 +56,8 @@ void QgsMapToolMoveVertex::canvasMoveEvent(QMouseEvent * e)
|
|||||||
QList<QgsRubberBand*>::iterator rb_it = mRubberBands.begin();
|
QList<QgsRubberBand*>::iterator rb_it = mRubberBands.begin();
|
||||||
|
|
||||||
QList<QgsSnappingResult> snapResults;
|
QList<QgsSnappingResult> snapResults;
|
||||||
if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults) != 0)
|
|
||||||
|
if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults, mExcludePoint) != 0)
|
||||||
{
|
{
|
||||||
return; //error, bail out
|
return; //error, bail out
|
||||||
}
|
}
|
||||||
@ -119,7 +125,10 @@ void QgsMapToolMoveVertex::canvasPressEvent(QMouseEvent * e)
|
|||||||
mRubberBands.push_back(rb);
|
mRubberBands.push_back(rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
//create rubber band list for snapping results
|
if(mRecentSnappingResults.size() > 0)
|
||||||
|
{
|
||||||
|
mExcludePoint.push_back(mRecentSnappingResults.first().snappedVertex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolMoveVertex::canvasReleaseEvent(QMouseEvent * e)
|
void QgsMapToolMoveVertex::canvasReleaseEvent(QMouseEvent * e)
|
||||||
@ -138,7 +147,7 @@ void QgsMapToolMoveVertex::canvasReleaseEvent(QMouseEvent * e)
|
|||||||
QgsPoint snappedPointLayerCoord;
|
QgsPoint snappedPointLayerCoord;
|
||||||
QList<QgsSnappingResult> snapResults;
|
QList<QgsSnappingResult> snapResults;
|
||||||
|
|
||||||
if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults) != 0)
|
if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults, mExcludePoint) != 0)
|
||||||
{
|
{
|
||||||
//error
|
//error
|
||||||
}
|
}
|
||||||
@ -171,6 +180,7 @@ void QgsMapToolMoveVertex::canvasReleaseEvent(QMouseEvent * e)
|
|||||||
|
|
||||||
mRecentSnappingResults.clear();
|
mRecentSnappingResults.clear();
|
||||||
mRubberBandMovingPoints.clear();
|
mRubberBandMovingPoints.clear();
|
||||||
|
mExcludePoint.clear();
|
||||||
|
|
||||||
mCanvas->refresh();
|
mCanvas->refresh();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,9 @@ class QgsMapToolMoveVertex: public QgsMapToolVertexEdit
|
|||||||
that no point should be moved*/
|
that no point should be moved*/
|
||||||
QList<int> mRubberBandMovingPoints;
|
QList<int> mRubberBandMovingPoints;
|
||||||
|
|
||||||
|
/**The position of the vertex to move (in map coordinates) to exclude later from snapping*/
|
||||||
|
QList<QgsPoint> mExcludePoint;
|
||||||
|
|
||||||
/**Deletes the rubber band pointers
|
/**Deletes the rubber band pointers
|
||||||
and clears mRubberBands*/
|
and clears mRubberBands*/
|
||||||
void removeRubberBands();
|
void removeRubberBands();
|
||||||
|
@ -39,7 +39,7 @@ QgsSnapper::~QgsSnapper()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsSnapper::snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult)
|
int QgsSnapper::snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints)
|
||||||
{
|
{
|
||||||
snappingResult.clear();
|
snappingResult.clear();
|
||||||
|
|
||||||
@ -85,6 +85,9 @@ int QgsSnapper::snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& sn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//excluded specific points from result
|
||||||
|
cleanResultList(snappingResultList, excludePoints);
|
||||||
|
|
||||||
//evaluate results according to snap mode
|
//evaluate results according to snap mode
|
||||||
QMultiMap<double, QgsSnappingResult>::iterator evalIt = snappingResultList.begin();
|
QMultiMap<double, QgsSnappingResult>::iterator evalIt = snappingResultList.begin();
|
||||||
if(evalIt == snappingResultList.end())
|
if(evalIt == snappingResultList.end())
|
||||||
@ -137,3 +140,30 @@ void QgsSnapper::setSnapMode(QgsSnapper::SNAP_MODE snapMode)
|
|||||||
{
|
{
|
||||||
mSnapMode = snapMode;
|
mSnapMode = snapMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsSnapper::cleanResultList(QMultiMap<double, QgsSnappingResult>& list, const QList<QgsPoint>& excludeList) const
|
||||||
|
{
|
||||||
|
QgsPoint currentResultPoint;
|
||||||
|
QgsSnappingResult currentSnappingResult;
|
||||||
|
QList<double> keysToRemove;
|
||||||
|
|
||||||
|
QMultiMap<double, QgsSnappingResult>::iterator result_it = list.begin();
|
||||||
|
for(; result_it != list.end(); ++result_it)
|
||||||
|
{
|
||||||
|
currentSnappingResult = result_it.value();
|
||||||
|
if(currentSnappingResult.snappedVertexNr != -1)
|
||||||
|
{
|
||||||
|
currentResultPoint = currentSnappingResult.snappedVertex;
|
||||||
|
if(excludeList.contains(currentResultPoint))
|
||||||
|
{
|
||||||
|
keysToRemove.push_back(result_it.key());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<double>::const_iterator remove_it = keysToRemove.constBegin();
|
||||||
|
for(; remove_it != keysToRemove.constEnd(); ++remove_it)
|
||||||
|
{
|
||||||
|
list.remove(*remove_it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -81,8 +81,9 @@ class CORE_EXPORT QgsSnapper
|
|||||||
/**Does the snapping operation
|
/**Does the snapping operation
|
||||||
@param startPoint the start point for snapping (in pixel coordinates)
|
@param startPoint the start point for snapping (in pixel coordinates)
|
||||||
@param snappingResult the list where the results are inserted (everything in map coordinate system)
|
@param snappingResult the list where the results are inserted (everything in map coordinate system)
|
||||||
|
@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
|
||||||
@return 0 in case of success*/
|
@return 0 in case of success*/
|
||||||
int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult);
|
int snapPoint(const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints = QList<QgsPoint>());
|
||||||
|
|
||||||
//setters
|
//setters
|
||||||
void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);
|
void setLayersToSnap(const QList<QgsVectorLayer*>& layerList);
|
||||||
@ -93,6 +94,10 @@ class CORE_EXPORT QgsSnapper
|
|||||||
private:
|
private:
|
||||||
/**Don't use the default constructor*/
|
/**Don't use the default constructor*/
|
||||||
QgsSnapper();
|
QgsSnapper();
|
||||||
|
|
||||||
|
/**Removes the snapping results that contains points in exclude list*/
|
||||||
|
void cleanResultList(QMultiMap<double, QgsSnappingResult>& list, const QList<QgsPoint>& excludeList) const;
|
||||||
|
|
||||||
/**The maprender object contains information about the output coordinate system
|
/**The maprender object contains information about the output coordinate system
|
||||||
of the map and about the relationship between pixel space and map space*/
|
of the map and about the relationship between pixel space and map space*/
|
||||||
QgsMapRender* mMapRender;
|
QgsMapRender* mMapRender;
|
||||||
|
@ -58,7 +58,7 @@ void QgsMapCanvasSnapper::setMapCanvas(QgsMapCanvas* canvas)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsMapCanvasSnapper::snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol)
|
int QgsMapCanvasSnapper::snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol, const QList<QgsPoint>& excludePoints)
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ int QgsMapCanvasSnapper::snapToCurrentLayer(const QPoint& p, QList<QgsSnappingRe
|
|||||||
mSnapper->setTolerances(toleranceList);
|
mSnapper->setTolerances(toleranceList);
|
||||||
mSnapper->setSnapToList(snapToList);
|
mSnapper->setSnapToList(snapToList);
|
||||||
|
|
||||||
if(mSnapper->snapPoint(p, results) != 0)
|
if(mSnapper->snapPoint(p, results, excludePoints) != 0)
|
||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ int QgsMapCanvasSnapper::snapToCurrentLayer(const QPoint& p, QList<QgsSnappingRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsMapCanvasSnapper::snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results)
|
int QgsMapCanvasSnapper::snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results, const QList<QgsPoint>& excludePoints)
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers(const QPoint& p, QList<QgsSnappi
|
|||||||
mSnapper->setTolerances(toleranceDoubleList);
|
mSnapper->setTolerances(toleranceDoubleList);
|
||||||
mSnapper->setSnapToList(snapTo);
|
mSnapper->setSnapToList(snapTo);
|
||||||
|
|
||||||
if(mSnapper->snapPoint(p, results) != 0)
|
if(mSnapper->snapPoint(p, results, excludePoints) != 0)
|
||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
@ -48,16 +48,18 @@ class GUI_EXPORT QgsMapCanvasSnapper
|
|||||||
@param p start point of the snap (in pixel coordinates)
|
@param p start point of the snap (in pixel coordinates)
|
||||||
@param results list to which the results are appended
|
@param results list to which the results are appended
|
||||||
@param snap_to snap to vertex or to segment
|
@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 snappingTol snapping tolerance. -1 means that the search radius for vertex edits is taken
|
||||||
int snapToCurrentLayer(const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SNAP_TO snap_to, double snappingTol = -1);
|
@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>());
|
||||||
/**Snaps to the background layers. This method is usefull to align the features of the
|
/**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).
|
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::ONE_RESULT. Therefore, only the
|
||||||
closest result is returned.
|
closest result is returned.
|
||||||
@param p start point of the snap (in pixel coordinates)
|
@param p start point of the snap (in pixel coordinates)
|
||||||
@param result snapped point
|
@param result snapped point
|
||||||
|
@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
|
||||||
@return 0 in case of success*/
|
@return 0 in case of success*/
|
||||||
int snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results);
|
int snapToBackgroundLayers(const QPoint& p, QList<QgsSnappingResult>& results, const QList<QgsPoint>& excludePoints = QList<QgsPoint>());
|
||||||
|
|
||||||
void setMapCanvas(QgsMapCanvas* canvas);
|
void setMapCanvas(QgsMapCanvas* canvas);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user