QGIS API Documentation  3.9.0-Master (224899f119)
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 
24 class QgsPathResolver;
25 class QgsVectorLayer;
27 class QgsCallout;
28 class QDomElement;
29 
39 class CORE_EXPORT QgsCalloutAbstractMetadata
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 
102 typedef QgsCallout *( *QgsCalloutCreateFunc )( const QVariantMap &, const QgsReadWriteContext & ) SIP_SKIP;
103 typedef 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;
134 
135  protected:
138 
139  private:
140 #ifdef SIP_RUN
142 #endif
143 };
144 
145 
155 class CORE_EXPORT QgsCalloutRegistry
156 {
157  public:
158 
161 
163  QgsCalloutRegistry( const QgsCalloutRegistry &rh ) = delete;
165  QgsCalloutRegistry &operator=( const QgsCalloutRegistry &rh ) = delete;
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
The class is used as a container of context for various read/write operations on other objects...
Abstract base class for callout renderers.
Definition: qgscallout.h:46
QgsCalloutMetadata(const QString &name, const QString &visibleName, const QIcon &icon, QgsCalloutCreateFunc pfCreate, QgsCalloutWidgetFunc pfWidget=nullptr)
Stores metadata about one callout renderer class.
Base class for widgets which allow control over the properties of callouts.
QgsCalloutWidgetFunc widgetFunction() const
QgsCallout *(* QgsCalloutCreateFunc)(const QVariantMap &, const QgsReadWriteContext &)
QgsCalloutWidgetFunc mWidgetFunc
#define SIP_SKIP
Definition: qgis_sip.h:126
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.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsCalloutCreateFunc mCreateFunc
QIcon icon() const
Returns an icon representing the callout.
QgsCalloutWidget *(* QgsCalloutWidgetFunc)(QgsVectorLayer *)
QString visibleName() const
Returns a friendly display name of the callout type.
void setWidgetFunction(QgsCalloutWidgetFunc f)
virtual QgsCalloutWidget * createCalloutWidget(QgsVectorLayer *)
Creates a widget for configuring callouts of this type.
Convenience metadata class that uses static functions to create callouts and their widgets...
Registry of available callout classes.
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
QgsCalloutCreateFunc createFunction() const
Resolves relative paths into absolute paths and vice versa.
QString name() const
Returns the unique name of the callout type.
Represents a vector layer which manages a vector based data sets.
virtual QgsCallout * createCallout(const QVariantMap &properties, const QgsReadWriteContext &context)=0
Create a callout of this type given the map of properties.