@@ -136,29 +136,29 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
136
136
int topologicalEditing = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /TopologicalEditing" , 0 );
137
137
138
138
// snapping on intersection on?
139
- int intersectionSnapping = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /IntersectionSnapping" , 0 );
139
+ int intersectionSnapping = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /IntersectionSnapping" , 0 );
140
140
141
141
if ( topologicalEditing == 0 )
142
142
{
143
- if ( intersectionSnapping == 0 )
144
- {
145
- mSnapper ->setSnapMode ( QgsSnapper::SnapWithOneResult );
146
- }
147
- else
148
- {
149
- mSnapper ->setSnapMode ( QgsSnapper::SnapWithResultsWithinTolerances );
150
- }
143
+ if ( intersectionSnapping == 0 )
144
+ {
145
+ mSnapper ->setSnapMode ( QgsSnapper::SnapWithOneResult );
146
+ }
147
+ else
148
+ {
149
+ mSnapper ->setSnapMode ( QgsSnapper::SnapWithResultsWithinTolerances );
150
+ }
151
151
}
152
152
else
153
153
{
154
- if ( intersectionSnapping == 0 )
155
- {
156
- mSnapper ->setSnapMode ( QgsSnapper::SnapWithResultsForSamePosition );
157
- }
158
- else
159
- {
160
- mSnapper ->setSnapMode ( QgsSnapper::SnapWithResultsWithinTolerances );
161
- }
154
+ if ( intersectionSnapping == 0 )
155
+ {
156
+ mSnapper ->setSnapMode ( QgsSnapper::SnapWithResultsForSamePosition );
157
+ }
158
+ else
159
+ {
160
+ mSnapper ->setSnapMode ( QgsSnapper::SnapWithResultsWithinTolerances );
161
+ }
162
162
}
163
163
164
164
@@ -279,60 +279,59 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
279
279
return 4 ;
280
280
}
281
281
282
- if ( intersectionSnapping == 1 )
282
+ if ( intersectionSnapping == 1 )
283
283
{
284
284
QList<QgsSnappingResult>::const_iterator it = results.constBegin ();
285
285
QList<QgsSnappingResult> segments;
286
286
QList<QgsSnappingResult> points;
287
287
for ( ; it != results.constEnd (); ++it )
288
288
{
289
- if ( it->snappedVertexNr ==- 1 )
289
+ if ( it->snappedVertexNr == - 1 )
290
290
{
291
- QgsDebugMsg (" segment" );
292
- segments.push_back (*it);
291
+ QgsDebugMsg ( " segment" );
292
+ segments.push_back ( *it );
293
293
}
294
294
else
295
295
{
296
- QgsDebugMsg (" no segment" );
297
- points.push_back (*it);
296
+ QgsDebugMsg ( " no segment" );
297
+ points.push_back ( *it );
298
298
}
299
299
}
300
300
301
- if ( segments.length () >=2 )
301
+ if ( segments.length () >= 2 )
302
302
{
303
303
304
- QgsGeometry* intersectionPoint;
305
304
QList<QgsSnappingResult> myResults;
306
305
307
306
QList<QgsSnappingResult>::const_iterator oSegIt = segments.constBegin ();
308
307
QList<QgsSnappingResult>::iterator iSegIt;
309
- for ( ; oSegIt != segments.constEnd (); ++oSegIt)
308
+ for ( ; oSegIt != segments.constEnd (); ++oSegIt )
310
309
{
311
- QgsDebugMsg ( QString::number (oSegIt->beforeVertexNr ) );
310
+ QgsDebugMsg ( QString::number ( oSegIt->beforeVertexNr ) );
311
+
312
+ QVector<QgsPoint> vertexPoints;
313
+ vertexPoints.append ( oSegIt->beforeVertex );
314
+ vertexPoints.append ( oSegIt->afterVertex );
315
+ QgsGeometry* lineA = QgsGeometry::fromPolyline ( vertexPoints );
312
316
317
+ for ( iSegIt = segments.begin (); iSegIt != segments.end (); ++iSegIt )
318
+ {
313
319
QVector<QgsPoint> vertexPoints;
314
- vertexPoints.append ( oSegIt ->beforeVertex );
315
- vertexPoints.append ( oSegIt ->afterVertex );
316
- QgsGeometry* lineA = QgsGeometry::fromPolyline ( vertexPoints );
320
+ vertexPoints.append ( iSegIt ->beforeVertex );
321
+ vertexPoints.append ( iSegIt ->afterVertex );
322
+ QgsGeometry* lineB = QgsGeometry::fromPolyline ( vertexPoints );
317
323
318
- for ( iSegIt = segments.begin (); iSegIt != segments.end (); ++iSegIt)
324
+ QgsGeometry* intersectionPoint = lineA->intersection ( lineB );
325
+ if ( intersectionPoint->type () == QGis::Point )
319
326
{
320
- QVector<QgsPoint> vertexPoints;
321
- vertexPoints.append ( iSegIt->beforeVertex );
322
- vertexPoints.append ( iSegIt->afterVertex );
323
- QgsGeometry* lineB = QgsGeometry::fromPolyline ( vertexPoints );
324
-
325
- intersectionPoint = lineA->intersection (lineB);
326
- if ( intersectionPoint->type () == QGis::Point)
327
- {
328
- iSegIt->snappedVertex = intersectionPoint->asPoint ();
329
- myResults.append (*iSegIt);
330
- }
327
+ iSegIt->snappedVertex = intersectionPoint->asPoint ();
328
+ myResults.append ( *iSegIt );
331
329
}
330
+ }
332
331
333
332
}
334
333
335
- if ( myResults.length () > 0 )
334
+ if ( myResults.length () > 0 )
336
335
{
337
336
results.clear ();
338
337
results = myResults;
0 commit comments