Skip to content

Commit b33b935

Browse files
dgoedkoop3nids
authored andcommitted
Update rubber band after editing nodes
It has to be done this way. Just adding updateSelectFeature() in a few places is not enough, because then the rubber band will still not be updated after an undo operation.
1 parent b0bbfc7 commit b33b935

File tree

4 files changed

+68
-19
lines changed

4 files changed

+68
-19
lines changed

src/app/nodetool/qgsmaptoolnodetool.cpp

+47-19
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ void QgsMapToolNodeTool::canvasMoveEvent( QgsMapMouseEvent* e )
121121
{
122122
if ( mMoveRubberBands.empty() )
123123
{
124+
QSettings settings;
125+
bool ghostLine = settings.value( "/qgis/digitizing/line_ghost", false ).toBool();
126+
if ( !ghostLine )
127+
{
128+
delete mSelectRubberBand;
129+
mSelectRubberBand = nullptr;
130+
}
124131
QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
125132
QSettings settings;
126133
QColor color(
@@ -242,6 +249,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
242249
}
243250
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
244251
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
252+
connect( vlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
245253
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
246254
mIsPoint = vlayer->geometryType() == QGis::Point;
247255
mNodeEditor = new QgsNodeEditor( vlayer, mSelectedFeature, mCanvas );
@@ -370,25 +378,37 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
370378

371379
void QgsMapToolNodeTool::updateSelectFeature()
372380
{
373-
delete mSelectRubberBand;
381+
updateSelectFeature( *mSelectedFeature->geometry() );
382+
}
374383

375-
mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
376-
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );
384+
void QgsMapToolNodeTool::updateSelectFeature( QgsGeometry &geom )
385+
{
386+
delete mSelectRubberBand;
377387

378-
QSettings settings;
379-
QColor color(
380-
settings.value( "/qgis/digitizing/fill_color_red", 255 ).toInt(),
381-
settings.value( "/qgis/digitizing/fill_color_green", 0 ).toInt(),
382-
settings.value( "/qgis/digitizing/fill_color_blue", 0 ).toInt() );
383-
double myAlpha = settings.value( "/qgis/digitizing/fill_color_alpha", 30 ).toInt() / 255.0 ;
384-
color.setAlphaF( myAlpha );
385-
mSelectRubberBand->setFillColor( color );
386-
387-
QgsAbstractGeometryV2* rbGeom = mSelectedFeature->geometry()->geometry()->clone();
388-
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
389-
if ( mCanvas->mapSettings().layerTransform( vlayer ) )
390-
rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) );
391-
mSelectRubberBand->setGeometry( rbGeom );
388+
if ( geom.geometry() )
389+
{
390+
mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
391+
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );
392+
393+
QSettings settings;
394+
QColor color(
395+
settings.value( "/qgis/digitizing/fill_color_red", 255 ).toInt(),
396+
settings.value( "/qgis/digitizing/fill_color_green", 0 ).toInt(),
397+
settings.value( "/qgis/digitizing/fill_color_blue", 0 ).toInt() );
398+
double myAlpha = settings.value( "/qgis/digitizing/fill_color_alpha", 30 ).toInt() / 255.0 ;
399+
color.setAlphaF( myAlpha );
400+
mSelectRubberBand->setFillColor( color );
401+
402+
QgsAbstractGeometryV2* rbGeom = geom.geometry()->clone();
403+
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
404+
if ( mCanvas->mapSettings().layerTransform( vlayer ) )
405+
rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) );
406+
mSelectRubberBand->setGeometry( rbGeom );
407+
}
408+
else
409+
{
410+
mSelectRubberBand = nullptr;
411+
}
392412
}
393413

394414
void QgsMapToolNodeTool::selectedFeatureDestroyed()
@@ -397,6 +417,16 @@ void QgsMapToolNodeTool::selectedFeatureDestroyed()
397417
cleanTool( false );
398418
}
399419

420+
void QgsMapToolNodeTool::geometryChanged( QgsFeatureId fid, QgsGeometry &geom )
421+
{
422+
QSettings settings;
423+
bool ghostLine = settings.value( "/qgis/digitizing/line_ghost", false ).toBool();
424+
if ( !ghostLine && mSelectedFeature && ( mSelectedFeature->featureId() == fid ) )
425+
{
426+
updateSelectFeature( geom );
427+
}
428+
}
429+
400430
void QgsMapToolNodeTool::currentLayerChanged( QgsMapLayer *layer )
401431
{
402432
if ( mSelectedFeature && layer != mSelectedFeature->vlayer() )
@@ -512,8 +542,6 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
512542

513543
mDeselectOnRelease = -1;
514544
}
515-
516-
updateSelectFeature();
517545
}
518546

519547
void QgsMapToolNodeTool::deactivate()

src/app/nodetool/qgsmaptoolnodetool.h

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
5050
public slots:
5151
void selectedFeatureDestroyed();
5252

53+
/*
54+
* the geometry for the selected feature has changed
55+
*/
56+
void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
57+
5358
/*
5459
* the current layer changed
5560
*/
@@ -71,6 +76,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
7176
*/
7277
void updateSelectFeature();
7378

79+
/**
80+
* Update select feature rubber band using a certain geometry
81+
*/
82+
void updateSelectFeature( QgsGeometry &geom );
83+
7484
/**
7585
* Deletes the rubber band pointers and clears mRubberBands
7686
*/

src/app/qgsoptions.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
804804
mFillColorToolButton->setContext( "gui" );
805805
mFillColorToolButton->setDefaultColor( QColor( 255, 0, 0, 30 ) );
806806

807+
mLineGhostCheckBox->setChecked( settings.value( "/qgis/digitizing/line_ghost", false ).toBool() );
808+
807809
//default snap mode
808810
mDefaultSnapModeComboBox->insertItem( 0, tr( "To vertex" ), "to vertex" );
809811
mDefaultSnapModeComboBox->insertItem( 1, tr( "To segment" ), "to segment" );
@@ -1305,6 +1307,8 @@ void QgsOptions::saveOptions()
13051307
mSettings->setValue( "/qgis/digitizing/fill_color_blue", digitizingColor.blue() );
13061308
mSettings->setValue( "/qgis/digitizing/fill_color_alpha", digitizingColor.alpha() );
13071309

1310+
settings.setValue( "/qgis/digitizing/line_ghost", mLineGhostCheckBox->isChecked() );
1311+
13081312
//default snap mode
13091313
QString defaultSnapModeString = mDefaultSnapModeComboBox->itemData( mDefaultSnapModeComboBox->currentIndex() ).toString();
13101314
mSettings->setValue( "/qgis/digitizing/default_snap_mode", defaultSnapModeString );

src/ui/qgsoptionsbase.ui

+7
Original file line numberDiff line numberDiff line change
@@ -3670,6 +3670,13 @@
36703670
</property>
36713671
</widget>
36723672
</item>
3673+
<item row="1" column="0" colspan="7">
3674+
<widget class="QCheckBox" name="mLineGhostCheckBox">
3675+
<property name="text">
3676+
<string>Don't update rubber band during node editing</string>
3677+
</property>
3678+
</widget>
3679+
</item>
36733680
</layout>
36743681
</widget>
36753682
</item>

0 commit comments

Comments
 (0)