Skip to content

Commit

Permalink
[vertex tool] highlight vertices of locked features when not selected (
Browse files Browse the repository at this point in the history
  • Loading branch information
backporting[bot] authored and 3nids committed Mar 4, 2019
1 parent adbdcea commit ecdfe1f
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 ) if ( !clickedOnHighlightedVertex && e->button() == Qt::LeftButton )
{
setHighlightedVertices( QList<Vertex>() ); // reset selection setHighlightedVertices( QList<Vertex>() ); // reset selection
updateLockedFeatureVertices();
}
} }


if ( e->button() == Qt::LeftButton ) 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 // 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 // we got to the end of the list - let's deselect any feature we may have had selected
setHighlightedVertices( QList<Vertex>(), ModeReset ); setHighlightedVertices( QList<Vertex>(), ModeReset );
mLockedFeature.reset(); cleanupLockedFeature();
if ( mVertexEditor )
{
mVertexEditor->updateEditor( nullptr );
}
} }


// we have either locked ourselves to a feature or unlocked again // 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 ( 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 // if show feature is called on a feature that's already binded to the vertex editor, toggle it off
mLockedFeature.reset(); cleanupLockedFeature();
if ( mVertexEditor )
{
mVertexEditor->updateEditor( nullptr );
}
return; return;
} }


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

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


updateLockedFeatureVertices();

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


mVertexEditor->updateEditor( mLockedFeature.get() ); 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 void QgsVertexTool::showVertexEditor() //#spellok
{ {
if ( !mVertexEditor ) if ( !mVertexEditor )
Expand Down Expand Up @@ -1382,6 +1403,16 @@ void QgsVertexTool::cleanupVertexEditor()
mVertexEditor.reset(); mVertexEditor.reset();
} }


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

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


setHighlightedVertices( vertices, ModeReset ); setHighlightedVertices( vertices, ModeReset );

updateLockedFeatureVertices();
} }


static int _firstSelectedVertex( QgsLockedFeature &selectedFeature ) 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 cleanupVertexEditor();


void cleanupLockedFeature();

/** /**
* Temporarily override snapping config and snap to vertices and edges * Temporarily override snapping config and snap to vertices and edges
of any editable vector layer, to allow selection of vertex for editing 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(); void stopRangeVertexSelection();


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

private: private:


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


// members for dragging operation // members for dragging operation


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


// support for vertex editor // support for vertex editor


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

0 comments on commit ecdfe1f

Please sign in to comment.