QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <functional>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgsapplication.h"
24#include "qgspathresolver.h"
25
26#include <QGraphicsItem>
27#include <QIcon>
28
30class QDomElement;
32
44{
45 public:
46
53 QgsAnnotationItemAbstractMetadata( const QString &type, const QString &visibleName, const QString &visiblePluralName = QString() )
54 : mType( type )
55 , mVisibleName( visibleName )
56 , mVisibleNamePlural( visiblePluralName.isEmpty() ? visibleName : visiblePluralName )
57 {}
58
60
64 QString type() const { return mType; }
65
70 QString visibleName() const { return mVisibleName; }
71
75 QString visiblePluralName() const { return mVisibleNamePlural; }
76
81
82 private:
83
84 QString mType;
85 QString mVisibleName;
86 QString mVisibleNamePlural;
87};
88
91
92#ifndef SIP_RUN
93
101{
102 public:
103
110 QgsAnnotationItemMetadata( const QString &type, const QString &visibleName, const QString &visiblePluralName,
111 const QgsAnnotationItemCreateFunc &pfCreate )
113 , mCreateFunc( pfCreate )
114 {}
115
120
121 QgsAnnotationItem *createItem() override { return mCreateFunc ? mCreateFunc() : nullptr; }
122
123 protected:
125
126};
127
128#endif
129
130
144class CORE_EXPORT QgsAnnotationItemRegistry : public QObject
145{
146 Q_OBJECT
147
148 public:
149
158 QgsAnnotationItemRegistry( QObject *parent = nullptr );
159
161
166 bool populate();
167
170
175 QgsAnnotationItemAbstractMetadata *itemMetadata( const QString &type ) const;
176
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
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,...
QgsAnnotationItemCreateFunc mCreateFunc
QgsAnnotationItem * createItem(const QString &type) const
Creates a new instance of a annotation item given the item type.
QgsAnnotationItemAbstractMetadata * itemMetadata(const QString &type) const
Returns the metadata for the specified item type.
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.
bool populate()
Populates the registry with standard item types.
QgsAnnotationItemRegistry(QObject *parent=nullptr)
Creates a new empty item registry.
QMap< QString, QString > itemTypes() const
Returns a map of available item types to translated name.
bool addItemType(QgsAnnotationItemAbstractMetadata *metadata)
Registers a new annotation item type.
QgsAnnotationItemRegistry(const QgsAnnotationItemRegistry &rh)=delete
QgsAnnotationItemRegistry & operator=(const QgsAnnotationItemRegistry &rh)=delete
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
A container for the context for various read/write operations on objects.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
std::function< QgsAnnotationItem *()> QgsAnnotationItemCreateFunc
Annotation item creation function.