@@ -31,7 +31,7 @@ QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker(QgsPoint center, QgsVe
31
31
marker->setWidth (2 );
32
32
double movement = 4 ;
33
33
double s = QgsTolerance::toleranceInMapUnits (movement, vlayer, mCanvas ->mapRenderer (), QgsTolerance::Pixels);
34
- QgsPoint pom = center;
34
+ QgsPoint pom = toMapCoordinates ( vlayer, center ) ;
35
35
pom.setX (pom.x () - s);
36
36
pom.setY (pom.y () - s);
37
37
marker->addPoint (pom);
@@ -58,7 +58,8 @@ QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas ): QgsMapToolVertex
58
58
mClicked = false ;
59
59
mChangingGeometry = false ;
60
60
mIsPoint = false ;
61
- connect ( canvas, SIGNAL (layersChanged ()), this , SLOT (layersChanged () ) );
61
+ connect ( canvas, SIGNAL (layersChanged ()), this , SLOT ( layersChanged () ) );
62
+ connect ( canvas->mapRenderer (), SIGNAL (destinationSrsChanged ()), this , SLOT ( coordinatesChanged () ) );
62
63
}
63
64
64
65
QgsMapToolNodeTool::~QgsMapToolNodeTool ()
@@ -76,6 +77,16 @@ void QgsMapToolNodeTool::layersChanged()
76
77
}
77
78
}
78
79
80
+ void QgsMapToolNodeTool::currentLayerChanged ( QgsMapLayer* layer)
81
+ {
82
+ QgsVectorLayer* vlayer = vlayer = dynamic_cast <QgsVectorLayer*>( layer );
83
+ if (mSelectionFeature != NULL && mSelectionFeature ->vlayer () != vlayer)
84
+ {
85
+ delete mSelectionFeature ;
86
+ mSelectionFeature = NULL ;
87
+ }
88
+ }
89
+
79
90
80
91
void QgsMapToolNodeTool::featureDeleted ( int featureId )
81
92
{
@@ -136,22 +147,22 @@ void QgsMapToolNodeTool::createMovingRubberBands()
136
147
int index = 0 ;
137
148
if (beforeVertex != -1 ) // adding first point which is not moving
138
149
{
139
- rb->addPoint (vertexMap[beforeVertex].point , false );
150
+ rb->addPoint ( toMapCoordinates ( mCanvas -> currentLayer (), vertexMap[beforeVertex].point ) , false );
140
151
mSelectionFeature ->setRubberBandValues (beforeVertex, true , lastRubberBand, index );
141
152
vertexMap[beforeVertex].inRubberBand = true ;
142
153
index ++;
143
154
}
144
155
while (vertex != -1 && vertexMap[vertex].selected && !vertexMap[vertex].inRubberBand )
145
156
{
146
- rb->addPoint (vertexMap[vertex].point , false );
157
+ rb->addPoint (toMapCoordinates ( mCanvas -> currentLayer (), vertexMap[vertex].point ) , false );
147
158
mSelectionFeature ->setRubberBandValues (vertex, true , lastRubberBand, index );
148
159
vertexMap[vertex].inRubberBand = true ;
149
160
index ++;
150
161
geometry->adjacentVertices (vertex, beforeVertex, vertex);
151
162
}
152
163
if (vertex != -1 && !vertexMap[vertex].selected ) // add last point if exists
153
164
{
154
- rb->addPoint (vertexMap[vertex].point , true );
165
+ rb->addPoint (toMapCoordinates ( mCanvas -> currentLayer (), vertexMap[vertex].point ) , true );
155
166
mSelectionFeature ->setRubberBandValues (vertex, true , lastRubberBand, index );
156
167
vertexMap[vertex].inRubberBand = true ;
157
168
index ++;
@@ -160,8 +171,15 @@ void QgsMapToolNodeTool::createMovingRubberBands()
160
171
lastRubberBand ++;
161
172
}
162
173
}
174
+ }
163
175
164
176
177
+ void QgsMapToolNodeTool::coordinatesChanged ()
178
+ {
179
+ if (mSelectionFeature != NULL )
180
+ {
181
+ mSelectionFeature ->updateVertexMarkersPosition ( mCanvas );
182
+ }
165
183
}
166
184
167
185
@@ -197,11 +215,9 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
197
215
{
198
216
QgsRubberBand* rb = createRubberBandMarker ( vertexMap[i].point , vlayer );
199
217
mQgsRubberBands .append (rb);
200
-
201
218
}
202
219
}
203
220
}
204
-
205
221
createMovingRubberBands ();
206
222
}
207
223
else
@@ -214,7 +230,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
214
230
QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
215
231
if (snapResults.size () > 0 )
216
232
{
217
- firstCoords = mClosestVertex ;
233
+ firstCoords = toMapCoordinates ( vlayer, mClosestVertex ) ;
218
234
}
219
235
220
236
// special handling of points
@@ -236,8 +252,10 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
236
252
237
253
if (vertexMap[i].selected )
238
254
{
239
- double x = vertexMap[i].point .x () + posMapCoord.x () - firstCoords.x ();
240
- double y = vertexMap[i].point .y () + posMapCoord.y () - firstCoords.y ();
255
+ QgsPoint mapCoords = toMapCoordinates ( vlayer, vertexMap[i].point );
256
+ double x = mapCoords.x () + posMapCoord.x () - firstCoords.x ();
257
+ double y = mapCoords.y () + posMapCoord.y () - firstCoords.y ();
258
+ // QgsPoint pom = toLayerCoordinates(
241
259
mQgsRubberBands [vertexMap[i].rubberBandNr ]->movePoint ( vertexMap[i].index + 1 , QgsPoint (x, y));
242
260
if (vertexMap[i].index == 0 )
243
261
{
@@ -337,7 +355,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
337
355
QgsGeometry* g = f.geometry ();
338
356
int atVertex, beforeVertex, afterVertex;
339
357
double dist;
340
- g->closestVertex (mapCoordPoint, atVertex, beforeVertex, afterVertex, dist);
358
+ g->closestVertex (toLayerCoordinates (vlayer, mapCoordPoint) , atVertex, beforeVertex, afterVertex, dist);
341
359
dist = sqrt (dist);
342
360
343
361
mSnapper .snapToCurrentLayer (e->pos (), snapResults, QgsSnapper::SnapToVertex, tol);
@@ -374,7 +392,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
374
392
{
375
393
mMoving = true ;
376
394
QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint (e->pos ().x (), e->pos ().y ());
377
- mClosestVertex = getClosestVertex ( point );
395
+ mClosestVertex = getClosestVertex ( toLayerCoordinates ( vlayer, point) );
378
396
if ( !mSelectionFeature ->isSelected ( snapResult.beforeVertexNr ) || !mSelectionFeature ->isSelected ( snapResult.afterVertexNr ))
379
397
{
380
398
mSelectionFeature ->deselectAllVertexes ();
@@ -396,7 +414,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
396
414
// some vertex selected
397
415
mMoving = true ;
398
416
QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint (e->pos ().x (), e->pos ().y ());
399
- mClosestVertex = getClosestVertex ( point );
417
+ mClosestVertex = getClosestVertex ( toLayerCoordinates ( vlayer, point) );
400
418
if (mMoving )
401
419
{
402
420
if (mCtrl )
@@ -441,7 +459,9 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
441
459
442
460
mClicked = false ;
443
461
mSelectionRectangle = false ;
444
- QgsPoint coords = mCanvas ->getCoordinateTransform ()->toMapPoint ( e->pos ().x (), e->pos ().y () );
462
+ QgsPoint coords = toMapCoordinates ( e->pos () );
463
+ // QgsPoint coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
464
+ // QgsPoint firstCoords = toMapCoordinates( *mLastCoordinates );
445
465
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates ->x (), mLastCoordinates ->y () );
446
466
if (mQRubberBand != NULL )
447
467
{
@@ -461,30 +481,34 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
461
481
}
462
482
else
463
483
{
464
- // got correct coordinates
484
+ // coordinates has to be coordinates from layer not canvas
485
+ QgsPoint layerCoords = toLayerCoordinates (vlayer, coords);
486
+ QgsPoint layerFirstCoords = toLayerCoordinates (vlayer, firstCoords);
487
+
488
+ // got correct coordinates
465
489
double topX;
466
490
double bottomX;
467
- if (coords .x () > firstCoords .x ())
491
+ if (layerCoords .x () > layerFirstCoords .x ())
468
492
{
469
- topX = firstCoords .x ();
470
- bottomX = coords .x ();
493
+ topX = layerFirstCoords .x ();
494
+ bottomX = layerCoords .x ();
471
495
}
472
496
else
473
497
{
474
- topX = coords .x ();
475
- bottomX = firstCoords .x ();
498
+ topX = layerCoords .x ();
499
+ bottomX = layerFirstCoords .x ();
476
500
}
477
501
double leftY;
478
502
double rightY;
479
- if (coords .y () > firstCoords .y ())
503
+ if (layerCoords .y () > layerFirstCoords .y ())
480
504
{
481
- leftY = firstCoords .y ();
482
- rightY = coords .y ();
505
+ leftY = layerFirstCoords .y ();
506
+ rightY = layerCoords .y ();
483
507
}
484
508
else
485
509
{
486
- leftY = coords .y ();
487
- rightY = firstCoords .y ();
510
+ leftY = layerCoords .y ();
511
+ rightY = layerFirstCoords .y ();
488
512
}
489
513
if (mMoving )
490
514
{
@@ -498,11 +522,12 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
498
522
// coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
499
523
if (snapResults.size () > 0 )
500
524
{
501
- firstCoords = mClosestVertex ;
525
+ firstCoords = toMapCoordinates ( vlayer, mClosestVertex ) ;
502
526
}
503
-
504
- double changeX = coords.x () - firstCoords.x ();
505
- double changeY = coords.y () - firstCoords.y ();
527
+ QgsPoint layerCoords = toLayerCoordinates (vlayer, coords);
528
+ QgsPoint layerFirstCoords = toLayerCoordinates (vlayer, firstCoords);
529
+ double changeX = layerCoords.x () - layerFirstCoords.x ();
530
+ double changeY = layerCoords.y () - layerFirstCoords.y ();
506
531
mChangingGeometry = true ;
507
532
mSelectionFeature ->moveSelectedVertexes ( changeX, changeY );
508
533
mCanvas ->refresh ();
@@ -541,7 +566,7 @@ void QgsMapToolNodeTool::deactivate()
541
566
delete mSelectionFeature ;
542
567
mSelectionFeature = NULL ;
543
568
disconnect ( mCanvas ->currentLayer (), SIGNAL ( featureDeleted (int ) ) );
544
- disconnect (mCanvas ->currentLayer (), SIGNAL ( layerModified (bool ) ) );
569
+ disconnect ( mCanvas ->currentLayer (), SIGNAL ( layerModified (bool ) ) );
545
570
546
571
mQRubberBand = NULL ;
547
572
mSelectAnother = false ;
@@ -592,11 +617,12 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
592
617
if (snapResults.first ().snappedVertexNr == -1 )
593
618
{
594
619
QgsPoint coords = snapResults.first ().snappedVertex ;
620
+ QgsPoint layerCoords = toLayerCoordinates ( vlayer, coords );
595
621
// QgsPoint coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
596
622
// add vertex
597
623
vlayer->beginEditCommand ( tr (" Inserted vertex" ) );
598
624
mChangingGeometry = true ;
599
- vlayer->insertVertex (coords .x (), coords .y (), mSelectionFeature ->featureId (), snapResults.first ().afterVertexNr );
625
+ vlayer->insertVertex (layerCoords .x (), layerCoords .y (), mSelectionFeature ->featureId (), snapResults.first ().afterVertexNr );
600
626
vlayer->endEditCommand ();
601
627
602
628
mSelectionFeature ->updateFromFeature ();
@@ -736,13 +762,16 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
736
762
{
737
763
mVlayer ->moveVertex ( mVertexMap [i].point .x () + changeX, mVertexMap [i].point .y () + changeY, mFeatureId , i);
738
764
mVertexMap [i].point = QgsPoint (mVertexMap [i].point .x () + changeX, mVertexMap [i].point .y () + changeY);
739
- mVertexMap [i].vertexMarker ->setCenter (mVertexMap [i].point );
765
+ QgsPoint point = mVertexMap [i].point ;
766
+ point = mCanvas ->mapRenderer ()->layerToMapCoordinates ( mVlayer , mVertexMap [i].point );
767
+
768
+ mVertexMap [i].vertexMarker ->setCenter (point);
740
769
mVertexMap [i].vertexMarker ->update ();
741
770
if (mVertexMap [i].equals != -1 && !mVertexMap [mVertexMap [i].equals ].selected )
742
771
{
743
772
int index = mVertexMap [i].equals ;
744
773
mVertexMap [index ].point = QgsPoint (mVertexMap [index ].point .x () + changeX, mVertexMap [index ].point .y () + changeY);
745
- mVertexMap [i].vertexMarker ->setCenter (mVertexMap [i]. point );
774
+ mVertexMap [i].vertexMarker ->setCenter (point);
746
775
mVertexMap [i].vertexMarker ->update ();
747
776
// for polygon delete both
748
777
}
@@ -755,7 +784,8 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
755
784
QgsVertexMarker* SelectionFeature::createVertexMarker (QgsPoint center)
756
785
{
757
786
QgsVertexMarker* marker = new QgsVertexMarker (mCanvas );
758
- marker->setCenter ( center );
787
+ QgsPoint newCenter = mCanvas ->mapRenderer ()->layerToMapCoordinates ( mVlayer , center );
788
+ marker->setCenter ( newCenter );
759
789
760
790
marker->setIconType ( QgsVertexMarker::ICON_BOX );
761
791
@@ -1028,7 +1058,7 @@ void SelectionFeature::updateVertexMarkersPosition( QgsMapCanvas* canvas )
1028
1058
{
1029
1059
for (int i=0 ; i< mVertexMap .size () ;i++)
1030
1060
{
1031
- mVertexMap [i].vertexMarker ->setCenter (mVertexMap [i].point );
1061
+ mVertexMap [i].vertexMarker ->setCenter ( mCanvas -> mapRenderer ()-> layerToMapCoordinates ( mVlayer , mVertexMap [i].point ) );
1032
1062
mVertexMap [i].vertexMarker ->update ();
1033
1063
}
1034
1064
}
0 commit comments