Skip to content

Commit 7731674

Browse files
committed
add isActive to QgsMapTool and update cursor when it is active
1 parent b3e5263 commit 7731674

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

python/gui/auto_generated/qgsmaptool.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ the previously used toolbutton to pop out. *
116116
QAction *action();
117117
%Docstring
118118
Returns associated action with map tool or NULL if no action is associated
119+
%End
120+
121+
bool isActive() const;
122+
%Docstring
123+
Returns if the current map tool active on the map canvas
124+
125+
.. versionadded:: 3.4
119126
%End
120127

121128
void setButton( QAbstractButton *button );

src/gui/qgsmaptool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ QAction *QgsMapTool::action()
130130
return mAction;
131131
}
132132

133+
bool QgsMapTool::isActive() const
134+
{
135+
return mCanvas && mCanvas->mapTool() == this;
136+
}
137+
133138
void QgsMapTool::setButton( QAbstractButton *button )
134139
{
135140
mButton = button;
@@ -143,6 +148,8 @@ QAbstractButton *QgsMapTool::button()
143148
void QgsMapTool::setCursor( const QCursor &cursor )
144149
{
145150
mCursor = cursor;
151+
if ( isActive() )
152+
mCanvas->setCursor( mCursor );
146153
}
147154

148155

src/gui/qgsmaptool.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ class GUI_EXPORT QgsMapTool : public QObject
137137
//! Returns associated action with map tool or NULL if no action is associated
138138
QAction *action();
139139

140+
/**
141+
* Returns if the current map tool active on the map canvas
142+
* \since QGIS 3.4
143+
*/
144+
bool isActive() const;
145+
140146
/**
141147
* Use this to associate a button to this maptool. It has the same meaning
142148
* as setAction() function except it works with a button instead of an QAction. */

0 commit comments

Comments
 (0)