Skip to content

Commit

Permalink
Update rubber band after editing nodes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgoedkoop authored and 3nids committed Dec 23, 2015
1 parent b0bbfc7 commit b33b935
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
66 changes: 47 additions & 19 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -121,6 +121,13 @@ void QgsMapToolNodeTool::canvasMoveEvent( QgsMapMouseEvent* e )
{
if ( mMoveRubberBands.empty() )
{
QSettings settings;
bool ghostLine = settings.value( "/qgis/digitizing/line_ghost", false ).toBool();
if ( !ghostLine )
{
delete mSelectRubberBand;
mSelectRubberBand = nullptr;
}
QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
QSettings settings;
QColor color(
Expand Down Expand Up @@ -242,6 +249,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
}
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
connect( vlayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry & ) ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
mIsPoint = vlayer->geometryType() == QGis::Point;
mNodeEditor = new QgsNodeEditor( vlayer, mSelectedFeature, mCanvas );
Expand Down Expand Up @@ -370,25 +378,37 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )

void QgsMapToolNodeTool::updateSelectFeature()
{
delete mSelectRubberBand;
updateSelectFeature( *mSelectedFeature->geometry() );
}

mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );
void QgsMapToolNodeTool::updateSelectFeature( QgsGeometry &geom )
{
delete mSelectRubberBand;

QSettings settings;
QColor color(
settings.value( "/qgis/digitizing/fill_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/fill_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/fill_color_blue", 0 ).toInt() );
double myAlpha = settings.value( "/qgis/digitizing/fill_color_alpha", 30 ).toInt() / 255.0 ;
color.setAlphaF( myAlpha );
mSelectRubberBand->setFillColor( color );

QgsAbstractGeometryV2* rbGeom = mSelectedFeature->geometry()->geometry()->clone();
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
if ( mCanvas->mapSettings().layerTransform( vlayer ) )
rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) );
mSelectRubberBand->setGeometry( rbGeom );
if ( geom.geometry() )
{
mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );

QSettings settings;
QColor color(
settings.value( "/qgis/digitizing/fill_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/fill_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/fill_color_blue", 0 ).toInt() );
double myAlpha = settings.value( "/qgis/digitizing/fill_color_alpha", 30 ).toInt() / 255.0 ;
color.setAlphaF( myAlpha );
mSelectRubberBand->setFillColor( color );

QgsAbstractGeometryV2* rbGeom = geom.geometry()->clone();
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
if ( mCanvas->mapSettings().layerTransform( vlayer ) )
rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) );
mSelectRubberBand->setGeometry( rbGeom );
}
else
{
mSelectRubberBand = nullptr;
}
}

void QgsMapToolNodeTool::selectedFeatureDestroyed()
Expand All @@ -397,6 +417,16 @@ void QgsMapToolNodeTool::selectedFeatureDestroyed()
cleanTool( false );
}

void QgsMapToolNodeTool::geometryChanged( QgsFeatureId fid, QgsGeometry &geom )
{
QSettings settings;
bool ghostLine = settings.value( "/qgis/digitizing/line_ghost", false ).toBool();
if ( !ghostLine && mSelectedFeature && ( mSelectedFeature->featureId() == fid ) )
{
updateSelectFeature( geom );
}
}

void QgsMapToolNodeTool::currentLayerChanged( QgsMapLayer *layer )
{
if ( mSelectedFeature && layer != mSelectedFeature->vlayer() )
Expand Down Expand Up @@ -512,8 +542,6 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )

mDeselectOnRelease = -1;
}

updateSelectFeature();
}

void QgsMapToolNodeTool::deactivate()
Expand Down
10 changes: 10 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Expand Up @@ -50,6 +50,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
public slots:
void selectedFeatureDestroyed();

/*
* the geometry for the selected feature has changed
*/
void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );

/*
* the current layer changed
*/
Expand All @@ -71,6 +76,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
*/
void updateSelectFeature();

/**
* Update select feature rubber band using a certain geometry
*/
void updateSelectFeature( QgsGeometry &geom );

/**
* Deletes the rubber band pointers and clears mRubberBands
*/
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -804,6 +804,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
mFillColorToolButton->setContext( "gui" );
mFillColorToolButton->setDefaultColor( QColor( 255, 0, 0, 30 ) );

mLineGhostCheckBox->setChecked( settings.value( "/qgis/digitizing/line_ghost", false ).toBool() );

//default snap mode
mDefaultSnapModeComboBox->insertItem( 0, tr( "To vertex" ), "to vertex" );
mDefaultSnapModeComboBox->insertItem( 1, tr( "To segment" ), "to segment" );
Expand Down Expand Up @@ -1305,6 +1307,8 @@ void QgsOptions::saveOptions()
mSettings->setValue( "/qgis/digitizing/fill_color_blue", digitizingColor.blue() );
mSettings->setValue( "/qgis/digitizing/fill_color_alpha", digitizingColor.alpha() );

settings.setValue( "/qgis/digitizing/line_ghost", mLineGhostCheckBox->isChecked() );

//default snap mode
QString defaultSnapModeString = mDefaultSnapModeComboBox->itemData( mDefaultSnapModeComboBox->currentIndex() ).toString();
mSettings->setValue( "/qgis/digitizing/default_snap_mode", defaultSnapModeString );
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -3670,6 +3670,13 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="7">
<widget class="QCheckBox" name="mLineGhostCheckBox">
<property name="text">
<string>Don't update rubber band during node editing</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit b33b935

Please sign in to comment.