Skip to content

Commit

Permalink
Also highlight vertices when highlighting a feature on mouse hover
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 6, 2017
1 parent 2d17ded commit efbfe3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/app/nodetool/qgsnodetool2.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmulticurve.h"
#include "qgsmultipoint.h"
#include "qgspointlocator.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
Expand Down Expand Up @@ -116,6 +117,21 @@ static bool isCircularVertex( const QgsGeometry &geom, int vertexIndex )
return geom.vertexIdFromVertexNr( vertexIndex, vid ) && vid.type == QgsVertexId::CurveVertex;
}


//! Create a multi-point geometry that can be used to highlight vertices of a feature
static QgsGeometry geometryToMultiPoint( const QgsGeometry &geom )
{
QgsMultiPointV2 *multiPoint = new QgsMultiPointV2();
QgsGeometry outputGeom( multiPoint );
QgsAbstractGeometry *g = geom.geometry();
for ( int i = 0; i < g->partCount(); ++i )
for ( int j = 0; j < g->ringCount( i ); ++j )
for ( int k = 0; k < g->vertexCount( i, j ); ++k )
multiPoint->addGeometry( new QgsPointV2( g->vertexAt( QgsVertexId( i, j, k ) ) ) );
return outputGeom;
}


//
// snapping match filters
//
Expand Down Expand Up @@ -200,6 +216,12 @@ QgsNodeTool2::QgsNodeTool2( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidge
mFeatureBand->setVisible( false );

QColor color = digitizingStrokeColor();
mFeatureBandMarkers = new QgsRubberBand( canvas );
mFeatureBandMarkers->setIcon( QgsRubberBand::ICON_CIRCLE );
mFeatureBandMarkers->setColor( color );
mFeatureBandMarkers->setIconSize( 8 );
mFeatureBandMarkers->setVisible( false );

mVertexBand = new QgsRubberBand( canvas );
mVertexBand->setIcon( QgsRubberBand::ICON_CIRCLE );
mVertexBand->setColor( color );
Expand All @@ -225,6 +247,7 @@ QgsNodeTool2::~QgsNodeTool2()
delete mSnapMarker;
delete mEdgeCenterMarker;
delete mFeatureBand;
delete mFeatureBandMarkers;
delete mVertexBand;
delete mEdgeBand;
delete mEndpointMarker;
Expand Down Expand Up @@ -556,6 +579,7 @@ void QgsNodeTool2::canvasDoubleClickEvent( QgsMapMouseEvent *e )
void QgsNodeTool2::removeTemporaryRubberBands()
{
mFeatureBand->setVisible( false );
mFeatureBandMarkers->setVisible( false );
mFeatureBandLayer = nullptr;
mFeatureBandFid = QgsFeatureId();
mVertexBand->setVisible( false );
Expand Down Expand Up @@ -773,6 +797,8 @@ void QgsNodeTool2::mouseMoveNotDragging( QgsMapMouseEvent *e )
if ( mFeatureBandLayer == m.layer() && mFeatureBandFid == m.featureId() )
return; // skip regeneration of rubber band if not needed
QgsGeometry geom = cachedGeometry( m.layer(), m.featureId() );
mFeatureBandMarkers->setToGeometry( geometryToMultiPoint( geom ), m.layer() );
mFeatureBandMarkers->setVisible( true );
if ( QgsWkbTypes::isCurvedType( geom.geometry()->wkbType() ) )
geom = QgsGeometry( geom.geometry()->segmentize() );
mFeatureBand->setToGeometry( geom, m.layer() );
Expand All @@ -783,6 +809,7 @@ void QgsNodeTool2::mouseMoveNotDragging( QgsMapMouseEvent *e )
else
{
mFeatureBand->setVisible( false );
mFeatureBandMarkers->setVisible( false );
mFeatureBandLayer = nullptr;
mFeatureBandFid = QgsFeatureId();
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/nodetool/qgsnodetool2.h
Expand Up @@ -198,6 +198,8 @@ class APP_EXPORT QgsNodeTool2 : 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
QgsRubberBand *mFeatureBandMarkers = nullptr;
//! source layer for mFeatureBand (null if mFeatureBand is null)
const QgsVectorLayer *mFeatureBandLayer = nullptr;
//! source feature id for mFeatureBand (zero if mFeatureBand is null)
Expand Down

0 comments on commit efbfe3b

Please sign in to comment.