Skip to content
Permalink
Browse files

nodetool: initialize select rubberband and fix indentation (fixes cra…

…sh on quit; see also PR#2433)
  • Loading branch information
jef-n committed Nov 8, 2015
1 parent 9d97c7c commit 1deaafc64c00b5b678d47e9784a521b5712cd383
Showing with 33 additions and 27 deletions.
  1. +33 −27 src/app/nodetool/qgsmaptoolnodetool.cpp
@@ -33,6 +33,7 @@

QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas )
: QgsMapToolEdit( canvas )
, mSelectRubberBand( 0 )
, mSelectedFeature( 0 )
, mNodeEditor( 0 )
, mMoving( true )
@@ -173,9 +174,9 @@ QgsFeature QgsMapToolNodeTool::getFeatureAtPoint( QgsMapMouseEvent* e )
{
QgsFeature feature;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( vlayer == NULL ) {
return feature;
}

if ( !vlayer )
return feature;

QgsFeatureRequest request;
request.setFilterRect( QgsRectangle( e->mapPoint().x(), e->mapPoint().y(), e->mapPoint().x(), e->mapPoint().y() ) );
@@ -204,18 +205,21 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
if ( snapResults.size() < 1 )
{
QgsFeature feature = getFeatureAtPoint( e );
if ( feature.geometry() == NULL ) {
emit messageEmitted(tr( "could not snap to a segment on the current layer." ) );
return;
if ( !feature.geometry() )
{
emit messageEmitted( tr( "could not snap to a segment on the current layer." ) );
return;
}
else {
// remove previous warning
emit messageDiscarded();
mSelectedFeature = new QgsSelectedFeature( feature.id(), vlayer, mCanvas );
updateSelectFeature();
else
{
// remove previous warning
emit messageDiscarded();
mSelectedFeature = new QgsSelectedFeature( feature.id(), vlayer, mCanvas );
updateSelectFeature();
}
}
else {
else
{
// remove previous warning
emit messageDiscarded();

@@ -339,24 +343,21 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
{
mSelectedFeature->deselectAllVertexes();

QgsFeature feature = getFeatureAtPoint( e );
if ( feature.geometry() == NULL ) {
return;
}
else {
mAnother = feature.id();
mSelectAnother = true;
}
QgsFeature feature = getFeatureAtPoint( e );
if ( !feature.geometry() )
return;

mAnother = feature.id();
mSelectAnother = true;
}
}
}
}

void QgsMapToolNodeTool::updateSelectFeature()
{
if (mSelectRubberBand != NULL) {
delete mSelectRubberBand;
}
delete mSelectRubberBand;

mSelectRubberBand = new QgsGeometryRubberBand( mCanvas, mSelectedFeature->geometry()->type() );
mSelectRubberBand->setBrushStyle( Qt::SolidPattern );
mSelectRubberBand->setFillColor( QColor( 255, 0, 0, 50 ) );
@@ -512,10 +513,12 @@ void QgsMapToolNodeTool::cleanTool( bool deleteSelectedFeature )
{
removeRubberBands();

if ( mSelectRubberBand != NULL ) {
if ( mSelectRubberBand )
{
delete mSelectRubberBand;
mSelectRubberBand = NULL;
mSelectRubberBand = 0;
}

if ( mSelectedFeature )
{
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
@@ -525,9 +528,12 @@ void QgsMapToolNodeTool::cleanTool( bool deleteSelectedFeature )
disconnect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
disconnect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );

if ( deleteSelectedFeature ) delete mSelectedFeature;
mSelectedFeature = NULL;
if ( deleteSelectedFeature )
delete mSelectedFeature;

mSelectedFeature = 0;
}

if ( mNodeEditor )
{
delete mNodeEditor;

0 comments on commit 1deaafc

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