File: qgsabstractmaptoolhandler.sip.in

package info (click to toggle)
qgis 3.22.16%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,186,020 kB
  • sloc: cpp: 1,275,562; python: 194,091; xml: 15,597; perl: 3,471; sh: 3,368; sql: 2,485; ansic: 2,219; yacc: 1,056; lex: 574; javascript: 504; lisp: 411; makefile: 227
file content (115 lines) | stat: -rw-r--r-- 3,880 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/************************************************************************
 * This file has been generated automatically from                      *
 *                                                                      *
 * src/gui/qgsabstractmaptoolhandler.h                                  *
 *                                                                      *
 * Do not edit manually ! Edit header and run scripts/sipify.pl again   *
 ************************************************************************/




class QgsAbstractMapToolHandler
{
%Docstring(signature="appended")
An abstract base class for map tool handlers which automatically handle all the necessary
logic for toggling the map tool and enabling/disabling the associated action
when the QGIS application is in a state permissible for the tool.

Creating these handlers avoids a lot of complex setup code and manual connections
which are otherwise necessary to ensure that a map tool is correctly activated and
deactivated when the state of the QGIS application changes (e.g. when the active
layer is changed, when edit modes are toggled, when other map tools are switched
to, etc).

- ### Example

.. code-block:: python

       class MyMapTool(QgsMapTool):
          ...

       class MyMapToolHandler(QgsAbstractMapToolHandler):

          def __init__(self, tool, action):
              super().__init__(tool, action)

          def isCompatibleWithLayer(self, layer, context):
              # this tool can only be activated when an editable vector layer is selected
              return isinstance(layer, QgsVectorLayer) and layer.isEditable()

       my_tool = MyMapTool()
       my_action = QAction('My Map Tool')

       my_handler = MyMapToolHandler(my_tool, my_action)
       iface.registerMapToolHandler(my_handler)

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsabstractmaptoolhandler.h"
%End
  public:

    struct Context
    {
      bool dummy;
    };

    QgsAbstractMapToolHandler( QgsMapTool *tool, QAction *action );
%Docstring
Constructor for a map tool handler for the specified ``tool``.

The ``action`` argument must be set to the action associated with switching
to the tool.

The ownership of neither ``tool`` nor ``action`` is transferred, and the caller
is responsible for ensuring that these objects exist for the lifetime of the
handler.

.. warning::

   The handler will be responsible for creating the appropriate
   connections between the ``action`` and the ``tool``. These should NOT be
   manually connected elsewhere!
%End

    virtual ~QgsAbstractMapToolHandler();

    QgsMapTool *mapTool();
%Docstring
Returns the tool associated with this handler.
%End

    QAction *action();
%Docstring
Returns the action associated with toggling the tool.
%End

    virtual bool isCompatibleWithLayer( QgsMapLayer *layer, const QgsAbstractMapToolHandler::Context &context ) = 0;
%Docstring
Returns ``True`` if the associated map tool is compatible with the specified ``layer``.

Additional information is available through the ``context`` argument.
%End

    virtual void setLayerForTool( QgsMapLayer *layer );
%Docstring
Sets the ``layer`` to use for the tool.

Called whenever a new layer should be associated with the tool, e.g. as a result of the
user selecting a different active layer.

The default implementation does nothing.
%End

};

/************************************************************************
 * This file has been generated automatically from                      *
 *                                                                      *
 * src/gui/qgsabstractmaptoolhandler.h                                  *
 *                                                                      *
 * Do not edit manually ! Edit header and run scripts/sipify.pl again   *
 ************************************************************************/