Skip to content
Permalink
Browse files
[api] Add method for PyQGIS QgsMapTool subclasses to set the tool name
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 57700196cde8b334d23b4889886c4c047fc0243c
Showing with 24 additions and 0 deletions.
  1. +11 −0 python/gui/auto_generated/qgsmaptool.sip.in
  2. +4 −0 src/gui/qgsmaptool.cpp
  3. +9 −0 src/gui/qgsmaptool.h
@@ -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

@@ -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




@@ -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()
{
@@ -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; }
@@ -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;

0 comments on commit 5770019

Please sign in to comment.