Skip to content

Commit 7119b74

Browse files
authored
[vertex tool] highlight vertices of locked features when not selected (#9348)
1 parent 1f80670 commit 7119b74

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

src/app/vertextool/qgsvertextool.cpp

+44-11
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ void QgsVertexTool::cadCanvasPressEvent( QgsMapMouseEvent *e )
436436
}
437437

438438
if ( !clickedOnHighlightedVertex && e->button() == Qt::LeftButton )
439+
{
439440
setHighlightedVertices( QList<Vertex>() ); // reset selection
441+
updateLockedFeatureVertices();
442+
}
440443
}
441444

442445
if ( e->button() == Qt::LeftButton )
@@ -994,11 +997,7 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
994997
// there's really nothing under the cursor or while cycling through the list of available features
995998
// we got to the end of the list - let's deselect any feature we may have had selected
996999
setHighlightedVertices( QList<Vertex>(), ModeReset );
997-
mLockedFeature.reset();
998-
if ( mVertexEditor )
999-
{
1000-
mVertexEditor->updateEditor( nullptr );
1001-
}
1000+
cleanupLockedFeature();
10021001
}
10031002

10041003
// we have either locked ourselves to a feature or unlocked again
@@ -1328,11 +1327,7 @@ void QgsVertexTool::updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid
13281327
if ( mLockedFeature && mLockedFeature->featureId() == fid && mLockedFeature->layer() == layer )
13291328
{
13301329
// if show feature is called on a feature that's already binded to the vertex editor, toggle it off
1331-
mLockedFeature.reset();
1332-
if ( mVertexEditor )
1333-
{
1334-
mVertexEditor->updateEditor( nullptr );
1335-
}
1330+
cleanupLockedFeature();
13361331
return;
13371332
}
13381333

@@ -1345,16 +1340,42 @@ void QgsVertexTool::updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid
13451340
mLockedFeature->selectVertex( mSelectedVertices.at( i ).vertexId );
13461341
}
13471342
}
1348-
13491343
connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );
13501344
}
13511345

1346+
updateLockedFeatureVertices();
1347+
13521348
// make sure the vertex editor is alive and visible
13531349
showVertexEditor(); //#spellok
13541350

13551351
mVertexEditor->updateEditor( mLockedFeature.get() );
13561352
}
13571353

1354+
void QgsVertexTool::updateLockedFeatureVertices()
1355+
{
1356+
qDeleteAll( mLockedFeatureVerticesMarkers );
1357+
mLockedFeatureVerticesMarkers.clear();
1358+
if ( mVertexEditor && mLockedFeature )
1359+
{
1360+
const QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
1361+
for ( const QgsVertexEntry *vertex : vertexMap )
1362+
{
1363+
if ( !vertex->isSelected() )
1364+
{
1365+
QgsVertexMarker *marker = new QgsVertexMarker( canvas() );
1366+
marker->setIconType( QgsVertexMarker::ICON_CIRCLE );
1367+
marker->setIconSize( QgsGuiUtils::scaleIconSize( 10 ) );
1368+
marker->setPenWidth( QgsGuiUtils::scaleIconSize( 3 ) );
1369+
marker->setColor( Qt::red );
1370+
marker->setFillColor( Qt::red );
1371+
marker->setCenter( toMapCoordinates( mLockedFeature->layer(), vertex->point() ) );
1372+
mLockedFeatureVerticesMarkers.append( marker );
1373+
}
1374+
}
1375+
}
1376+
}
1377+
1378+
13581379
void QgsVertexTool::showVertexEditor() //#spellok
13591380
{
13601381
if ( !mVertexEditor )
@@ -1382,6 +1403,16 @@ void QgsVertexTool::cleanupVertexEditor()
13821403
mVertexEditor.reset();
13831404
}
13841405

1406+
void QgsVertexTool::cleanupLockedFeature()
1407+
{
1408+
mLockedFeature.reset();
1409+
if ( mVertexEditor )
1410+
{
1411+
mVertexEditor->updateEditor( nullptr );
1412+
}
1413+
updateLockedFeatureVertices();
1414+
}
1415+
13851416
void QgsVertexTool::lockedFeatureSelectionChanged()
13861417
{
13871418
Q_ASSERT( mLockedFeature );
@@ -1396,6 +1427,8 @@ void QgsVertexTool::lockedFeatureSelectionChanged()
13961427
}
13971428

13981429
setHighlightedVertices( vertices, ModeReset );
1430+
1431+
updateLockedFeatureVertices();
13991432
}
14001433

14011434
static int _firstSelectedVertex( QgsLockedFeature &selectedFeature )

src/app/vertextool/qgsvertextool.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
141141

142142
void cleanupVertexEditor();
143143

144+
void cleanupLockedFeature();
145+
144146
/**
145147
* Temporarily override snapping config and snap to vertices and edges
146148
of any editable vector layer, to allow selection of vertex for editing
@@ -292,6 +294,9 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
292294

293295
void stopRangeVertexSelection();
294296

297+
//! update the highlight of vertices from the locked feature
298+
void updateLockedFeatureVertices();
299+
295300
private:
296301

297302
// members used for temporary highlight of stuff
@@ -306,7 +311,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
306311
QgsVertexMarker *mEdgeCenterMarker = nullptr;
307312
//! rubber band for highlight of a whole feature on mouse over and not dragging anything
308313
QgsRubberBand *mFeatureBand = nullptr;
309-
//! rubber band for highlight of all vertices of a feature on mouse over and not dragging anything
314+
//! rubber band for highlight of all vertices of a feature on mouse over and not dragging anything, also used for locked feature vertices
310315
QgsRubberBand *mFeatureBandMarkers = nullptr;
311316
//! source layer for mFeatureBand (null if mFeatureBand is null)
312317
const QgsVectorLayer *mFeatureBandLayer = nullptr;
@@ -316,6 +321,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
316321
QgsRubberBand *mVertexBand = nullptr;
317322
//! highlight of an edge while mouse pointer is close to an edge and not dragging anything
318323
QgsRubberBand *mEdgeBand = nullptr;
324+
//! highlight of locked feature vertices (but not selected)
325+
QList<QgsVertexMarker *> mLockedFeatureVerticesMarkers;
319326

320327
// members for dragging operation
321328

@@ -437,7 +444,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
437444

438445
// support for vertex editor
439446

440-
//! Selected feature for the vertex editor
447+
//! Locked feature for the vertex editor
441448
std::unique_ptr<QgsLockedFeature> mLockedFeature;
442449
//! Dock widget which allows editing vertices
443450
std::unique_ptr<QgsVertexEditor> mVertexEditor;

0 commit comments

Comments
 (0)