Skip to content

Commit c5e110d

Browse files
committed
nodetool: track layer of selected feature instead of current layer (fixes #7351)
1 parent 86eda3d commit c5e110d

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/app/nodetool/qgsmaptoolnodetool.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ void QgsMapToolNodeTool::createMovingRubberBands()
4949
{
5050
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
5151

52-
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
52+
Q_ASSERT( mSelectedFeature );
53+
54+
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
55+
Q_ASSERT( vlayer );
56+
5357
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature->vertexMap();
5458
QgsGeometry* geometry = mSelectedFeature->geometry();
5559
int beforeVertex, afterVertex;
@@ -84,7 +88,7 @@ void QgsMapToolNodeTool::createMovingRubberBands()
8488
int index = 0;
8589
if ( beforeVertex != -1 ) // adding first point which is not moving
8690
{
87-
rb->addPoint( toMapCoordinates( mCanvas->currentLayer(), vertexMap[beforeVertex]->point() ), false );
91+
rb->addPoint( toMapCoordinates( vlayer, vertexMap[beforeVertex]->point() ), false );
8892
vertexMap[beforeVertex]->setRubberBandValues( true, lastRubberBand, index );
8993
index++;
9094
}
@@ -96,15 +100,15 @@ void QgsMapToolNodeTool::createMovingRubberBands()
96100
createTopologyRubberBands( vlayer, vertexMap, vertex );
97101
}
98102
// adding point which will be moved
99-
rb->addPoint( toMapCoordinates( mCanvas->currentLayer(), vertexMap[vertex]->point() ), false );
103+
rb->addPoint( toMapCoordinates( vlayer, vertexMap[vertex]->point() ), false );
100104
// setting values about added vertex
101105
vertexMap[vertex]->setRubberBandValues( true, lastRubberBand, index );
102106
index++;
103107
geometry->adjacentVertices( vertex, beforeVertex, vertex );
104108
}
105109
if ( vertex != -1 && !vertexMap[vertex]->isSelected() ) // add last point not moving if exists
106110
{
107-
rb->addPoint( toMapCoordinates( mCanvas->currentLayer(), vertexMap[vertex]->point() ), true );
111+
rb->addPoint( toMapCoordinates( vlayer, vertexMap[vertex]->point() ), true );
108112
vertexMap[vertex]->setRubberBandValues( true, lastRubberBand, index );
109113
index++;
110114
}
@@ -225,9 +229,8 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
225229
if ( !mSelectedFeature || !mClicked )
226230
return;
227231

228-
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
229-
if ( !vlayer )
230-
return;
232+
QgsVectorLayer* vlayer = mSelectedFeature->vlayer();
233+
Q_ASSERT( vlayer );
231234

232235
mSelectAnother = false;
233236

@@ -347,13 +350,15 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
347350
{
348351
QgsDebugCall;
349352

350-
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
351-
352353
mClicked = true;
353354
mPressCoordinates = e->pos();
354355
QList<QgsSnappingResult> snapResults;
355356
if ( !mSelectedFeature )
356357
{
358+
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
359+
if ( !vlayer )
360+
return;
361+
357362
mSelectAnother = false;
358363
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertexAndSegment, -1 );
359364

@@ -369,6 +374,9 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
369374
}
370375
else
371376
{
377+
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
378+
Q_ASSERT( vlayer );
379+
372380
// some feature already selected
373381
QgsPoint layerCoordPoint = toLayerCoordinates( vlayer, e->pos() );
374382

@@ -488,7 +496,8 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
488496

489497
removeRubberBands();
490498

491-
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
499+
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
500+
Q_ASSERT( vlayer );
492501

493502
mClicked = false;
494503
mSelectionRectangle = false;
@@ -626,10 +635,12 @@ void QgsMapToolNodeTool::removeRubberBands()
626635

627636
void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
628637
{
629-
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
630-
if ( !vlayer )
638+
if ( !mSelectedFeature )
631639
return;
632640

641+
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
642+
Q_ASSERT( vlayer );
643+
633644
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
634645
QMultiMap<double, QgsSnappingResult> currentResultList;
635646

0 commit comments

Comments
 (0)