QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsfieldformatter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldformatter.h - QgsFieldFormatter
3 
4  ---------------------
5  begin : 2.12.2016
6  copyright : (C) 2016 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSFIELDKIT_H
17 #define QGSFIELDKIT_H
18 
19 #include <QString>
20 #include <QVariant>
21 
22 #include "qgis_core.h"
23 #include "qgsvectorlayerref.h"
24 
25 class QgsVectorLayer;
26 
33 class CORE_EXPORT QgsFieldFormatterContext
34 {
35  public:
36 
40  QgsFieldFormatterContext() = default;
41 
46  QgsProject *project() const { return mProject; }
47 
52  void setProject( QgsProject *project ) { mProject = project; }
53 
54  private:
55  QgsProject *mProject = nullptr;
56 };
57 
72 class CORE_EXPORT QgsFieldFormatter
73 {
74  public:
75 
79  QgsFieldFormatter() = default;
80 
81  virtual ~QgsFieldFormatter() = default;
82 
88  enum Flag
89  {
90  CanProvideAvailableValues = 1
91  };
92  Q_DECLARE_FLAGS( Flags, Flag )
93 
94 
100  virtual QString id() const = 0;
101 
109  virtual QString representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const;
110 
118  virtual QVariant sortValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const;
119 
126  virtual Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const;
127 
141  virtual QVariant createCache( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const;
142 
155  virtual QList< QgsVectorLayerRef > layerDependencies( const QVariantMap &config ) const SIP_SKIP;
156 
163  virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const;
164 
170  Flags flags() const { return mFlags; }
171 
177  void setFlags( const Flags &flags );
178 
179  private:
180  Flags mFlags;
181 };
182 
183 #endif // QGSFIELDKIT_H
QgsFieldFormatter::flags
Flags flags() const
Returns the flags.
Definition: qgsfieldformatter.h:170
QgsFieldFormatterContext
Definition: qgsfieldformatter.h:33
QgsProject
Definition: qgsproject.h:92
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsFieldFormatter::Flag
Flag
Flags for the abilities of the formatter.
Definition: qgsfieldformatter.h:88
qgsvectorlayerref.h
QgsFieldFormatterContext::project
QgsProject * project() const
Returns the project used in field formatter.
Definition: qgsfieldformatter.h:46
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsFieldFormatterContext::setProject
void setProject(QgsProject *project)
Sets the project used in field formatter.
Definition: qgsfieldformatter.h:52
QgsFieldFormatter
Definition: qgsfieldformatter.h:72