QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
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.h"
20 #include <QDomElement>
21 #include <QDomDocument>
22 
23 class QgsPaintEffect;
25 
37 {
38  public:
39 
44  QgsPaintEffectAbstractMetadata( const QString& name, const QString& visibleName );
45 
47 
52  QString name() const { return mName; }
53 
58  QString visibleName() const { return mVisibleName; }
59 
64  virtual QgsPaintEffect* createPaintEffect( const QgsStringMap& map ) = 0;
65 
70  virtual QgsPaintEffectWidget* createWidget() { return nullptr; }
71 
72  protected:
75 
76 };
77 
78 typedef QgsPaintEffect*( *QgsPaintEffectCreateFunc )( const QgsStringMap& );
79 typedef QgsPaintEffectWidget*( *QgsPaintEffectWidgetFunc )();
80 
88 {
89 
90  public:
91 
99  QgsPaintEffectMetadata( const QString& name, const QString& visibleName,
100  QgsPaintEffectCreateFunc pfCreate,
101  QgsPaintEffectWidgetFunc pfWidget = nullptr )
102  : QgsPaintEffectAbstractMetadata( name, visibleName )
103  , mCreateFunc( pfCreate )
104  , mWidgetFunc( pfWidget )
105  {}
106 
111  QgsPaintEffectCreateFunc createFunction() const { return mCreateFunc; }
112 
118  QgsPaintEffectWidgetFunc widgetFunction() const { return mWidgetFunc; }
119 
125  void setWidgetFunction( QgsPaintEffectWidgetFunc f ) { mWidgetFunc = f; }
126 
133  virtual QgsPaintEffect* createPaintEffect( const QgsStringMap& map ) override { return mCreateFunc ? mCreateFunc( map ) : nullptr; }
134 
140  virtual QgsPaintEffectWidget* createWidget() override { return mWidgetFunc ? mWidgetFunc() : nullptr; }
141 
142  protected:
145 };
146 
147 
154 class CORE_EXPORT QgsPaintEffectRegistry
155 {
156  public:
157 
160  static QgsPaintEffectRegistry* instance();
161 
166  QgsPaintEffectAbstractMetadata* effectMetadata( const QString& name ) const;
167 
172  bool addEffectType( QgsPaintEffectAbstractMetadata* metadata );
173 
180  QgsPaintEffect* createEffect( const QString& name, const QgsStringMap& properties = QgsStringMap() ) const;
181 
188  QgsPaintEffect* createEffect( const QDomElement& element ) const;
189 
193  QStringList effects() const;
194 
201  static QgsPaintEffect* defaultStack();
202 
209  static bool isDefaultStack( QgsPaintEffect* effect );
210 
211  protected:
214 
216 
217  private:
218 
220  QgsPaintEffectRegistry& operator=( const QgsPaintEffectRegistry& rh );
221 };
222 
223 #endif //QGSPAINTEFFECTREGISTRY_H
virtual QgsPaintEffect * createPaintEffect(const QgsStringMap &map) override
Creates a new paint effect of the metadata&#39;s effect class.
Convenience metadata class that uses static functions to create an effect and its widget...
QgsPaintEffectWidgetFunc widgetFunction() const
Returns the paint effect properties widget creation function for the paint effect class...
Base class for effect properties widgets.
QString visibleName() const
Returns the user visible string representing the paint effect class.
Base class for visual effects which can be applied to QPicture drawings.
Stores metadata about a paint effect class.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:492
QgsPaintEffectCreateFunc mCreateFunc
QgsPaintEffectCreateFunc createFunction() const
Returns the paint effect creation function for the paint effect class.
QgsPaintEffectWidgetFunc mWidgetFunc
QgsPaintEffectWidget *(* QgsPaintEffectWidgetFunc)()
QgsPaintEffect *(* QgsPaintEffectCreateFunc)(const QgsStringMap &)
QgsPaintEffectMetadata(const QString &name, const QString &visibleName, QgsPaintEffectCreateFunc pfCreate, QgsPaintEffectWidgetFunc pfWidget=nullptr)
Create effect metadata from static functions.
QMap< QString, QgsPaintEffectAbstractMetadata * > mMetadata
virtual QgsPaintEffectWidget * createWidget() override
Creates a new paint effect properties widget for the metadata&#39;s effect class.
QString name() const
Returns the unique string representing the paint effect class.
void setWidgetFunction(QgsPaintEffectWidgetFunc f)
Sets the paint effect properties widget creation function for the paint effect class.
virtual QgsPaintEffectWidget * createWidget()
Create configuration widget for paint effect of this class.
Singleton registry of available paint effects.