QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
50 QgsCalloutAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() )
51 : mName( name )
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
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#ifndef SIP_RUN
115 QgsCalloutMetadata( const QString &name, const QString &visibleName, const QIcon &icon, QgsCalloutCreateFunc pfCreate, QgsCalloutWidgetFunc pfWidget = nullptr )
117 , mCreateFunc( pfCreate )
118 , mWidgetFunc( pfWidget )
119 {}
120
125
128#endif
129
130 QgsCallout *createCallout( const QVariantMap &properties, const QgsReadWriteContext &context ) override SIP_FACTORY;
131 QgsCalloutWidget *createCalloutWidget( QgsMapLayer *vl ) override SIP_FACTORY;
132
133 protected:
136
137 private:
138#ifdef SIP_RUN
140#endif
141};
142
143
153class CORE_EXPORT QgsCalloutRegistry
154{
155 public:
158
161
165 QgsCalloutAbstractMetadata *calloutMetadata( const QString &type ) const;
166
173
179 QgsCallout *createCallout( const QString &type, const QVariantMap &properties = QVariantMap(), const QgsReadWriteContext &context = QgsReadWriteContext() ) const SIP_FACTORY;
180
186 QgsCallout *createCallout( const QString &type, const QDomElement &element, const QgsReadWriteContext &context ) const SIP_FACTORY;
187
191 QStringList calloutTypes() const;
192
199
200 private:
201#ifdef SIP_RUN
203#endif
204
205 QMap<QString, QgsCalloutAbstractMetadata *> mMetadata;
206};
207
208#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:83
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:123
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
QgsCalloutWidget *(* QgsCalloutWidgetFunc)(QgsMapLayer *)
QgsCallout *(* QgsCalloutCreateFunc)(const QVariantMap &, const QgsReadWriteContext &)