Skip to content

Commit 263beb4

Browse files
committed
Fix crash in Select by Radius
If a radius value is entered immediately after clicking with the tool (before any mouse movement), it would trigger a crash (cherry-picked from 9e01a04)
1 parent b8c7305 commit 263beb4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/app/qgsmaptoolselectradius.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ void QgsMapToolSelectRadius::canvasMoveEvent( QgsMapMouseEvent *e )
124124

125125
if ( !mRubberBand )
126126
{
127-
mRubberBand = qgis::make_unique< QgsRubberBand >( mCanvas, QgsWkbTypes::PolygonGeometry );
128-
mRubberBand->setFillColor( mFillColor );
129-
mRubberBand->setStrokeColor( mStrokeColor );
127+
createRubberBand();
130128
}
131129

132130
updateRadiusFromEdge( radiusEdge );
@@ -156,9 +154,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QgsMapMouseEvent *e )
156154
{
157155
if ( !mRubberBand )
158156
{
159-
mRubberBand = qgis::make_unique< QgsRubberBand >( mCanvas, QgsWkbTypes::PolygonGeometry );
160-
mRubberBand->setFillColor( mFillColor );
161-
mRubberBand->setStrokeColor( mStrokeColor );
157+
createRubberBand();
162158
}
163159
QgsPointXY radiusEdge = e->snapPoint();
164160
updateRadiusFromEdge( radiusEdge );
@@ -205,6 +201,9 @@ void QgsMapToolSelectRadius::keyReleaseEvent( QKeyEvent *e )
205201

206202
void QgsMapToolSelectRadius::updateRubberband( const double &radius )
207203
{
204+
if ( !mRubberBand )
205+
createRubberBand();
206+
208207
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
209208
for ( int i = 0; i <= RADIUS_SEGMENTS; ++i )
210209
{
@@ -262,6 +261,13 @@ void QgsMapToolSelectRadius::createRotationWidget()
262261
connect( mDistanceWidget, &QgsDistanceWidget::distanceEditingCanceled, this, &QgsMapToolSelectRadius::cancel );
263262
}
264263

264+
void QgsMapToolSelectRadius::createRubberBand()
265+
{
266+
mRubberBand = qgis::make_unique< QgsRubberBand >( mCanvas, QgsWkbTypes::PolygonGeometry );
267+
mRubberBand->setFillColor( mFillColor );
268+
mRubberBand->setStrokeColor( mStrokeColor );
269+
}
270+
265271
void QgsMapToolSelectRadius::deleteRotationWidget()
266272
{
267273
if ( mDistanceWidget )

src/app/qgsmaptoolselectradius.h

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class APP_EXPORT QgsMapToolSelectRadius : public QgsMapTool
103103
void deleteRotationWidget();
104104
void createRotationWidget();
105105

106+
void createRubberBand();
107+
106108
//! used for storing all of the maps point for the polygon
107109
std::unique_ptr< QgsRubberBand > mRubberBand;
108110
std::unique_ptr<QgsSnapIndicator> mSnapIndicator;

0 commit comments

Comments
 (0)