QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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#include "moc_qgsmaptoolshaperegistry.cpp"
20
21
25
27{
28 qDeleteAll( mMapTools );
29 mMapTools.clear();
30}
31
33{
34 if ( !mapTool )
35 return;
36
37 if ( mapToolMetadata( mapTool->id() ) )
38 return;
39
40 mMapTools.append( mapTool );
41}
42
44{
45 QList<QgsMapToolShapeMetadata *>::iterator it = mMapTools.begin();
46 while ( it != mMapTools.end() )
47 {
48 if ( ( *it )->id() == id )
49 {
50 delete *it;
51 it = mMapTools.erase( it );
52 }
53 else
54 {
55 ++it;
56 }
57 }
58}
59
61{
62 for ( QgsMapToolShapeMetadata *md : std::as_const( mMapTools ) )
63 {
64 if ( md->id() == id )
65 return md;
66 }
67
68 return nullptr;
69}
70
72{
74 if ( !md )
75 return nullptr;
76
77 return md->factory( parentTool );
78}
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 =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
Constructs the map tool at the given id for the given parentTool Caller takes ownership of the return...
void removeMapTool(const QString &id)
Removes a registered map tool at the given id The tool will be deleted.
void addMapTool(QgsMapToolShapeMetadata *mapTool)
Adds a new shape map tool.
QgsMapToolShapeMetadata * mapToolMetadata(const QString &id) const
Returns the map tool metadata for the given id.