qgis/QGIS — pull request #1257 by leyan (2014-03-19 15:47:00+00:00)
Title: Snapping priority

This pull request aims to solve http://hub.qgis.org/issues/7058 , which was also mentioned as a problem by Olivier Dalang for CADInput (at the end of https://github.com/olivierdalang/CadInput). The problem is that when a point is on a line, with snapping to segment and vertex, there is currently no way to snap exactly on the point as all the segment is potential snapping position.

The idea is to have snapToBackgroundLayers always return all the potential candidates (I did not understand why the use of QgsSnapper::SnapWithResultsWithinTolerances depended on intersection snapping or topological editing, please tell me if I missed something vital !). Then snapPointFromResults prioritizes a point layer if there is one in the list of results, instead of simply returning the first result as previously.

I had to implement the same logic for the measurement tools, which cannot use snapPointFromResults as they do not inherit QgsMapToolEdit but its base classe QgsMapTool. I think it would make sense to move snapPointFromResults to QgsMapTool.

QgsMaptoolOffsetCurve is a special case as the initial feature should not be snapped, so it has to decide itself which snapping result is needed. I tried to use excludePoints to avoid the initial features, but segments could also be snapped and there is no way to exclude segments of the snapping.

Additionally, I managed to somewhat mess up my git history, I hope the pull request is OK anyway. Otherwise, I will make a clean one.