QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgscalloutsregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscalloutsregistry.h
3 ---------------------
4 begin : July 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSCALLOUTSREGISTRY_H
17#define QGSCALLOUTSREGISTRY_H
18
19#include "qgis_core.h"
20#include "qgis.h"
21#include "qgsreadwritecontext.h"
22#include <QIcon>
23
24class QgsPathResolver;
25class QgsVectorLayer;
27class QgsCallout;
28class QDomElement;
29
40{
41 public:
42
50 QgsCalloutAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() )
51 : mName( name )
52 , mVisibleName( visibleName )
53 , mIcon( icon )
54 {}
55
56 virtual ~QgsCalloutAbstractMetadata() = default;
57
62 QString name() const { return mName; }
63
68 QString visibleName() const { return mVisibleName; }
69
74 QIcon icon() const { return mIcon; }
75
80 void setIcon( const QIcon &icon ) { mIcon = icon; }
81
87 virtual QgsCallout *createCallout( const QVariantMap &properties, const QgsReadWriteContext &context ) = 0 SIP_FACTORY;
88
94 virtual QgsCalloutWidget *createCalloutWidget( QgsVectorLayer * );
95
96 protected:
97 QString mName;
98 QString mVisibleName;
99 QIcon mIcon;
100};
101
102typedef QgsCallout *( *QgsCalloutCreateFunc )( const QVariantMap &, const QgsReadWriteContext & ) SIP_SKIP;
103typedef QgsCalloutWidget *( *QgsCalloutWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;
104
111{
112 public:
113
115 QgsCalloutMetadata( const QString &name, const QString &visibleName,
116 const QIcon &icon,
117 QgsCalloutCreateFunc pfCreate,
118 QgsCalloutWidgetFunc pfWidget = nullptr ) SIP_SKIP
119 : QgsCalloutAbstractMetadata( name, visibleName, icon )
120 , mCreateFunc( pfCreate )
121 , mWidgetFunc( pfWidget )
122 {}
123
125 QgsCalloutCreateFunc createFunction() const { return mCreateFunc; } SIP_SKIP
127 QgsCalloutWidgetFunc widgetFunction() const { return mWidgetFunc; } SIP_SKIP
128
130 void setWidgetFunction( QgsCalloutWidgetFunc f ) { mWidgetFunc = f; } SIP_SKIP
131
132 QgsCallout *createCallout( const QVariantMap &properties, const QgsReadWriteContext &context ) override SIP_FACTORY;
133 QgsCalloutWidget *createCalloutWidget( QgsVectorLayer *vl ) override SIP_FACTORY;
134
135 protected:
138
139 private:
140#ifdef SIP_RUN
142#endif
143};
144
145
155class CORE_EXPORT QgsCalloutRegistry
156{
157 public:
158
161
166
170 QgsCalloutAbstractMetadata *calloutMetadata( const QString &type ) const;
171
177 bool addCalloutType( QgsCalloutAbstractMetadata *metadata SIP_TRANSFER );
178
184 QgsCallout *createCallout( const QString &type, const QVariantMap &properties = QVariantMap(), const QgsReadWriteContext &context = QgsReadWriteContext() ) const SIP_FACTORY;
185
191 QgsCallout *createCallout( const QString &type, const QDomElement &element, const QgsReadWriteContext &context ) const SIP_FACTORY;
192
196 QStringList calloutTypes() const;
197
203 static QgsCallout *defaultCallout() SIP_FACTORY;
204
205 private:
206#ifdef SIP_RUN
208#endif
209
210 QMap<QString, QgsCalloutAbstractMetadata *> mMetadata;
211};
212
213#endif // QGSCALLOUTSREGISTRY_H
Stores metadata about one callout renderer class.
virtual ~QgsCalloutAbstractMetadata()=default
QString visibleName() const
Returns a friendly display name of the callout type.
virtual QgsCallout * createCallout(const QVariantMap &properties, const QgsReadWriteContext &context)=0
Create a callout of this type given the map of properties.
QIcon icon() const
Returns an icon representing the callout.
void setIcon(const QIcon &icon)
Sets an icon representing the callout.
QgsCalloutAbstractMetadata(const QString &name, const QString &visibleName, const QIcon &icon=QIcon())
Constructor for QgsCalloutAbstractMetadata, with the specified name.
QString name() const
Returns the unique name of the callout type.
Convenience metadata class that uses static functions to create callouts and their widgets.
QgsCalloutCreateFunc createFunction() const
QgsCalloutWidgetFunc widgetFunction() const
QgsCalloutWidgetFunc mWidgetFunc
QgsCalloutCreateFunc mCreateFunc
QgsCalloutMetadata(const QString &name, const QString &visibleName, const QIcon &icon, QgsCalloutCreateFunc pfCreate, QgsCalloutWidgetFunc pfWidget=nullptr)
void setWidgetFunction(QgsCalloutWidgetFunc f)
Registry of available callout classes.
QgsCalloutRegistry & operator=(const QgsCalloutRegistry &rh)=delete
QgsCalloutRegistry cannot be copied.
QgsCalloutRegistry(const QgsCalloutRegistry &rh)=delete
QgsCalloutRegistry cannot be copied.
Base class for widgets which allow control over the properties of callouts.
Abstract base class for callout renderers.
Definition: qgscallout.h:53
Resolves relative paths into absolute paths and vice versa.
The class is used as a container of context for various read/write operations on other objects.
Represents a vector layer which manages a vector based data sets.
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsCalloutWidget *(* QgsCalloutWidgetFunc)(QgsVectorLayer *)
QgsCallout *(* QgsCalloutCreateFunc)(const QVariantMap &, const QgsReadWriteContext &)