Skip to content
Permalink
Browse files

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.
  • Loading branch information
dgoedkoop authored and 3nids committed Nov 28, 2015
1 parent b0bbfc7 commit b33b9351f75eaafb23f2a2909f931a07dab19524
@@ -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(
@@ -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 );
@@ -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()
@@ -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() )
@@ -512,8 +542,6 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )

mDeselectOnRelease = -1;
}

updateSelectFeature();
}

void QgsMapToolNodeTool::deactivate()
@@ -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
*/
@@ -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
*/
@@ -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" );
@@ -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 );
@@ -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>

0 comments on commit b33b935

Please sign in to comment.
You can’t perform that action at this time.