Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[vertex tool] highlight vertices of locked features when not selected
  • Loading branch information
3nids committed Mar 4, 2019
1 parent ecef55e commit 95ce10b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
55 changes: 44 additions & 11 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -436,7 +436,10 @@ void QgsVertexTool::cadCanvasPressEvent( QgsMapMouseEvent *e )
}

if ( !clickedOnHighlightedVertex && e->button() == Qt::LeftButton )
{
setHighlightedVertices( QList<Vertex>() ); // reset selection
updateLockedFeatureVertices();
}
}

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

// we have either locked ourselves to a feature or unlocked again
Expand Down Expand Up @@ -1328,11 +1327,7 @@ void QgsVertexTool::updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid
if ( mLockedFeature && mLockedFeature->featureId() == fid && mLockedFeature->layer() == layer )
{
// if show feature is called on a feature that's already binded to the vertex editor, toggle it off
mLockedFeature.reset();
if ( mVertexEditor )
{
mVertexEditor->updateEditor( nullptr );
}
cleanupLockedFeature();
return;
}

Expand All @@ -1345,16 +1340,42 @@ void QgsVertexTool::updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid
mLockedFeature->selectVertex( mSelectedVertices.at( i ).vertexId );
}
}

connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );
}

updateLockedFeatureVertices();

// make sure the vertex editor is alive and visible
showVertexEditor(); //#spellok

mVertexEditor->updateEditor( mLockedFeature.get() );
}

void QgsVertexTool::updateLockedFeatureVertices()
{
qDeleteAll( mLockedFeatureVerticesMarkers );
mLockedFeatureVerticesMarkers.clear();
if ( mVertexEditor && mLockedFeature )
{
const QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
for ( const QgsVertexEntry *vertex : vertexMap )
{
if ( !vertex->isSelected() )
{
QgsVertexMarker *marker = new QgsVertexMarker( canvas() );
marker->setIconType( QgsVertexMarker::ICON_CIRCLE );
marker->setIconSize( QgsGuiUtils::scaleIconSize( 10 ) );
marker->setPenWidth( QgsGuiUtils::scaleIconSize( 3 ) );
marker->setColor( Qt::red );
marker->setFillColor( Qt::red );
marker->setCenter( toMapCoordinates( mLockedFeature->layer(), vertex->point() ) );
mLockedFeatureVerticesMarkers.append( marker );
}
}
}
}


void QgsVertexTool::showVertexEditor() //#spellok
{
if ( !mVertexEditor )
Expand Down Expand Up @@ -1382,6 +1403,16 @@ void QgsVertexTool::cleanupVertexEditor()
mVertexEditor.reset();
}

void QgsVertexTool::cleanupLockedFeature()
{
mLockedFeature.reset();
if ( mVertexEditor )
{
mVertexEditor->updateEditor( nullptr );
}
updateLockedFeatureVertices();
}

void QgsVertexTool::lockedFeatureSelectionChanged()
{
Q_ASSERT( mLockedFeature );
Expand All @@ -1396,6 +1427,8 @@ void QgsVertexTool::lockedFeatureSelectionChanged()
}

setHighlightedVertices( vertices, ModeReset );

updateLockedFeatureVertices();
}

static int _firstSelectedVertex( QgsLockedFeature &selectedFeature )
Expand Down
11 changes: 9 additions & 2 deletions src/app/vertextool/qgsvertextool.h
Expand Up @@ -141,6 +141,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

void cleanupVertexEditor();

void cleanupLockedFeature();

/**
* Temporarily override snapping config and snap to vertices and edges
of any editable vector layer, to allow selection of vertex for editing
Expand Down Expand Up @@ -292,6 +294,9 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

void stopRangeVertexSelection();

//! update the highlight of vertices from the locked feature
void updateLockedFeatureVertices();

private:

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

// members for dragging operation

Expand Down Expand Up @@ -437,7 +444,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

// support for vertex editor

//! Selected feature for the vertex editor
//! Locked feature for the vertex editor
std::unique_ptr<QgsLockedFeature> mLockedFeature;
//! Dock widget which allows editing vertices
std::unique_ptr<QgsVertexEditor> mVertexEditor;
Expand Down

0 comments on commit 95ce10b

Please sign in to comment.