QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
6  email : [email protected]
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 
42 void QgsMapToolShapeRegistry::removeMapTool( const QString &id )
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 }
QgsMapToolShapeRegistry::mapToolMetadata
QgsMapToolShapeMetadata * mapToolMetadata(const QString &id) const
Returns the map tool metadata for the given id.
Definition: qgsmaptoolshaperegistry.cpp:59
QgsMapToolShapeRegistry::~QgsMapToolShapeRegistry
~QgsMapToolShapeRegistry()
Definition: qgsmaptoolshaperegistry.cpp:25
QgsMapToolShapeMetadata
QgsMapToolShapeMetadata is a base class for shape map tools metadata to be used in QgsMapToolShapeReg...
Definition: qgsmaptoolshaperegistry.h:81
QgsMapToolShapeRegistry::QgsMapToolShapeRegistry
QgsMapToolShapeRegistry()
Constructor.
Definition: qgsmaptoolshaperegistry.cpp:21
QgsMapToolShapeRegistry::mapTool
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...
Definition: qgsmaptoolshaperegistry.cpp:70
qgsmaptoolshaperegistry.h
QgsMapToolShapeAbstract::id
QString id() const
Returns the id of the shape tool (equivalent to the one from the metadata)
Definition: qgsmaptoolshapeabstract.h:67
QgsMapToolShapeAbstract
QgsMapToolShapeAbstract is a base class for shape map tools to be used by QgsMapToolCapture.
Definition: qgsmaptoolshapeabstract.h:40
QgsMapToolShapeRegistry::addMapTool
void addMapTool(QgsMapToolShapeMetadata *mapTool SIP_TRANSFER)
Adds a new shape map tool.
Definition: qgsmaptoolshaperegistry.cpp:31
QgsMapToolCapture
Definition: qgsmaptoolcapture.h:49
QgsMapToolShapeRegistry::removeMapTool
void removeMapTool(const QString &id)
Removes a registered map tool at the given id The tool will be deleted.
Definition: qgsmaptoolshaperegistry.cpp:42
QgsMapToolShapeMetadata::factory
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.