@@ -101,8 +101,9 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
101
101
// Find nearest segment of the selected line, move that node to the mouse location
102
102
if (!snapSegmentWithContext (point))
103
103
{
104
- QMessageBox::warning (0 , " Error" , " Could not snap vertex. Have you set the tolerance?" ,
105
- QMessageBox::Ok, Qt::NoButton);
104
+ QMessageBox::warning (0 , " Error" ,
105
+ QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
106
+ QMessageBox::Ok, Qt::NoButton);
106
107
return ;
107
108
}
108
109
@@ -130,15 +131,32 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
130
131
#endif
131
132
132
133
// Find the closest line segment to the mouse position
133
- // Then set up the rubber band to its endpoints
134
+ // Then find the closest vertex on that line segment
135
+ // Then set up the rubber band to its adjoining vertexes
134
136
135
- // Find nearest segment of the selected line, move that node to the mouse location
136
- if (!snapVertexWithContext (point))
137
- {
138
- QMessageBox::warning (0 , " Error" , " Could not snap vertex. Have you set the tolerance?" ,
139
- QMessageBox::Ok, Qt::NoButton);
140
- return ;
141
- }
137
+ QgsPoint snapPoint;
138
+
139
+ snapPoint = point;
140
+ if (!snapSegmentWithContext (snapPoint))
141
+ {
142
+ QMessageBox::warning (0 , " Error" ,
143
+ QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
144
+ QMessageBox::Ok, Qt::NoButton);
145
+ return ;
146
+ }
147
+
148
+ snapPoint = point;
149
+ if (!snapVertexOfSnappedSegment (snapPoint))
150
+ {
151
+ QMessageBox::warning (0 , " Error" ,
152
+ QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ),
153
+ QMessageBox::Ok, Qt::NoButton);
154
+ return ;
155
+ }
156
+
157
+ #ifdef QGISDEBUG
158
+ qWarning (" Creating rubber band for moveVertex" );
159
+ #endif
142
160
143
161
index = mSnappedAtVertex ;
144
162
createRubberBand ();
@@ -178,8 +196,9 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
178
196
// TODO: Find nearest segment of the selected line, move that node to the mouse location
179
197
if (!snapVertexWithContext (point))
180
198
{
181
- QMessageBox::warning (0 , " Error" , " Could not snap vertex. Have you set the tolerance?" ,
182
- QMessageBox::Ok, Qt::NoButton);
199
+ QMessageBox::warning (0 , " Error" ,
200
+ QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ),
201
+ QMessageBox::Ok, Qt::NoButton);
183
202
return ;
184
203
}
185
204
@@ -216,14 +235,15 @@ bool QgsMapToolVertexEdit::snapSegmentWithContext(QgsPoint& point)
216
235
if (!vlayer->snapSegmentWithContext (point, beforeVertex, atFeatureId, atGeometry, tolerance ()))
217
236
{
218
237
mSnappedAtFeatureId = -1 ;
219
- QMessageBox::warning (0 , " Error" , " Could not snap segment. Have you set the tolerance?" ,
220
- QMessageBox::Ok, Qt::NoButton);
238
+ QMessageBox::warning (0 , " Error" ,
239
+ QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
240
+ QMessageBox::Ok, Qt::NoButton);
221
241
return FALSE ;
222
242
}
223
243
else
224
244
{
225
245
#ifdef QGISDEBUG
226
- std::cout << " QgsMapToolVertexEdit: Snapped to segment fid " << atFeatureId << " ." << std::endl;
246
+ std::cout << " QgsMapToolVertexEdit::snapSegmentWithContext: Snapped to segment fid " << atFeatureId << " ." << std::endl;
227
247
#endif
228
248
229
249
// Save where we snapped to
@@ -266,6 +286,50 @@ bool QgsMapToolVertexEdit::snapVertexWithContext(QgsPoint& point)
266
286
}
267
287
}
268
288
289
+ bool QgsMapToolVertexEdit::snapVertexOfSnappedSegment (QgsPoint& point)
290
+ {
291
+ double twoBeforeVertexSqrDist;
292
+ double beforeVertexSqrDist;
293
+
294
+ // Set up the "other side" of the snapped-to segment
295
+ QgsGeometryVertexIndex snappedTwoBeforeVertex (mSnappedBeforeVertex );
296
+ snappedTwoBeforeVertex.decrement_back ();
297
+
298
+ #ifdef QGISDEBUG
299
+ std::cout << " QgsMapToolVertexEdit::snapVertexOfSnappedSegment: Choice of "
300
+ << snappedTwoBeforeVertex.toString ().toLocal8Bit ().data () << " or "
301
+ << mSnappedBeforeVertex .toString ().toLocal8Bit ().data () << " ." << std::endl;
302
+ #endif
303
+
304
+
305
+ twoBeforeVertexSqrDist = mSnappedAtGeometry .sqrDistToVertexAt (point, snappedTwoBeforeVertex);
306
+ beforeVertexSqrDist = mSnappedAtGeometry .sqrDistToVertexAt (point, mSnappedBeforeVertex );
307
+
308
+ #ifdef QGISDEBUG
309
+ std::cout << " QgsMapToolVertexEdit::snapVertexOfSnappedSegment: Choice of "
310
+ << twoBeforeVertexSqrDist << " or "
311
+ << beforeVertexSqrDist << " ." << std::endl;
312
+ #endif
313
+
314
+
315
+ // See which of the two verticies is closer (i.e. smaller squared distance)
316
+ if (twoBeforeVertexSqrDist < beforeVertexSqrDist)
317
+ {
318
+ mSnappedAtVertex = snappedTwoBeforeVertex;
319
+ }
320
+ else
321
+ {
322
+ mSnappedAtVertex = mSnappedBeforeVertex ;
323
+ }
324
+
325
+ #ifdef QGISDEBUG
326
+ std::cout << " QgsMapToolVertexEdit::snapVertexOfSnappedSegment: Chose "
327
+ << mSnappedAtVertex .toString ().toLocal8Bit ().data () << " ." << std::endl;
328
+ #endif
329
+
330
+ return TRUE ;
331
+ }
332
+
269
333
bool QgsMapToolVertexEdit::snapVertex (QgsPoint& point, int exclFeatureId, int exclVertexNr)
270
334
{
271
335
QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas ->currentLayer ());
0 commit comments