Skip to content

Commit

Permalink
[api] Add method for PyQGIS QgsMapTool subclasses to set the tool name
Browse files Browse the repository at this point in the history
Since PyQGIS can't access protected member variables, we need an
explicit setter for this variable.
  • Loading branch information
nyalldawson committed Jun 15, 2021
1 parent bb82807 commit 5770019
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/gui/auto_generated/qgsmaptool.sip.in
Expand Up @@ -170,6 +170,8 @@ returns pointer to the tool's map canvas
%Docstring
Emit map tool changed with the old tool

.. seealso:: :py:func:`setToolName`

.. versionadded:: 2.3
%End

Expand Down Expand Up @@ -305,6 +307,15 @@ Transforms a ``rect`` from map coordinates to ``layer`` coordinates.
Transforms a ``point`` from map coordinates to screen coordinates.
%End

void setToolName( const QString &name );
%Docstring
Sets the tool's ``name``.

.. seealso:: :py:func:`toolName`

.. versionadded:: 3.20
%End




Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmaptool.cpp
Expand Up @@ -76,6 +76,10 @@ QPoint QgsMapTool::toCanvasCoordinates( const QgsPointXY &point ) const
return QPoint( std::round( x ), std::round( y ) );
}

void QgsMapTool::setToolName( const QString &name )
{
mToolName = name;
}

void QgsMapTool::activate()
{
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsmaptool.h
Expand Up @@ -176,6 +176,7 @@ class GUI_EXPORT QgsMapTool : public QObject

/**
* Emit map tool changed with the old tool
* \see setToolName()
* \since QGIS 2.3
*/
QString toolName() { return mToolName; }
Expand Down Expand Up @@ -284,6 +285,14 @@ class GUI_EXPORT QgsMapTool : public QObject
//! Transforms a \a point from map coordinates to screen coordinates.
QPoint toCanvasCoordinates( const QgsPointXY &point ) const;

/**
* Sets the tool's \a name.
*
* \see toolName()
* \since QGIS 3.20
*/
void setToolName( const QString &name );

//! The pointer to the map canvas
QgsMapCanvas *mCanvas = nullptr;

Expand Down

0 comments on commit 5770019

Please sign in to comment.