Skip to content

Commit

Permalink
add isActive to QgsMapTool and update cursor when it is active
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Oct 19, 2018
1 parent b3e5263 commit 7731674
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsmaptool.sip.in
Expand Up @@ -116,6 +116,13 @@ the previously used toolbutton to pop out. *
QAction *action();
%Docstring
Returns associated action with map tool or NULL if no action is associated
%End

bool isActive() const;
%Docstring
Returns if the current map tool active on the map canvas

.. versionadded:: 3.4
%End

void setButton( QAbstractButton *button );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmaptool.cpp
Expand Up @@ -130,6 +130,11 @@ QAction *QgsMapTool::action()
return mAction;
}

bool QgsMapTool::isActive() const
{
return mCanvas && mCanvas->mapTool() == this;
}

void QgsMapTool::setButton( QAbstractButton *button )
{
mButton = button;
Expand All @@ -143,6 +148,8 @@ QAbstractButton *QgsMapTool::button()
void QgsMapTool::setCursor( const QCursor &cursor )
{
mCursor = cursor;
if ( isActive() )
mCanvas->setCursor( mCursor );
}


Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmaptool.h
Expand Up @@ -137,6 +137,12 @@ class GUI_EXPORT QgsMapTool : public QObject
//! Returns associated action with map tool or NULL if no action is associated
QAction *action();

/**
* Returns if the current map tool active on the map canvas
* \since QGIS 3.4
*/
bool isActive() const;

/**
* Use this to associate a button to this maptool. It has the same meaning
* as setAction() function except it works with a button instead of an QAction. */
Expand Down

0 comments on commit 7731674

Please sign in to comment.