29 : mMapSettings( mapRenderer->mapSettings() )
30 , mSnapMode( SnapWithOneResult )
36 : mMapSettings( mapSettings )
37 , mSnapMode( SnapWithOneResult )
46 int QgsSnapper::snapPoint(
const QPoint& startPoint, QList<QgsSnappingResult>& snappingResult,
const QList<QgsPoint>& excludePoints )
49 return snapMapPoint( mapCoordPoint, snappingResult, excludePoints );
54 snappingResult.clear();
56 QMultiMap<double, QgsSnappingResult> snappingResultList;
57 QMultiMap<double, QgsSnappingResult> currentResultList;
64 QList<QgsSnapper::SnapLayer>::iterator snapLayerIt;
65 for ( snapLayerIt = mSnapLayers.begin(); snapLayerIt != mSnapLayers.end(); ++snapLayerIt )
67 if ( !snapLayerIt->mLayer->hasGeometryType() )
70 currentResultList.clear();
75 if ( snapLayerIt->mLayer->snapWithContext( layerCoordPoint, tolerance,
76 currentResultList, snapLayerIt->mSnapTo ) != 0 )
82 QMultiMap<double, QgsSnappingResult>::iterator currentResultIt;
83 for ( currentResultIt = currentResultList.begin(); currentResultIt != currentResultList.end(); ++currentResultIt )
87 newResult = currentResultIt.value();
91 snappingResultList.insert( sqrt( newResult.
snappedVertex.
sqrDist( mapCoordPoint ) ), newResult );
96 cleanResultList( snappingResultList, excludePoints );
99 QMultiMap<double, QgsSnappingResult>::iterator evalIt = snappingResultList.begin();
100 if ( evalIt == snappingResultList.end() )
108 for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
110 if ( evalIt.value().snappedVertexNr != -1 )
112 returnResult = evalIt.value();
113 snappingResultList.erase( evalIt );
119 snappingResult.push_back( returnResult );
128 double tolerance = 0.000001;
130 for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
134 snappingResult.push_back( evalIt.value() );
142 for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
144 snappingResult.push_back( evalIt.value() );
153 mSnapLayers = snapLayers;
159 mSnapMode = snapMode;
162 void QgsSnapper::cleanResultList( QMultiMap<double, QgsSnappingResult>& list,
const QList<QgsPoint>& excludeList )
const
166 QList<double> keysToRemove;
168 QMultiMap<double, QgsSnappingResult>::iterator result_it = list.begin();
169 for ( ; result_it != list.end(); ++result_it )
171 currentSnappingResult = result_it.value();
175 if ( excludeList.contains( currentResultPoint ) )
177 keysToRemove.push_back( result_it.key() );
182 QList<double>::const_iterator remove_it = keysToRemove.constBegin();
183 for ( ; remove_it != keysToRemove.constEnd(); ++remove_it )
185 list.remove( *remove_it );