@@ -34,8 +34,9 @@ QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas )
34
34
, mClicked( false )
35
35
, mCtrl( false )
36
36
, mSelectAnother( false )
37
- , mRubberBand ( 0 )
37
+ , mSelectionRubberBand ( 0 )
38
38
, mIsPoint( false )
39
+ , mDeselectOnRelease( -1 )
39
40
{
40
41
}
41
42
@@ -221,17 +222,18 @@ void QgsMapToolNodeTool::createTopologyRubberBands( QgsVectorLayer* vlayer, cons
221
222
222
223
void QgsMapToolNodeTool::canvasMoveEvent ( QMouseEvent * e )
223
224
{
224
- QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
225
- if ( !mSelectedFeature || !vlayer || !mClicked )
225
+ if ( !mSelectedFeature || !mClicked )
226
226
return ;
227
227
228
+ QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
228
229
if ( !vlayer )
229
230
return ;
230
231
231
232
mSelectAnother = false ;
233
+
232
234
if ( mMoving )
233
235
{
234
- // create rubberband if none exists
236
+ // create rubberband, if none exists
235
237
if ( mRubberBands .empty () )
236
238
{
237
239
if ( mIsPoint )
@@ -255,18 +257,19 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
255
257
{
256
258
// move rubberband
257
259
QList<QgsSnappingResult> snapResults;
258
- QgsPoint firstCoords = mCanvas -> getCoordinateTransform ()-> toMapPoint ( mLastCoordinates -> x (), mLastCoordinates -> y () );
260
+ QgsPoint firstCoords = toMapCoordinates ( mPressCoordinates );
259
261
QList<QgsPoint> excludePoints;
260
262
excludePoints.append ( mClosestVertex );
261
263
mSnapper .snapToBackgroundLayers ( e->pos (), snapResults, excludePoints );
262
- // get correct coordinates to move
264
+
265
+ // get correct coordinates to move to
263
266
QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
264
267
if ( snapResults.size () > 0 )
265
268
{
266
269
firstCoords = toMapCoordinates ( vlayer, mClosestVertex );
267
270
}
268
271
269
- // special handling of points
272
+ // handle points
270
273
if ( mIsPoint )
271
274
{
272
275
double offsetX = posMapCoord.x () - firstCoords.x ();
@@ -290,6 +293,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
290
293
double y = mapCoords.y () + posMapCoord.y () - firstCoords.y ();
291
294
292
295
mRubberBands [vertexMap[i]->rubberBandNr ()]->movePoint ( vertexMap[i]->rubberBandIndex (), QgsPoint ( x, y ) );
296
+
293
297
if ( vertexMap[i]->rubberBandIndex () == 0 )
294
298
{
295
299
mRubberBands [vertexMap[i]->rubberBandNr ()]->movePoint ( 0 , QgsPoint ( x, y ) );
@@ -319,6 +323,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
319
323
}
320
324
}
321
325
}
326
+
322
327
mPosMapCoordBackup = posMapCoord;
323
328
}
324
329
}
@@ -327,24 +332,25 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
327
332
if ( !mSelectionRectangle )
328
333
{
329
334
mSelectionRectangle = true ;
330
- mRubberBand = new QRubberBand ( QRubberBand::Rectangle, mCanvas );
335
+ mSelectionRubberBand = new QRubberBand ( QRubberBand::Rectangle, mCanvas );
331
336
mRect = new QRect ();
332
- mRect ->setTopLeft ( QPoint ( mLastCoordinates -> x (), mLastCoordinates -> y () ) );
337
+ mRect ->setTopLeft ( mPressCoordinates );
333
338
}
334
339
mRect ->setBottomRight ( e->pos () );
335
340
QRect normalizedRect = mRect ->normalized ();
336
- mRubberBand ->setGeometry ( normalizedRect );
337
- mRubberBand ->show ();
341
+ mSelectionRubberBand ->setGeometry ( normalizedRect );
342
+ mSelectionRubberBand ->show ();
338
343
}
339
344
}
340
345
341
346
void QgsMapToolNodeTool::canvasPressEvent ( QMouseEvent * e )
342
347
{
343
348
QgsDebugMsg ( " Entering." );
344
- QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
349
+
350
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
345
351
346
352
mClicked = true ;
347
- mLastCoordinates = new QgsPoint ( e->pos (). x (), e-> pos (). y () );
353
+ mPressCoordinates = e->pos ();
348
354
QList<QgsSnappingResult> snapResults;
349
355
if ( !mSelectedFeature )
350
356
{
@@ -364,7 +370,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
364
370
else
365
371
{
366
372
// some feature already selected
367
- QgsPoint mapCoordPoint = mCanvas -> getCoordinateTransform ()-> toMapPoint ( e->pos (). x (), e-> pos (). y () );
373
+ QgsPoint mapCoordPoint = toMapCoordinates ( e->pos () );
368
374
double tol = QgsTolerance::vertexSearchRadius ( vlayer, mCanvas ->mapRenderer () );
369
375
370
376
// get geometry and find if snapping is near it
@@ -374,15 +380,45 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
374
380
dist = sqrt ( dist );
375
381
376
382
mSnapper .snapToCurrentLayer ( e->pos (), snapResults, QgsSnapper::SnapToVertex, tol );
377
- if ( dist > tol )
383
+ if ( dist <= tol )
384
+ {
385
+ // some vertex selected
386
+ mMoving = true ;
387
+ QgsPoint point = toMapCoordinates ( e->pos () );
388
+ mClosestVertex = closestVertex ( toLayerCoordinates ( vlayer, point ) );
389
+ if ( mMoving )
390
+ {
391
+ if ( mSelectedFeature ->isSelected ( atVertex ) )
392
+ {
393
+ mDeselectOnRelease = atVertex;
394
+ }
395
+ else if ( mCtrl )
396
+ {
397
+ mSelectedFeature ->invertVertexSelection ( atVertex );
398
+ }
399
+ else
400
+ {
401
+ mSelectedFeature ->deselectAllVertexes ();
402
+ mSelectedFeature ->selectVertex ( atVertex );
403
+ }
404
+ }
405
+ else
406
+ {
407
+ // select another feature
408
+ mAnother = snapResults.first ().snappedAtGeometry ;
409
+ mSelectAnother = true ;
410
+ }
411
+ }
412
+ else
378
413
{
379
- // for points only selecting another feature
380
- // no vertexes found (selecting or inverting selection) if move
381
- // or select another feature if clicked there
382
- mSnapper .snapToCurrentLayer ( e->pos (), snapResults, mIsPoint ? QgsSnapper::SnapToVertex : QgsSnapper::SnapToSegment, tol );
414
+ // no near vertex to snap
415
+ // unless point layer, try segment
416
+ if ( !mIsPoint )
417
+ mSnapper .snapToCurrentLayer ( e->pos (), snapResults, QgsSnapper::SnapToSegment, tol );
418
+
383
419
if ( snapResults.size () > 0 )
384
420
{
385
- // need to check all if there is a point in my selected feature
421
+ // need to check all if there is a point in the feature
386
422
mAnother = snapResults.first ().snappedAtGeometry ;
387
423
mSelectAnother = true ;
388
424
QList<QgsSnappingResult>::iterator it = snapResults.begin ();
@@ -401,7 +437,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
401
437
if ( !mSelectAnother )
402
438
{
403
439
mMoving = true ;
404
- QgsPoint point = mCanvas -> getCoordinateTransform ()-> toMapPoint ( e->pos (). x (), e-> pos (). y () );
440
+ QgsPoint point = toMapCoordinates ( e->pos () );
405
441
mClosestVertex = closestVertex ( toLayerCoordinates ( vlayer, point ) );
406
442
407
443
if ( mIsPoint )
@@ -416,8 +452,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
416
452
mSelectedFeature ->invertVertexSelection ( snapResult.snappedVertexNr );
417
453
}
418
454
}
419
- else if ( !mSelectedFeature ->isSelected ( snapResult.beforeVertexNr ) ||
420
- !mSelectedFeature ->isSelected ( snapResult.afterVertexNr ) )
455
+ else
421
456
{
422
457
if ( !mCtrl )
423
458
{
@@ -438,31 +473,6 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
438
473
mSelectedFeature ->deselectAllVertexes ();
439
474
}
440
475
}
441
- else
442
- {
443
- // some vertex selected
444
- mMoving = true ;
445
- QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint ( e->pos ().x (), e->pos ().y () );
446
- mClosestVertex = closestVertex ( toLayerCoordinates ( vlayer, point ) );
447
- if ( mMoving )
448
- {
449
- if ( mCtrl )
450
- {
451
- mSelectedFeature ->invertVertexSelection ( atVertex );
452
- }
453
- else
454
- {
455
- mSelectedFeature ->deselectAllVertexes ();
456
- mSelectedFeature ->selectVertex ( atVertex );
457
- }
458
- }
459
- else
460
- {
461
- // select another feature
462
- mAnother = snapResults.first ().snappedAtGeometry ;
463
- mSelectAnother = true ;
464
- }
465
- }
466
476
}
467
477
QgsDebugMsg ( " Leaving." );
468
478
}
@@ -476,109 +486,77 @@ void QgsMapToolNodeTool::selectedFeatureDestroyed()
476
486
void QgsMapToolNodeTool::canvasReleaseEvent ( QMouseEvent * e )
477
487
{
478
488
if ( !mSelectedFeature )
479
- {
480
- // no feature is selected
481
489
return ;
482
- }
483
490
484
491
removeRubberBands ();
485
492
486
493
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
487
494
488
495
mClicked = false ;
489
496
mSelectionRectangle = false ;
490
- QgsPoint coords = toMapCoordinates ( e->pos () );
491
497
492
- QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates ->x (), mLastCoordinates ->y () );
493
- if ( mRubberBand )
498
+ if ( mSelectionRubberBand )
494
499
{
495
- mRubberBand ->close ();
496
- delete mRubberBand ;
497
- mRubberBand = 0 ;
500
+ mSelectionRubberBand ->close ();
501
+ delete mSelectionRubberBand ;
502
+ mSelectionRubberBand = 0 ;
498
503
}
499
504
500
- if ( mLastCoordinates -> x () == e->pos (). x () && mLastCoordinates -> y () == e-> pos (). y () )
505
+ if ( mPressCoordinates == e->pos () )
501
506
{
502
507
if ( mSelectAnother )
503
508
{
504
- // select another feature (this should deselect current one ;-) )
509
+ // select another feature
505
510
mSelectedFeature ->setSelectedFeature ( mAnother , vlayer, mCanvas );
506
511
mIsPoint = vlayer->geometryType () == QGis::Point;
507
512
mSelectAnother = false ;
508
513
}
509
514
}
510
515
else
511
516
{
512
- // coordinates has to be coordinates from layer not canvas
513
- QgsPoint layerCoords = toLayerCoordinates ( vlayer, coords );
514
- QgsPoint layerFirstCoords = toLayerCoordinates ( vlayer, firstCoords );
515
-
516
- // got correct coordinates
517
- double topX, bottomX;
518
- if ( layerCoords.x () > layerFirstCoords.x () )
519
- {
520
- topX = layerFirstCoords.x ();
521
- bottomX = layerCoords.x ();
522
- }
523
- else
524
- {
525
- topX = layerCoords.x ();
526
- bottomX = layerFirstCoords.x ();
527
- }
528
-
529
- double leftY, rightY;
530
- if ( layerCoords.y () > layerFirstCoords.y () )
531
- {
532
- leftY = layerFirstCoords.y ();
533
- rightY = layerCoords.y ();
534
- }
535
- else
536
- {
537
- leftY = layerCoords.y ();
538
- rightY = layerFirstCoords.y ();
539
- }
540
-
541
517
if ( mMoving )
542
518
{
543
519
mMoving = false ;
520
+
544
521
QList<QgsSnappingResult> snapResults;
545
- QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates ->x (), mLastCoordinates ->y () );
546
- QList<QgsPoint> excludePoints;
547
- excludePoints.append ( mClosestVertex );
548
- mSnapper .snapToBackgroundLayers ( e->pos (), snapResults, excludePoints );
549
- coords = snapPointFromResults ( snapResults, e->pos () );
550
- // coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
551
- int topologicalEditing = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /TopologicalEditing" , 0 );
522
+ mSnapper .snapToBackgroundLayers ( e->pos (), snapResults, QList<QgsPoint>() << mClosestVertex );
523
+
524
+ QgsPoint releaseCoords = snapPointFromResults ( snapResults, e->pos () );
525
+ QgsPoint pressCoords;
526
+
552
527
if ( snapResults.size () > 0 )
553
528
{
554
- firstCoords = toMapCoordinates ( vlayer, mClosestVertex );
529
+ pressCoords = toLayerCoordinates ( vlayer, mClosestVertex );
530
+
531
+ int topologicalEditing = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /TopologicalEditing" , 0 );
555
532
if ( topologicalEditing )
556
533
{
557
534
insertSegmentVerticesForSnap ( snapResults, vlayer );
558
535
}
559
536
}
560
- QgsPoint layerCoords = toLayerCoordinates ( vlayer, coords );
561
- QgsPoint layerFirstCoords = toLayerCoordinates ( vlayer, firstCoords );
537
+ else
538
+ {
539
+ pressCoords = toLayerCoordinates ( vlayer, mPressCoordinates );
540
+ }
562
541
563
- double changeX = layerCoords.x () - layerFirstCoords.x ();
564
- double changeY = layerCoords.y () - layerFirstCoords.y ();
565
- mSelectedFeature ->beginGeometryChange ();
566
- mSelectedFeature ->moveSelectedVertexes ( changeX, changeY );
542
+ mSelectedFeature ->moveSelectedVertexes ( releaseCoords - pressCoords );
567
543
mCanvas ->refresh ();
568
- mSelectedFeature ->endGeometryChange ();
569
- // movingVertexes
570
544
}
571
545
else // selecting vertexes by rubberband
572
546
{
547
+ // coordinates has to be coordinates from layer not canvas
548
+ QgsRectangle r ( toLayerCoordinates ( vlayer, mPressCoordinates ),
549
+ toLayerCoordinates ( vlayer, e->pos () ) );
550
+
573
551
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature ->vertexMap ();
574
552
if ( !mCtrl )
575
553
{
576
554
mSelectedFeature ->deselectAllVertexes ();
577
555
}
556
+
578
557
for ( int i = 0 ; i < vertexMap.size (); i++ )
579
558
{
580
- if ( vertexMap[i]->point ().x () < bottomX && vertexMap[i]->point ().y () > leftY
581
- && vertexMap[i]->point ().x () > topX && vertexMap[i]->point ().y () < rightY )
559
+ if ( r.contains ( vertexMap[i]->point () ) )
582
560
{
583
561
// inverting selection is enough because all were deselected if ctrl is not pressed
584
562
mSelectedFeature ->invertVertexSelection ( i, false );
@@ -589,7 +567,20 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
589
567
590
568
mMoving = false ;
591
569
592
- removeRubberBands ();
570
+ if ( mDeselectOnRelease != -1 )
571
+ {
572
+ if ( mCtrl )
573
+ {
574
+ mSelectedFeature ->invertVertexSelection ( mDeselectOnRelease );
575
+ }
576
+ else
577
+ {
578
+ mSelectedFeature ->deselectAllVertexes ();
579
+ mSelectedFeature ->selectVertex ( mDeselectOnRelease );
580
+ }
581
+
582
+ mDeselectOnRelease = -1 ;
583
+ }
593
584
594
585
mRecentSnappingResults .clear ();
595
586
mExcludePoint .clear ();
@@ -602,7 +593,7 @@ void QgsMapToolNodeTool::deactivate()
602
593
delete mSelectedFeature ;
603
594
mSelectedFeature = 0 ;
604
595
605
- mRubberBand = 0 ;
596
+ mSelectionRubberBand = 0 ;
606
597
mSelectAnother = false ;
607
598
mCtrl = false ;
608
599
mMoving = true ;
0 commit comments