QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsmaptoolshaperegistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolshaperegistry.cpp
3 ----------------------
4 begin : January 2022
5 copyright : (C) 2022 by Denis Rouzaud
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20
22{
23}
24
26{
27 qDeleteAll( mMapTools );
28 mMapTools.clear();
29}
30
32{
33 if ( !mapTool )
34 return;
35
36 if ( mapToolMetadata( mapTool->id() ) )
37 return;
38
39 mMapTools.append( mapTool );
40}
41
43{
44 QList<QgsMapToolShapeMetadata *>::iterator it = mMapTools.begin();
45 while ( it != mMapTools.end() )
46 {
47 if ( ( *it )->id() == id )
48 {
49 delete *it;
50 it = mMapTools.erase( it );
51 }
52 else
53 {
54 ++it;
55 }
56 }
57}
58
60{
61 for ( QgsMapToolShapeMetadata *md : std::as_const( mMapTools ) )
62 {
63 if ( md->id() == id )
64 return md;
65 }
66
67 return nullptr;
68}
69
71{
73 if ( !md )
74 return nullptr;
75
76 return md->factory( parentTool );
77}
QgsMapToolCapture is a base class capable of capturing point, lines and polygons.
QgsMapToolShapeAbstract is a base class for shape map tools to be used by QgsMapToolCapture.
QString id() const
Returns the id of the shape tool (equivalent to the one from the metadata)
QgsMapToolShapeMetadata is a base class for shape map tools metadata to be used in QgsMapToolShapeReg...
virtual QgsMapToolShapeAbstract * factory(QgsMapToolCapture *parentlTool) const SIP_FACTORY=0
Creates the shape map tool for the given parentTool Caller takes ownership of the returned object.
QgsMapToolShapeAbstract * mapTool(const QString &id, QgsMapToolCapture *parentTool) const SIP_FACTORY
Constructs the map tool at the given id for the given parentTool Caller takes ownership of the return...
void addMapTool(QgsMapToolShapeMetadata *mapTool SIP_TRANSFER)
Adds a new shape map tool.
void removeMapTool(const QString &id)
Removes a registered map tool at the given id The tool will be deleted.
QgsMapToolShapeMetadata * mapToolMetadata(const QString &id) const
Returns the map tool metadata for the given id.