14
14
***************************************************************************/
15
15
/* $Id$ */
16
16
17
+ #include " qgslogger.h"
17
18
#include " qgsmaptoolvertexedit.h"
18
19
#include " qgsmapcanvas.h"
19
20
#include " qgsmaprender.h"
@@ -49,11 +50,11 @@ void QgsMapToolVertexEdit::canvasMoveEvent(QMouseEvent * e)
49
50
{
50
51
QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas ->currentLayer ());
51
52
if (!vlayer)
52
- {
53
- return ;
54
- }
53
+ {
54
+ return ;
55
+ }
55
56
56
- if (e->buttons () == Qt::LeftButton && (mTool == AddVertex || mTool == MoveVertex))
57
+ if (e->buttons () == Qt::LeftButton && (mTool == AddVertex || mTool == MoveVertex) && mRubberBand )
57
58
{
58
59
// int index = (mStartPointValid ? 1 : 0);
59
60
int index;
@@ -89,75 +90,60 @@ void QgsMapToolVertexEdit::canvasMoveEvent(QMouseEvent * e)
89
90
// transform snapped point back into map coordinates for the rubberband
90
91
QgsPoint mapPoint = toMapCoords (vlayer, layerPoint);
91
92
92
- if (mRubberBand )
93
- {
94
- mRubberBand ->movePoint (index, mapPoint);
95
- }
96
- else
97
- {
98
- #ifdef QGISDEBUG
99
- std::cout << " QgsMapToolVertexEdit::canvasMoveEvent: mRubberBand is empty when it ought not to be!" << std::endl;
100
- #endif
101
- }
102
-
93
+ mRubberBand ->movePoint (index, mapPoint);
103
94
}
104
-
105
95
}
106
96
107
97
108
98
void QgsMapToolVertexEdit::canvasPressEvent (QMouseEvent * e)
109
99
{
110
100
QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas ->currentLayer ());
111
101
if (!vlayer)
112
- {
113
- return ;
114
- }
102
+ {
103
+ return ;
104
+ }
115
105
116
106
QgsPoint layerPoint = toLayerCoords (vlayer, e->pos ());
117
-
107
+
118
108
QgsGeometryVertexIndex index, rb1Index, rb2Index; // rb1Index/rb2Index is for rubberbanding
119
-
109
+
120
110
if (mTool == AddVertex)
121
111
{
122
112
// Find the closest line segment to the mouse position
123
113
// Then set up the rubber band to its endpoints
124
114
125
- #ifdef QGISDEBUG
126
- std::cout << " QgsMapCanvas::mousePressEvent: QGis::AddVertex." << std::endl;
127
- #endif
128
-
129
- // Find nearest segment of the selected line, move that node to the mouse location
130
- if (!snapSegmentWithContext (layerPoint))
131
- {
132
- displaySnapToleranceWarning ();
133
- return ;
134
- }
135
-
136
- index = mSnappedBeforeVertex ;
137
- // Get the endpoint of the snapped-to segment
138
- QgsPoint layerPnt2 = mSnappedAtGeometry .vertexAt (index);
139
-
140
- // Get the startpoint of the snapped-to segment
141
- index.decrement_back ();
142
- QgsPoint layerPnt1 = mSnappedAtGeometry .vertexAt (index);
143
-
144
- createRubberBand ();
145
-
146
- if (layerPnt1 != QgsPoint (0 ,0 ))
147
- {
148
- QgsPoint mapPnt1 = toMapCoords (vlayer, layerPnt1);
149
- mRubberBand ->addPoint (mapPnt1);
150
- }
151
- QgsPoint mapPoint = toMapCoords (vlayer, layerPoint);
152
- mRubberBand ->addPoint (mapPoint);
153
- QgsPoint mapPnt2 = toMapCoords (vlayer, layerPnt2);
154
- mRubberBand ->addPoint (mapPnt2);
115
+ QgsDebugMsg (" QGis::AddVertex." );
116
+
117
+ // Find nearest segment of the selected line, move that node to the mouse location
118
+ if ( !snapSegmentWithContext (layerPoint) )
119
+ {
120
+ displaySnapToleranceWarning ();
121
+ return ;
122
+ }
123
+
124
+ index = mSnappedBeforeVertex ;
125
+ // Get the endpoint of the snapped-to segment
126
+ QgsPoint layerPnt2 = mSnappedAtGeometry .vertexAt (index);
127
+
128
+ // Get the startpoint of the snapped-to segment
129
+ index.decrement_back ();
130
+ QgsPoint layerPnt1 = mSnappedAtGeometry .vertexAt (index);
131
+
132
+ createRubberBand ();
133
+
134
+ if (layerPnt1 != QgsPoint (0 ,0 ))
135
+ {
136
+ QgsPoint mapPnt1 = toMapCoords (vlayer, layerPnt1);
137
+ mRubberBand ->addPoint (mapPnt1);
138
+ }
139
+ QgsPoint mapPoint = toMapCoords (vlayer, layerPoint);
140
+ mRubberBand ->addPoint (mapPoint);
141
+ QgsPoint mapPnt2 = toMapCoords (vlayer, layerPnt2);
142
+ mRubberBand ->addPoint (mapPnt2);
155
143
}
156
144
else if (mTool == MoveVertex)
157
145
{
158
- #ifdef QGISDEBUG
159
- std::cout << " QgsMapCanvas::mousePressEvent: QGis::MoveVertex." << std::endl;
160
- #endif
146
+ QgsDebugMsg (" QGis::MoveVertex." );
161
147
162
148
// Find the closest line segment to the mouse position
163
149
// Then find the closest vertex on that line segment
@@ -167,88 +153,82 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
167
153
168
154
snapPoint = layerPoint;
169
155
if (vlayer->vectorType () == QGis::Point)// snap to point for point/multipoint layers
156
+ {
157
+ if (!snapVertexWithContext (snapPoint))
170
158
{
171
- if (!snapVertexWithContext (snapPoint))
172
- {
173
- displaySnapToleranceWarning ();
174
- return ;
175
- }
159
+ displaySnapToleranceWarning ();
160
+ return ;
176
161
}
162
+ }
177
163
else // snap to segment and take the closest vertex in case of line/multiline/polygon/multipolygon layers
164
+ {
165
+ if (!snapSegmentWithContext (snapPoint))
166
+ {
167
+ displaySnapToleranceWarning ();
168
+ return ;
169
+ }
170
+
171
+ if (!snapVertexOfSnappedSegment (snapPoint))
172
+ {
173
+ QMessageBox::warning (0 , QObject::tr (" Error" ),
174
+ QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ));
175
+ return ;
176
+ }
177
+
178
+ QgsDebugMsg (" Creating rubber band for moveVertex" );
179
+
180
+ index = mSnappedAtVertex ;
181
+ createRubberBand ();
182
+ if (mRubberBandIndex1 != -1 )
178
183
{
179
- if (!snapSegmentWithContext (snapPoint))
180
- {
181
- displaySnapToleranceWarning ();
182
- return ;
183
- }
184
-
185
- if (!snapVertexOfSnappedSegment (snapPoint))
186
- {
187
- QMessageBox::warning (0 , QObject::tr (" Error" ),
188
- QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ));
189
- return ;
190
- }
191
-
192
- #ifdef QGISDEBUG
193
- qWarning (" Creating rubber band for moveVertex" );
194
- #endif
195
-
196
- index = mSnappedAtVertex ;
197
- createRubberBand ();
198
- if (mRubberBandIndex1 != -1 )
199
- {
200
- rb1Index.push_back (mRubberBandIndex1 );
201
- QgsPoint layerPnt1 = mSnappedAtGeometry .vertexAt (rb1Index);
202
- QgsPoint mapPnt1 = toMapCoords (vlayer, layerPnt1);
203
- mRubberBand ->addPoint (mapPnt1);
204
- mStartPointValid = true ;
205
- }
206
- else
207
- {
208
- mStartPointValid = false ;
209
- }
210
- if (mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1 )
211
- {
212
- QgsPoint mapPoint = toMapCoords (vlayer, layerPoint);
213
- mRubberBand ->addPoint (mapPoint);
214
- }
215
- if (mRubberBandIndex2 != -1 )
216
- {
217
- rb2Index.push_back (mRubberBandIndex2 );
218
- QgsPoint layerPnt2 = mSnappedAtGeometry .vertexAt (rb2Index);
219
- QgsPoint mapPnt2 = toMapCoords (vlayer, layerPnt2);
220
- mRubberBand ->addPoint (mapPnt2);
221
- }
222
- #ifdef QGISDEBUG
223
- qWarning (" Creating rubber band for moveVertex" );
224
- #endif
184
+ rb1Index.push_back (mRubberBandIndex1 );
185
+ QgsPoint layerPnt1 = mSnappedAtGeometry .vertexAt (rb1Index);
186
+ QgsPoint mapPnt1 = toMapCoords (vlayer, layerPnt1);
187
+ mRubberBand ->addPoint (mapPnt1);
188
+ mStartPointValid = true ;
225
189
}
190
+ else
191
+ {
192
+ mStartPointValid = false ;
193
+ }
194
+ if (mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1 )
195
+ {
196
+ QgsPoint mapPoint = toMapCoords (vlayer, layerPoint);
197
+ mRubberBand ->addPoint (mapPoint);
198
+ }
199
+ if (mRubberBandIndex2 != -1 )
200
+ {
201
+ rb2Index.push_back (mRubberBandIndex2 );
202
+ QgsPoint layerPnt2 = mSnappedAtGeometry .vertexAt (rb2Index);
203
+ QgsPoint mapPnt2 = toMapCoords (vlayer, layerPnt2);
204
+ mRubberBand ->addPoint (mapPnt2);
205
+ }
206
+ QgsDebugMsg (" Creating rubber band for moveVertex" );
207
+ }
226
208
}
227
209
else if (mTool == DeleteVertex)
228
210
{
229
- #ifdef QGISDEBUG
230
- std::cout << " QgsMapCanvas::mousePressEvent: QGis::DeleteVertex." << std::endl;
231
- #endif
211
+ QgsDebugMsg (" QGis::DeleteVertex." );
232
212
233
213
// TODO: Find nearest node of the selected line, show a big X symbol
234
-
214
+
235
215
// TODO: Find nearest segment of the selected line, move that node to the mouse location
236
216
if (!snapVertexWithContext (layerPoint))
237
- {
238
- QMessageBox::warning (0 , QObject::tr (" Error" ),
239
- QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ));
240
- return ;
241
- }
242
-
217
+ {
218
+ QMessageBox::warning (0 , QObject::tr (" Error" ),
219
+ QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ));
220
+ return ;
221
+ }
222
+
243
223
// Get the point of the snapped-to vertex
244
224
QgsPoint layerPnt = mSnappedAtGeometry .vertexAt (mSnappedAtVertex );
245
225
QgsPoint mapPnt = toMapCoords (vlayer, layerPnt);
246
-
226
+
247
227
mCross = new QgsVertexMarker (mCanvas );
248
228
mCross ->setIconType (QgsVertexMarker::ICON_X);
249
229
mCross ->setCenter (mapPnt);
250
230
}
251
-
231
+
252
232
}
253
233
254
234
double QgsMapToolVertexEdit::tolerance ()
@@ -299,9 +279,7 @@ bool QgsMapToolVertexEdit::snapSegmentWithContext(QgsPoint& point)
299
279
}
300
280
else
301
281
{
302
- #ifdef QGISDEBUG
303
- std::cout << " QgsMapToolVertexEdit::snapSegmentWithContext: Snapped to segment fid " << atFeatureId << " ." << std::endl;
304
- #endif
282
+ QgsDebugMsg (" Snapped to segment fid " + QString::number (atFeatureId) + " ." );
305
283
306
284
// Save where we snapped to
307
285
mSnappedBeforeVertex = beforeVertex;
@@ -333,9 +311,7 @@ bool QgsMapToolVertexEdit::snapVertexWithContext(QgsPoint& point)
333
311
}
334
312
else
335
313
{
336
- #ifdef QGISDEBUG
337
- std::cout << " QgsMapToolVertexEdit: Snapped to segment fid " << atFeatureId << " ." << std::endl;
338
- #endif
314
+ QgsDebugMsg (" Snapped to segment fid " + QString::number (atFeatureId) + " ." );
339
315
340
316
// Save where we snapped to
341
317
mSnappedAtVertex = atVertex;
@@ -354,22 +330,14 @@ bool QgsMapToolVertexEdit::snapVertexOfSnappedSegment(QgsPoint& point)
354
330
QgsGeometryVertexIndex snappedTwoBeforeVertex (mSnappedBeforeVertex );
355
331
snappedTwoBeforeVertex.decrement_back ();
356
332
357
- #ifdef QGISDEBUG
358
- std::cout << " QgsMapToolVertexEdit::snapVertexOfSnappedSegment: Choice of "
359
- << snappedTwoBeforeVertex.toString ().toLocal8Bit ().data () << " or "
360
- << mSnappedBeforeVertex .toString ().toLocal8Bit ().data () << " ." << std::endl;
361
- #endif
362
-
333
+ QgsDebugMsg ( " Choice of " + snappedTwoBeforeVertex.toString ()
334
+ + " or " + mSnappedBeforeVertex .toString () + " ." );
363
335
364
336
twoBeforeVertexSqrDist = mSnappedAtGeometry .sqrDistToVertexAt (point, snappedTwoBeforeVertex);
365
337
beforeVertexSqrDist = mSnappedAtGeometry .sqrDistToVertexAt (point, mSnappedBeforeVertex );
366
338
367
- #ifdef QGISDEBUG
368
- std::cout << " QgsMapToolVertexEdit::snapVertexOfSnappedSegment: Choice of "
369
- << twoBeforeVertexSqrDist << " or "
370
- << beforeVertexSqrDist << " ." << std::endl;
371
- #endif
372
-
339
+ QgsDebugMsg ( " Choice of " + QString::number (twoBeforeVertexSqrDist)
340
+ + " or " + QString::number (beforeVertexSqrDist) + " ." );
373
341
374
342
// See which of the two verticies is closer (i.e. smaller squared distance)
375
343
if (twoBeforeVertexSqrDist < beforeVertexSqrDist)
@@ -381,10 +349,7 @@ bool QgsMapToolVertexEdit::snapVertexOfSnappedSegment(QgsPoint& point)
381
349
mSnappedAtVertex = mSnappedBeforeVertex ;
382
350
}
383
351
384
- #ifdef QGISDEBUG
385
- std::cout << " QgsMapToolVertexEdit::snapVertexOfSnappedSegment: Chose "
386
- << mSnappedAtVertex .toString ().toLocal8Bit ().data () << " ." << std::endl;
387
- #endif
352
+ QgsDebugMsg (" Chose " + mSnappedAtVertex .toString () + " ." );
388
353
389
354
// Now determine the rubber band verticies to use with this snapped vertex
390
355
mSnappedAtGeometry .adjacentVerticies (mSnappedAtVertex , mRubberBandIndex1 , mRubberBandIndex2 );
@@ -396,19 +361,19 @@ void QgsMapToolVertexEdit::snapVertex(QgsPoint& point, int exclFeatureId, int ex
396
361
{
397
362
QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas ->currentLayer ());
398
363
if (vlayer)
364
+ {
365
+ QgsGeometryVertexIndex vIndex;
366
+ int snappedFeatureId;
367
+ int rbPoint1, rbPoint2;
368
+ QgsGeometry snappedGeometry;
369
+ QgsPoint cpyPoint = point;
370
+ vlayer->snapVertexWithContext (cpyPoint, vIndex, rbPoint1, rbPoint2, snappedFeatureId, snappedGeometry, tolerance ());
371
+ if (snappedFeatureId != exclFeatureId || vIndex.back () != exclVertexNr)
399
372
{
400
- QgsGeometryVertexIndex vIndex;
401
- int snappedFeatureId;
402
- int rbPoint1, rbPoint2;
403
- QgsGeometry snappedGeometry;
404
- QgsPoint cpyPoint = point;
405
- vlayer->snapVertexWithContext (cpyPoint, vIndex, rbPoint1, rbPoint2, snappedFeatureId, snappedGeometry, tolerance ());
406
- if (snappedFeatureId != exclFeatureId || vIndex.back () != exclVertexNr)
407
- {
408
- // success, assign snapped coordinates to point
409
- point = cpyPoint;
410
- }
373
+ // success, assign snapped coordinates to point
374
+ point = cpyPoint;
411
375
}
376
+ }
412
377
}
413
378
414
379
@@ -450,9 +415,7 @@ void QgsMapToolVertexEdit::canvasReleaseEvent(QMouseEvent * e)
450
415
// snap to nearest vertex of vectorlayer
451
416
snapVertex (layerPoint, mSnappedAtFeatureId , mSnappedBeforeVertex .back ());
452
417
453
- #ifdef QGISDEBUG
454
- std::cout << " QgsMapToolVertexEdit::canvasReleaseEvent: AddVertex." << std::endl;
455
- #endif
418
+ QgsDebugMsg (" AddVertex." );
456
419
457
420
deleteRubberBand ();
458
421
@@ -464,9 +427,8 @@ void QgsMapToolVertexEdit::canvasReleaseEvent(QMouseEvent * e)
464
427
{
465
428
// snap to nearest vertex of vectorlayer
466
429
snapVertex (layerPoint, mSnappedAtFeatureId , mSnappedAtVertex .back ());
467
- #ifdef QGISDEBUG
468
- std::cout << " QgsMapToolVertexEdit::canvasReleaseEvent: MoveVertex." << std::endl;
469
- #endif
430
+
431
+ QgsDebugMsg (" MoveVertex." );
470
432
471
433
delete mRubberBand ;
472
434
mRubberBand = 0 ;
@@ -475,9 +437,7 @@ void QgsMapToolVertexEdit::canvasReleaseEvent(QMouseEvent * e)
475
437
}
476
438
else if (mTool == DeleteVertex)
477
439
{
478
- #ifdef QGISDEBUG
479
- std::cout << " QgsMapToolVertexEdit::canvasReleaseEvent: DeleteVertex." << std::endl;
480
- #endif
440
+ QgsDebugMsg (" DeleteVertex." );
481
441
482
442
delete mCross ;
483
443
mCross = 0 ;
0 commit comments