Skip to content

Commit

Permalink
Highlight the selected feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 7, 2015
1 parent 580f70a commit d73ef5b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -212,13 +212,15 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
// remove previous warning
emit messageDiscarded();
mSelectedFeature = new QgsSelectedFeature( feature.id(), vlayer, mCanvas );
updateSelectFeature();
}
}
else {
// remove previous warning
emit messageDiscarded();

mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
updateSelectFeature();
}
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
Expand Down Expand Up @@ -350,6 +352,21 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
}
}

void QgsMapToolNodeTool::updateSelectFeature()
{
if (mSelectRubberBand != NULL) {
delete mSelectRubberBand;
}
mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );
mSelectRubberBand->setFillColor( QColor( 255, 0, 0, 50 ) );
QgsAbstractGeometryV2* rbGeom = mSelectedFeature->geometry()->geometry()->clone();
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
if ( mCanvas->mapSettings().layerTransform( vlayer ) )
rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) );
mSelectRubberBand->setGeometry( rbGeom );
}

void QgsMapToolNodeTool::selectedFeatureDestroyed()
{
QgsDebugCall;
Expand Down Expand Up @@ -396,6 +413,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
{
// select another feature
mSelectedFeature->setSelectedFeature( mAnother, vlayer, mCanvas );
updateSelectFeature();
mIsPoint = vlayer->geometryType() == QGis::Point;
mSelectAnother = false;
}
Expand Down Expand Up @@ -494,6 +512,10 @@ void QgsMapToolNodeTool::cleanTool( bool deleteSelectedFeature )
{
removeRubberBands();

if ( mSelectRubberBand != NULL ) {
delete mSelectRubberBand;
mSelectRubberBand = NULL;
}
if ( mSelectedFeature )
{
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
Expand All @@ -504,7 +526,7 @@ void QgsMapToolNodeTool::cleanTool( bool deleteSelectedFeature )
disconnect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );

if ( deleteSelectedFeature ) delete mSelectedFeature;
mSelectedFeature = 0;
mSelectedFeature = NULL;
}
if ( mNodeEditor )
{
Expand Down
8 changes: 8 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Expand Up @@ -66,6 +66,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
*/
QgsFeature getFeatureAtPoint( QgsMapMouseEvent* e );

/**
* Update select feature rubber band
*/
void updateSelectFeature();

/**
* Deletes the rubber band pointers and clears mRubberBands
*/
Expand Down Expand Up @@ -121,6 +126,9 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
/** Rubber bands during node move */
QMap<QgsFeatureId, QgsGeometryRubberBand*> mMoveRubberBands;

/** Rubber band for selected feature */
QgsGeometryRubberBand* mSelectRubberBand;

/** Vertices of features to move */
QMap<QgsFeatureId, QList< QPair<QgsVertexId, QgsPointV2> > > mMoveVertices;

Expand Down

1 comment on commit d73ef5b

@oper4
Copy link

@oper4 oper4 commented on d73ef5b Nov 8, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

I'm the author of "bug" report (https://hub.qgis.org/issues/13793) - maybe it wolud be better in case of polygons just to show "semitransparent red" outline?
That's my point of view against "red semitransparent background" - when I edit common boundary of two polygons (snapping options/enable topological editing) using Node tool now only one of them has that red background - so it's weird. Second thing - during editing if I move the feature I still see its old position as a red trace... it's on screencast:
https://www.dropbox.com/s/o9ixhygs87jb2v2/clip4.mp4?dl=0

Currently all the time I digitize sth from rasters and wms's - that's why all my polygon layers have transparent background - and now it's useless to use Node tool as it appears sth on the screen.

Thanks

Piotr Kania

Please sign in to comment.