QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
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
28class 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
58
62 QString type() const { return mType; }
63
68 QString visibleName() const { return mVisibleName; }
69
73 QString visiblePluralName() const { return mVisibleNamePlural; }
74
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
142class CORE_EXPORT QgsAnnotationItemRegistry : public QObject
143{
144 Q_OBJECT
145
146 public:
147
156 QgsAnnotationItemRegistry( QObject *parent = nullptr );
157
159
164 bool populate();
165
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
Stores metadata about one annotation item class.
QgsAnnotationItemAbstractMetadata(const QString &type, const QString &visibleName, const QString &visiblePluralName=QString())
Constructor for QgsAnnotationItemAbstractMetadata with the specified class type and visibleName.
virtual QgsAnnotationItem * createItem()=0
Creates a new, default, annotation item of this class.
QString visiblePluralName() const
Returns a translated, user visible name for plurals of the annotation item class (e....
QString type() const
Returns the unique item type string for the annotation item class.
QString visibleName() const
Returns a translated, user visible name for the annotation item class.
virtual ~QgsAnnotationItemAbstractMetadata()=default
Convenience metadata class that uses static functions to create annotation items and their configurat...
QgsAnnotationItem * createItem() override
Creates a new, default, annotation item of this class.
QgsAnnotationItemCreateFunc createFunction() const
Returns the classes' item default creation function.
QgsAnnotationItemMetadata(const QString &type, const QString &visibleName, const QString &visiblePluralName, const QgsAnnotationItemCreateFunc &pfCreate)
Constructor for QgsAnnotationItemMetadata with the specified class type and visibleName,...
Registry of available annotation item types.
void typeAdded(const QString &type, const QString &name)
Emitted whenever a new item type is added to the registry, with the specified type and visible name.
QgsAnnotationItemRegistry(const QgsAnnotationItemRegistry &rh)=delete
QgsAnnotationItemRegistry cannot be copied.
QgsAnnotationItemRegistry & operator=(const QgsAnnotationItemRegistry &rh)=delete
QgsAnnotationItemRegistry cannot be copied.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
The class is used as a container of context for various read/write operations on other objects.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
std::function< QgsAnnotationItem *()> QgsAnnotationItemCreateFunc
Annotation item creation function.