@@ -31,7 +31,7 @@ QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker(QgsPoint center, QgsVe
3131 marker->setWidth (2 );
3232 double movement = 4 ;
3333 double s = QgsTolerance::toleranceInMapUnits (movement, vlayer, mCanvas ->mapRenderer (), QgsTolerance::Pixels);
34- QgsPoint pom = center;
34+ QgsPoint pom = toMapCoordinates ( vlayer, center ) ;
3535 pom.setX (pom.x () - s);
3636 pom.setY (pom.y () - s);
3737 marker->addPoint (pom);
@@ -58,7 +58,8 @@ QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas ): QgsMapToolVertex
5858 mClicked = false ;
5959 mChangingGeometry = false ;
6060 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 () ) );
6263}
6364
6465QgsMapToolNodeTool::~QgsMapToolNodeTool ()
@@ -76,6 +77,16 @@ void QgsMapToolNodeTool::layersChanged()
7677 }
7778}
7879
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+
7990
8091void QgsMapToolNodeTool::featureDeleted ( int featureId )
8192{
@@ -136,22 +147,22 @@ void QgsMapToolNodeTool::createMovingRubberBands()
136147 int index = 0 ;
137148 if (beforeVertex != -1 ) // adding first point which is not moving
138149 {
139- rb->addPoint (vertexMap[beforeVertex].point , false );
150+ rb->addPoint ( toMapCoordinates ( mCanvas -> currentLayer (), vertexMap[beforeVertex].point ) , false );
140151 mSelectionFeature ->setRubberBandValues (beforeVertex, true , lastRubberBand, index );
141152 vertexMap[beforeVertex].inRubberBand = true ;
142153 index ++;
143154 }
144155 while (vertex != -1 && vertexMap[vertex].selected && !vertexMap[vertex].inRubberBand )
145156 {
146- rb->addPoint (vertexMap[vertex].point , false );
157+ rb->addPoint (toMapCoordinates ( mCanvas -> currentLayer (), vertexMap[vertex].point ) , false );
147158 mSelectionFeature ->setRubberBandValues (vertex, true , lastRubberBand, index );
148159 vertexMap[vertex].inRubberBand = true ;
149160 index ++;
150161 geometry->adjacentVertices (vertex, beforeVertex, vertex);
151162 }
152163 if (vertex != -1 && !vertexMap[vertex].selected ) // add last point if exists
153164 {
154- rb->addPoint (vertexMap[vertex].point , true );
165+ rb->addPoint (toMapCoordinates ( mCanvas -> currentLayer (), vertexMap[vertex].point ) , true );
155166 mSelectionFeature ->setRubberBandValues (vertex, true , lastRubberBand, index );
156167 vertexMap[vertex].inRubberBand = true ;
157168 index ++;
@@ -160,8 +171,15 @@ void QgsMapToolNodeTool::createMovingRubberBands()
160171 lastRubberBand ++;
161172 }
162173 }
174+ }
163175
164176
177+ void QgsMapToolNodeTool::coordinatesChanged ()
178+ {
179+ if (mSelectionFeature != NULL )
180+ {
181+ mSelectionFeature ->updateVertexMarkersPosition ( mCanvas );
182+ }
165183}
166184
167185
@@ -197,11 +215,9 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
197215 {
198216 QgsRubberBand* rb = createRubberBandMarker ( vertexMap[i].point , vlayer );
199217 mQgsRubberBands .append (rb);
200-
201218 }
202219 }
203220 }
204-
205221 createMovingRubberBands ();
206222 }
207223 else
@@ -214,7 +230,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
214230 QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
215231 if (snapResults.size () > 0 )
216232 {
217- firstCoords = mClosestVertex ;
233+ firstCoords = toMapCoordinates ( vlayer, mClosestVertex ) ;
218234 }
219235
220236 // special handling of points
@@ -236,8 +252,10 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
236252
237253 if (vertexMap[i].selected )
238254 {
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(
241259 mQgsRubberBands [vertexMap[i].rubberBandNr ]->movePoint ( vertexMap[i].index + 1 , QgsPoint (x, y));
242260 if (vertexMap[i].index == 0 )
243261 {
@@ -337,7 +355,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
337355 QgsGeometry* g = f.geometry ();
338356 int atVertex, beforeVertex, afterVertex;
339357 double dist;
340- g->closestVertex (mapCoordPoint, atVertex, beforeVertex, afterVertex, dist);
358+ g->closestVertex (toLayerCoordinates (vlayer, mapCoordPoint) , atVertex, beforeVertex, afterVertex, dist);
341359 dist = sqrt (dist);
342360
343361 mSnapper .snapToCurrentLayer (e->pos (), snapResults, QgsSnapper::SnapToVertex, tol);
@@ -374,7 +392,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
374392 {
375393 mMoving = true ;
376394 QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint (e->pos ().x (), e->pos ().y ());
377- mClosestVertex = getClosestVertex ( point );
395+ mClosestVertex = getClosestVertex ( toLayerCoordinates ( vlayer, point) );
378396 if ( !mSelectionFeature ->isSelected ( snapResult.beforeVertexNr ) || !mSelectionFeature ->isSelected ( snapResult.afterVertexNr ))
379397 {
380398 mSelectionFeature ->deselectAllVertexes ();
@@ -396,7 +414,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
396414 // some vertex selected
397415 mMoving = true ;
398416 QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint (e->pos ().x (), e->pos ().y ());
399- mClosestVertex = getClosestVertex ( point );
417+ mClosestVertex = getClosestVertex ( toLayerCoordinates ( vlayer, point) );
400418 if (mMoving )
401419 {
402420 if (mCtrl )
@@ -441,7 +459,9 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
441459
442460 mClicked = false ;
443461 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 );
445465 QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates ->x (), mLastCoordinates ->y () );
446466 if (mQRubberBand != NULL )
447467 {
@@ -461,30 +481,34 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
461481 }
462482 else
463483 {
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
465489 double topX;
466490 double bottomX;
467- if (coords .x () > firstCoords .x ())
491+ if (layerCoords .x () > layerFirstCoords .x ())
468492 {
469- topX = firstCoords .x ();
470- bottomX = coords .x ();
493+ topX = layerFirstCoords .x ();
494+ bottomX = layerCoords .x ();
471495 }
472496 else
473497 {
474- topX = coords .x ();
475- bottomX = firstCoords .x ();
498+ topX = layerCoords .x ();
499+ bottomX = layerFirstCoords .x ();
476500 }
477501 double leftY;
478502 double rightY;
479- if (coords .y () > firstCoords .y ())
503+ if (layerCoords .y () > layerFirstCoords .y ())
480504 {
481- leftY = firstCoords .y ();
482- rightY = coords .y ();
505+ leftY = layerFirstCoords .y ();
506+ rightY = layerCoords .y ();
483507 }
484508 else
485509 {
486- leftY = coords .y ();
487- rightY = firstCoords .y ();
510+ leftY = layerCoords .y ();
511+ rightY = layerFirstCoords .y ();
488512 }
489513 if (mMoving )
490514 {
@@ -498,11 +522,12 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
498522 // coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
499523 if (snapResults.size () > 0 )
500524 {
501- firstCoords = mClosestVertex ;
525+ firstCoords = toMapCoordinates ( vlayer, mClosestVertex ) ;
502526 }
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 ();
506531 mChangingGeometry = true ;
507532 mSelectionFeature ->moveSelectedVertexes ( changeX, changeY );
508533 mCanvas ->refresh ();
@@ -541,7 +566,7 @@ void QgsMapToolNodeTool::deactivate()
541566 delete mSelectionFeature ;
542567 mSelectionFeature = NULL ;
543568 disconnect ( mCanvas ->currentLayer (), SIGNAL ( featureDeleted (int ) ) );
544- disconnect (mCanvas ->currentLayer (), SIGNAL ( layerModified (bool ) ) );
569+ disconnect ( mCanvas ->currentLayer (), SIGNAL ( layerModified (bool ) ) );
545570
546571 mQRubberBand = NULL ;
547572 mSelectAnother = false ;
@@ -592,11 +617,12 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
592617 if (snapResults.first ().snappedVertexNr == -1 )
593618 {
594619 QgsPoint coords = snapResults.first ().snappedVertex ;
620+ QgsPoint layerCoords = toLayerCoordinates ( vlayer, coords );
595621 // QgsPoint coords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );
596622 // add vertex
597623 vlayer->beginEditCommand ( tr (" Inserted vertex" ) );
598624 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 );
600626 vlayer->endEditCommand ();
601627
602628 mSelectionFeature ->updateFromFeature ();
@@ -736,13 +762,16 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
736762 {
737763 mVlayer ->moveVertex ( mVertexMap [i].point .x () + changeX, mVertexMap [i].point .y () + changeY, mFeatureId , i);
738764 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);
740769 mVertexMap [i].vertexMarker ->update ();
741770 if (mVertexMap [i].equals != -1 && !mVertexMap [mVertexMap [i].equals ].selected )
742771 {
743772 int index = mVertexMap [i].equals ;
744773 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);
746775 mVertexMap [i].vertexMarker ->update ();
747776 // for polygon delete both
748777 }
@@ -755,7 +784,8 @@ void SelectionFeature::moveSelectedVertexes( double changeX, double changeY )
755784QgsVertexMarker* SelectionFeature::createVertexMarker (QgsPoint center)
756785{
757786 QgsVertexMarker* marker = new QgsVertexMarker (mCanvas );
758- marker->setCenter ( center );
787+ QgsPoint newCenter = mCanvas ->mapRenderer ()->layerToMapCoordinates ( mVlayer , center );
788+ marker->setCenter ( newCenter );
759789
760790 marker->setIconType ( QgsVertexMarker::ICON_BOX );
761791
@@ -1028,7 +1058,7 @@ void SelectionFeature::updateVertexMarkersPosition( QgsMapCanvas* canvas )
10281058{
10291059 for (int i=0 ; i< mVertexMap .size () ;i++)
10301060 {
1031- mVertexMap [i].vertexMarker ->setCenter (mVertexMap [i].point );
1061+ mVertexMap [i].vertexMarker ->setCenter ( mCanvas -> mapRenderer ()-> layerToMapCoordinates ( mVlayer , mVertexMap [i].point ) );
10321062 mVertexMap [i].vertexMarker ->update ();
10331063 }
10341064}
0 commit comments