QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 QgsMapLayer;
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( QgsMapLayer * );
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 )( QgsMapLayer * ) 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 SIP_SKIP { return mCreateFunc; }
127 QgsCalloutWidgetFunc widgetFunction() const SIP_SKIP { return mWidgetFunc; }
128
130 void setWidgetFunction( QgsCalloutWidgetFunc f ) SIP_SKIP { mWidgetFunc = f; }
131
132 QgsCallout *createCallout( const QVariantMap &properties, const QgsReadWriteContext &context ) override SIP_FACTORY;
133 QgsCalloutWidget *createCalloutWidget( QgsMapLayer *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
164
168 QgsCalloutAbstractMetadata *calloutMetadata( const QString &type ) const;
169
175 bool addCalloutType( QgsCalloutAbstractMetadata *metadata SIP_TRANSFER );
176
182 QgsCallout *createCallout( const QString &type, const QVariantMap &properties = QVariantMap(), const QgsReadWriteContext &context = QgsReadWriteContext() ) const SIP_FACTORY;
183
189 QgsCallout *createCallout( const QString &type, const QDomElement &element, const QgsReadWriteContext &context ) const SIP_FACTORY;
190
194 QStringList calloutTypes() const;
195
201 static QgsCallout *defaultCallout() SIP_FACTORY;
202
203 private:
204#ifdef SIP_RUN
206#endif
207
208 QMap<QString, QgsCalloutAbstractMetadata *> mMetadata;
209};
210
211#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(const QgsCalloutRegistry &rh)=delete
Base class for widgets which allow control over the properties of callouts.
Abstract base class for callout renderers.
Definition qgscallout.h:54
Base class for all map layer types.
Definition qgsmaplayer.h:76
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.
#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)(QgsMapLayer *)
QgsCallout *(* QgsCalloutCreateFunc)(const QVariantMap &, const QgsReadWriteContext &)