Skip to content

Commit adec719

Browse files
authored
allow switching in/out mode while drawing zooming rect (#8261)
1 parent 8d7c54e commit adec719

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/gui/qgsmaptoolzoom.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas *canvas, bool zoomOut )
3838

3939
{
4040
mToolName = tr( "Zoom" );
41-
updateCursor();
41+
setZoomMode( mNativeZoomOut, true );
4242
}
4343

4444
QgsMapToolZoom::~QgsMapToolZoom()
@@ -52,6 +52,8 @@ void QgsMapToolZoom::canvasMoveEvent( QgsMapMouseEvent *e )
5252
if ( !( e->buttons() & Qt::LeftButton ) )
5353
return;
5454

55+
setZoomMode( e->modifiers().testFlag( Qt::AltModifier ) ^ mNativeZoomOut );
56+
5557
if ( !mDragging )
5658
{
5759
mDragging = true;
@@ -62,6 +64,7 @@ void QgsMapToolZoom::canvasMoveEvent( QgsMapMouseEvent *e )
6264
mRubberBand->setColor( color );
6365
mZoomRect.setTopLeft( e->pos() );
6466
}
67+
6568
mZoomRect.setBottomRight( e->pos() );
6669
if ( mRubberBand )
6770
{
@@ -85,6 +88,8 @@ void QgsMapToolZoom::canvasReleaseEvent( QgsMapMouseEvent *e )
8588
if ( e->button() != Qt::LeftButton )
8689
return;
8790

91+
setZoomMode( e->modifiers().testFlag( Qt::AltModifier ) ^ mNativeZoomOut );
92+
8893
// We are not really dragging in this case. This is sometimes caused by
8994
// a pen based computer reporting a press, move, and release, all the
9095
// one point.
@@ -136,30 +141,30 @@ void QgsMapToolZoom::deactivate()
136141
QgsMapTool::deactivate();
137142
}
138143

139-
void QgsMapToolZoom::updateCursor()
144+
void QgsMapToolZoom::setZoomMode( bool zoomOut, bool force )
140145
{
146+
if ( !force && zoomOut == mZoomOut )
147+
return;
148+
149+
mZoomOut = zoomOut;
141150
setCursor( mZoomOut ? mZoomOutCursor : mZoomInCursor );
142151
}
143152

144153
void QgsMapToolZoom::keyPressEvent( QKeyEvent *e )
145154
{
146155
if ( e->key() == Qt::Key_Alt )
147156
{
148-
mZoomOut = !mZoomOut;
149-
updateCursor();
157+
setZoomMode( !mNativeZoomOut );
150158
}
151159
}
152160

153161
void QgsMapToolZoom::keyReleaseEvent( QKeyEvent *e )
154162
{
155163
// key press events are not caught wile the mouse is pressed
156-
// so we can't mess if we are already dragging
157-
// we need to go back to native state, as it cannot be determine
158-
// (since the press event is not detected while mouse is pressed)
164+
// this is detected in map canvas move event
159165

160166
if ( e->key() == Qt::Key_Alt )
161167
{
162-
mZoomOut = mNativeZoomOut;
163-
updateCursor();
168+
setZoomMode( mNativeZoomOut );
164169
}
165170
}

src/gui/qgsmaptoolzoom.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
6464
QCursor mZoomInCursor;
6565

6666
private:
67-
void updateCursor();
67+
void setZoomMode( bool zoomOut, bool force = false );
6868
};
6969

7070
#endif

0 commit comments

Comments
 (0)