Skip to content

Commit

Permalink
Fix crash in Select by Radius
Browse files Browse the repository at this point in the history
If a radius value is entered immediately after clicking with the
tool (before any mouse movement), it would trigger a crash
  • Loading branch information
nyalldawson committed Mar 16, 2018
1 parent dc0da6f commit 9e01a04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/app/qgsmaptoolselectradius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ void QgsMapToolSelectRadius::canvasMoveEvent( QgsMapMouseEvent *e )

if ( !mRubberBand )
{
mRubberBand = qgis::make_unique< QgsRubberBand >( mCanvas, QgsWkbTypes::PolygonGeometry );
mRubberBand->setFillColor( mFillColor );
mRubberBand->setStrokeColor( mStrokeColor );
createRubberBand();
}

updateRadiusFromEdge( radiusEdge );
Expand Down Expand Up @@ -156,9 +154,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QgsMapMouseEvent *e )
{
if ( !mRubberBand )
{
mRubberBand = qgis::make_unique< QgsRubberBand >( mCanvas, QgsWkbTypes::PolygonGeometry );
mRubberBand->setFillColor( mFillColor );
mRubberBand->setStrokeColor( mStrokeColor );
createRubberBand();
}
QgsPointXY radiusEdge = e->snapPoint();
updateRadiusFromEdge( radiusEdge );
Expand Down Expand Up @@ -205,6 +201,9 @@ void QgsMapToolSelectRadius::keyReleaseEvent( QKeyEvent *e )

void QgsMapToolSelectRadius::updateRubberband( const double &radius )
{
if ( !mRubberBand )
createRubberBand();

mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
for ( int i = 0; i <= RADIUS_SEGMENTS; ++i )
{
Expand Down Expand Up @@ -262,6 +261,13 @@ void QgsMapToolSelectRadius::createRotationWidget()
connect( mDistanceWidget, &QgsDistanceWidget::distanceEditingCanceled, this, &QgsMapToolSelectRadius::cancel );
}

void QgsMapToolSelectRadius::createRubberBand()
{
mRubberBand = qgis::make_unique< QgsRubberBand >( mCanvas, QgsWkbTypes::PolygonGeometry );
mRubberBand->setFillColor( mFillColor );
mRubberBand->setStrokeColor( mStrokeColor );
}

void QgsMapToolSelectRadius::deleteRotationWidget()
{
if ( mDistanceWidget )
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsmaptoolselectradius.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class APP_EXPORT QgsMapToolSelectRadius : public QgsMapTool
void deleteRotationWidget();
void createRotationWidget();

void createRubberBand();

//! used for storing all of the maps point for the polygon
std::unique_ptr< QgsRubberBand > mRubberBand;
std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
Expand Down

0 comments on commit 9e01a04

Please sign in to comment.