QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgspainteffectregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspainteffectregistry.h
3  ------------------------
4  begin : January 2015
5  copyright : (C) 2015 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 QGSPAINTEFFECTREGISTRY_H
17 #define QGSPAINTEFFECTREGISTRY_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include <QDomElement>
22 #include <QDomDocument>
23 #include <QMap>
24 #include <QVariantMap>
25 
26 class QgsPaintEffect;
28 
41 {
42  public:
43 
49  QgsPaintEffectAbstractMetadata( const QString &name, const QString &visibleName );
50 
51  virtual ~QgsPaintEffectAbstractMetadata() = default;
52 
58  QString name() const { return mName; }
59 
65  QString visibleName() const { return mVisibleName; }
66 
72  virtual QgsPaintEffect *createPaintEffect( const QVariantMap &map ) = 0 SIP_FACTORY;
73 
79  virtual QgsPaintEffectWidget *createWidget() SIP_FACTORY { return nullptr; }
80 
81  protected:
82  QString mName;
83  QString mVisibleName;
84 
85 };
86 
87 typedef QgsPaintEffect *( *QgsPaintEffectCreateFunc )( const QVariantMap & ) SIP_SKIP;
88 typedef QgsPaintEffectWidget *( *QgsPaintEffectWidgetFunc )() SIP_SKIP;
89 
99 {
100 
101  public:
102 
111  QgsPaintEffectMetadata( const QString &name, const QString &visibleName,
112  QgsPaintEffectCreateFunc pfCreate,
113  QgsPaintEffectWidgetFunc pfWidget = nullptr ) SIP_SKIP
114  : QgsPaintEffectAbstractMetadata( name, visibleName )
115  , mCreateFunc( pfCreate )
116  , mWidgetFunc( pfWidget )
117  {}
118 
124  QgsPaintEffectCreateFunc createFunction() const { return mCreateFunc; } SIP_SKIP
125 
132  QgsPaintEffectWidgetFunc widgetFunction() const { return mWidgetFunc; } SIP_SKIP
133 
140  void setWidgetFunction( QgsPaintEffectWidgetFunc f ) { mWidgetFunc = f; } SIP_SKIP
141 
149  QgsPaintEffect *createPaintEffect( const QVariantMap &map ) override { return mCreateFunc ? mCreateFunc( map ) : nullptr; } SIP_SKIP
150 
157  QgsPaintEffectWidget *createWidget() override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc() : nullptr; } SIP_SKIP
158 
159  protected:
162 };
163 
164 
175 class CORE_EXPORT QgsPaintEffectRegistry
176 {
177  public:
178 
181 
183  QgsPaintEffectRegistry( const QgsPaintEffectRegistry &rh ) = delete;
185  QgsPaintEffectRegistry &operator=( const QgsPaintEffectRegistry &rh ) = delete;
186 
192  QgsPaintEffectAbstractMetadata *effectMetadata( const QString &name ) const;
193 
199  bool addEffectType( QgsPaintEffectAbstractMetadata *metadata SIP_TRANSFER );
200 
208  QgsPaintEffect *createEffect( const QString &name, const QVariantMap &properties = QVariantMap() ) const SIP_FACTORY;
209 
217  QgsPaintEffect *createEffect( const QDomElement &element ) const SIP_FACTORY;
218 
223  QStringList effects() const;
224 
232  static QgsPaintEffect *defaultStack() SIP_FACTORY;
233 
241  static bool isDefaultStack( QgsPaintEffect *effect );
242 
243  private:
244 #ifdef SIP_RUN
246 #endif
247 
248  QMap<QString, QgsPaintEffectAbstractMetadata *> mMetadata;
249 };
250 
251 #endif //QGSPAINTEFFECTREGISTRY_H
QgsPaintEffectMetadata::widgetFunction
QgsPaintEffectWidgetFunc widgetFunction() const
Returns the paint effect properties widget creation function for the paint effect class.
Definition: qgspainteffectregistry.h:132
QgsPaintEffectAbstractMetadata::createWidget
virtual QgsPaintEffectWidget * createWidget()
Create configuration widget for paint effect of this class.
Definition: qgspainteffectregistry.h:79
QgsPaintEffectMetadata::createPaintEffect
QgsPaintEffect * createPaintEffect(const QVariantMap &map) override
Creates a new paint effect of the metadata's effect class.
Definition: qgspainteffectregistry.h:149
QgsPaintEffectCreateFunc
QgsPaintEffect *(* QgsPaintEffectCreateFunc)(const QVariantMap &)
Definition: qgspainteffectregistry.h:87
QgsPaintEffectMetadata::mWidgetFunc
QgsPaintEffectWidgetFunc mWidgetFunc
Definition: qgspainteffectregistry.h:161
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsPaintEffectAbstractMetadata::name
QString name() const
Returns the unique string representing the paint effect class.
Definition: qgspainteffectregistry.h:58
QgsPaintEffectMetadata::createFunction
QgsPaintEffectCreateFunc createFunction() const
Returns the paint effect creation function for the paint effect class.
Definition: qgspainteffectregistry.h:124
QgsPaintEffectAbstractMetadata::mVisibleName
QString mVisibleName
Definition: qgspainteffectregistry.h:83
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsPaintEffectAbstractMetadata
Stores metadata about a paint effect class.
Definition: qgspainteffectregistry.h:40
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsPaintEffectMetadata::mCreateFunc
QgsPaintEffectCreateFunc mCreateFunc
Definition: qgspainteffectregistry.h:160
QgsPaintEffectMetadata::createWidget
QgsPaintEffectWidget * createWidget() override
Creates a new paint effect properties widget for the metadata's effect class.
Definition: qgspainteffectregistry.h:157
QgsPaintEffectRegistry
Registry of available paint effects.
Definition: qgspainteffectregistry.h:175
QgsPaintEffectMetadata::QgsPaintEffectMetadata
QgsPaintEffectMetadata(const QString &name, const QString &visibleName, QgsPaintEffectCreateFunc pfCreate, QgsPaintEffectWidgetFunc pfWidget=nullptr)
Create effect metadata from static functions.
Definition: qgspainteffectregistry.h:111
QgsPaintEffectWidget
Base class for effect properties widgets.
Definition: qgspainteffectwidget.h:40
QgsPaintEffectMetadata::setWidgetFunction
void setWidgetFunction(QgsPaintEffectWidgetFunc f)
Sets the paint effect properties widget creation function for the paint effect class.
Definition: qgspainteffectregistry.h:140
QgsPaintEffectAbstractMetadata::visibleName
QString visibleName() const
Returns the user visible string representing the paint effect class.
Definition: qgspainteffectregistry.h:65
QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.
Definition: qgspainteffect.h:52
QgsPaintEffectWidgetFunc
QgsPaintEffectWidget *(* QgsPaintEffectWidgetFunc)()
Definition: qgspainteffectregistry.h:88
QgsPaintEffectAbstractMetadata::mName
QString mName
Definition: qgspainteffectregistry.h:82
SIP_EXTERNAL
#define SIP_EXTERNAL
Definition: qgis_sip.h:116
QgsPaintEffectMetadata
Convenience metadata class that uses static functions to create an effect and its widget.
Definition: qgspainteffectregistry.h:98