Skip to content

Commit d3fcdb4

Browse files
committedMay 2, 2016
[FEATURE] Support single click to select with freehand select tool
This brings the behaviour of the freehand select into line with the select by rectangle tool, which allows clicks without drag to select a single feature. (fix #14747)
1 parent 70adf26 commit d3fcdb4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
 

‎src/app/qgsmaptoolselectfreehand.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,29 @@ void QgsMapToolSelectFreehand::canvasReleaseEvent( QgsMapMouseEvent* e )
6868
if ( !mRubberBand )
6969
return;
7070

71+
bool singleSelect = false;
72+
if ( mRubberBand->numberOfVertices() > 0 && mRubberBand->numberOfVertices() <= 2 )
73+
{
74+
// single click, not drag - create a rectangle around clicked point
75+
QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas );
76+
if ( vlayer )
77+
{
78+
QRect selectRect;
79+
QgsMapToolSelectUtils::expandSelectRectangle( selectRect, vlayer, e->pos() );
80+
QgsMapToolSelectUtils::setRubberBand( mCanvas, selectRect, mRubberBand );
81+
singleSelect = true;
82+
}
83+
}
84+
7185
if ( mRubberBand->numberOfVertices() > 2 )
7286
{
7387
QgsGeometry* shapeGeom = mRubberBand->asGeometry();
74-
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, shapeGeom, e );
88+
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, shapeGeom,
89+
e->modifiers() & Qt::ShiftModifier,
90+
e->modifiers() & Qt::ControlModifier, singleSelect );
7591
delete shapeGeom;
7692
}
93+
7794
mRubberBand->reset( QGis::Polygon );
7895
delete mRubberBand;
7996
mRubberBand = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.