QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsannotationitemregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsannotationitemregistry.h
3  ------------------------
4  begin : October 2019
5  copyright : (C) 2019 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSANNOTATIONITEMREGISTRY_H
17 #define QGSANNOTATIONITEMREGISTRY_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgsapplication.h"
22 #include "qgspathresolver.h"
23 #include <QGraphicsItem> //for QGraphicsItem::UserType
24 #include <QIcon>
25 #include <functional>
26 
27 class QgsAnnotationItem;
28 class QDomElement;
30 
42 {
43  public:
44 
51  QgsAnnotationItemAbstractMetadata( const QString &type, const QString &visibleName, const QString &visiblePluralName = QString() )
52  : mType( type )
53  , mVisibleName( visibleName )
54  , mVisibleNamePlural( visiblePluralName.isEmpty() ? visibleName : visiblePluralName )
55  {}
56 
57  virtual ~QgsAnnotationItemAbstractMetadata() = default;
58 
62  QString type() const { return mType; }
63 
68  QString visibleName() const { return mVisibleName; }
69 
73  QString visiblePluralName() const { return mVisibleNamePlural; }
74 
78  virtual QgsAnnotationItem *createItem() = 0 SIP_FACTORY;
79 
80  private:
81 
82  QString mType;
83  QString mVisibleName;
84  QString mVisibleNamePlural;
85 };
86 
89 
90 #ifndef SIP_RUN
91 
99 {
100  public:
101 
108  QgsAnnotationItemMetadata( const QString &type, const QString &visibleName, const QString &visiblePluralName,
109  const QgsAnnotationItemCreateFunc &pfCreate )
110  : QgsAnnotationItemAbstractMetadata( type, visibleName, visiblePluralName )
111  , mCreateFunc( pfCreate )
112  {}
113 
117  QgsAnnotationItemCreateFunc createFunction() const { return mCreateFunc; }
118 
119  QgsAnnotationItem *createItem() override { return mCreateFunc ? mCreateFunc() : nullptr; }
120 
121  protected:
122  QgsAnnotationItemCreateFunc mCreateFunc = nullptr;
123 
124 };
125 
126 #endif
127 
128 
142 class CORE_EXPORT QgsAnnotationItemRegistry : public QObject
143 {
144  Q_OBJECT
145 
146  public:
147 
156  QgsAnnotationItemRegistry( QObject *parent = nullptr );
157 
158  ~QgsAnnotationItemRegistry() override;
159 
164  bool populate();
165 
169  QgsAnnotationItemRegistry &operator=( const QgsAnnotationItemRegistry &rh ) = delete;
170 
175  QgsAnnotationItemAbstractMetadata *itemMetadata( const QString &type ) const;
176 
180  bool addItemType( QgsAnnotationItemAbstractMetadata *metadata SIP_TRANSFER );
181 
185  QgsAnnotationItem *createItem( const QString &type ) const SIP_FACTORY;
186 
190  QMap< QString, QString> itemTypes() const;
191 
192  signals:
193 
198  void typeAdded( const QString &type, const QString &name );
199 
200  private:
201 #ifdef SIP_RUN
203 #endif
204 
205  QMap<QString, QgsAnnotationItemAbstractMetadata *> mMetadata;
206 
207 };
208 
209 #endif //QGSANNOTATIONITEMREGISTRY_H
210 
211 
212 
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsAnnotationItemCreateFunc
std::function< QgsAnnotationItem *()> QgsAnnotationItemCreateFunc
Annotation item creation function.
Definition: qgsannotationitemregistry.h:88
qgspathresolver.h
QgsAnnotationItemAbstractMetadata::QgsAnnotationItemAbstractMetadata
QgsAnnotationItemAbstractMetadata(const QString &type, const QString &visibleName, const QString &visiblePluralName=QString())
Constructor for QgsAnnotationItemAbstractMetadata with the specified class type and visibleName.
Definition: qgsannotationitemregistry.h:51
QgsAnnotationItemAbstractMetadata::visiblePluralName
QString visiblePluralName() const
Returns a translated, user visible name for plurals of the annotation item class (e....
Definition: qgsannotationitemregistry.h:73
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgsapplication.h
QgsAnnotationItemAbstractMetadata::type
QString type() const
Returns the unique item type string for the annotation item class.
Definition: qgsannotationitemregistry.h:62
QgsAnnotationItemMetadata
Convenience metadata class that uses static functions to create annotation items and their configurat...
Definition: qgsannotationitemregistry.h:98
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsAnnotationItemMetadata::createFunction
QgsAnnotationItemCreateFunc createFunction() const
Returns the classes' item default creation function.
Definition: qgsannotationitemregistry.h:117
QgsAnnotationItemRegistry
Registry of available annotation item types.
Definition: qgsannotationitemregistry.h:142
QgsAnnotationItemAbstractMetadata::visibleName
QString visibleName() const
Returns a translated, user visible name for the annotation item class.
Definition: qgsannotationitemregistry.h:68
QgsAnnotationItemAbstractMetadata
Stores metadata about one annotation item class.
Definition: qgsannotationitemregistry.h:41
QgsAnnotationItemMetadata::createItem
QgsAnnotationItem * createItem() override
Creates a new, default, annotation item of this class.
Definition: qgsannotationitemregistry.h:119
QgsAnnotationItemMetadata::QgsAnnotationItemMetadata
QgsAnnotationItemMetadata(const QString &type, const QString &visibleName, const QString &visiblePluralName, const QgsAnnotationItemCreateFunc &pfCreate)
Constructor for QgsAnnotationItemMetadata with the specified class type and visibleName,...
Definition: qgsannotationitemregistry.h:108
QgsAnnotationItem
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Definition: qgsannotationitem.h:42