QGIS API Documentation 3.99.0-Master (26c88405ac0)
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.h"
20#include "qgis_core.h"
21#include "qgsreadwritecontext.h"
22
23#include <QIcon>
24
25class QgsPathResolver;
26class QgsMapLayer;
28class QgsCallout;
29class QDomElement;
30
41{
42 public:
43
51 QgsCalloutAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() )
52 : mName( name )
54 , mIcon( icon )
55 {}
56
57 virtual ~QgsCalloutAbstractMetadata() = default;
58
63 QString name() const { return mName; }
64
69 QString visibleName() const { return mVisibleName; }
70
75 QIcon icon() const { return mIcon; }
76
81 void setIcon( const QIcon &icon ) { mIcon = icon; }
82
88 virtual QgsCallout *createCallout( const QVariantMap &properties, const QgsReadWriteContext &context ) = 0 SIP_FACTORY;
89
96
97 protected:
98 QString mName;
99 QString mVisibleName;
100 QIcon mIcon;
101};
102
103typedef QgsCallout *( *QgsCalloutCreateFunc )( const QVariantMap &, const QgsReadWriteContext & ) SIP_SKIP;
104typedef QgsCalloutWidget *( *QgsCalloutWidgetFunc )( QgsMapLayer * ) SIP_SKIP;
105
112{
113 public:
114
116 QgsCalloutMetadata( const QString &name, const QString &visibleName,
117 const QIcon &icon,
118 QgsCalloutCreateFunc pfCreate,
119 QgsCalloutWidgetFunc pfWidget = nullptr ) SIP_SKIP
121 , mCreateFunc( pfCreate )
122 , mWidgetFunc( pfWidget )
123 {}
124
129
132
133 QgsCallout *createCallout( const QVariantMap &properties, const QgsReadWriteContext &context ) override SIP_FACTORY;
134 QgsCalloutWidget *createCalloutWidget( QgsMapLayer *vl ) override SIP_FACTORY;
135
136 protected:
139
140 private:
141#ifdef SIP_RUN
143#endif
144};
145
146
156class CORE_EXPORT QgsCalloutRegistry
157{
158 public:
159
162
165
169 QgsCalloutAbstractMetadata *calloutMetadata( const QString &type ) const;
170
177
183 QgsCallout *createCallout( const QString &type, const QVariantMap &properties = QVariantMap(), const QgsReadWriteContext &context = QgsReadWriteContext() ) const SIP_FACTORY;
184
190 QgsCallout *createCallout( const QString &type, const QDomElement &element, const QgsReadWriteContext &context ) const SIP_FACTORY;
191
195 QStringList calloutTypes() const;
196
203
204 private:
205#ifdef SIP_RUN
207#endif
208
209 QMap<QString, QgsCalloutAbstractMetadata *> mMetadata;
210};
211
212#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 QgsCalloutWidget * createCalloutWidget(QgsMapLayer *)
Creates a widget for configuring callouts of this 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.
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)
QgsCalloutAbstractMetadata * calloutMetadata(const QString &type) const
Returns the metadata for specified the specified callout type.
static QgsCallout * defaultCallout()
Create a new instance of a callout with default settings.
bool addCalloutType(QgsCalloutAbstractMetadata *metadata)
Registers a new callout type.
QStringList calloutTypes() const
Returns a list of all available callout types.
QgsCalloutRegistry & operator=(const QgsCalloutRegistry &rh)=delete
QgsCallout * createCallout(const QString &type, const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext()) const
Creates a new instance of a callout, given the callout type and properties.
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:55
Base class for all map layer types.
Definition qgsmaplayer.h:80
Resolves relative paths into absolute paths and vice versa.
A container for the context for various read/write operations on objects.
#define SIP_EXTERNAL
Definition qgis_sip.h:124
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
QgsCalloutWidget *(* QgsCalloutWidgetFunc)(QgsMapLayer *)
QgsCallout *(* QgsCalloutCreateFunc)(const QVariantMap &, const QgsReadWriteContext &)