QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsvaluerelationfieldformatter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvaluerelationfieldformatter.h - QgsValueRelationFieldFormatter
3 
4  ---------------------
5  begin : 3.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 QGSVALUERELATIONFIELDKIT_H
17 #define QGSVALUERELATIONFIELDKIT_H
18 
19 #include "qgis_core.h"
20 #include "qgsfieldformatter.h"
21 #include "qgsexpression.h"
22 #include "qgsexpressioncontext.h"
23 
24 #include <QVector>
25 #include <QVariant>
26 
27 
37 {
38  public:
39  struct ValueRelationItem
40  {
42  ValueRelationItem( const QVariant &key, const QString &value, const QString &description = QString() )
43  : key( key )
44  , value( value )
45  , description( description )
46  {}
47 
49  ValueRelationItem() = default;
50 
51  QVariant key;
52  QString value;
53  QString description;
54  };
55 
56  typedef QVector < QgsValueRelationFieldFormatter::ValueRelationItem > ValueRelationCache;
57 
62 
63  QString id() const override;
64  QString representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;
65 
66  QVariant sortValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;
67 
68  QVariant createCache( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const override;
69 
74  static QStringList valueToStringList( const QVariant &value );
75 
87  static QgsValueRelationFieldFormatter::ValueRelationCache createCache( const QVariantMap &config, const QgsFeature &formFeature = QgsFeature(), const QgsFeature &parentFormFeature = QgsFeature() );
88 
97  static bool expressionRequiresFormScope( const QString &expression );
98 
106  static QSet<QString> expressionFormAttributes( const QString &expression );
107 
115  static QSet<QString> expressionFormVariables( const QString &expression );
116 
125  static bool expressionRequiresParentFormScope( const QString &expression );
126 
134  static QSet<QString> expressionParentFormAttributes( const QString &expression );
135 
143  static QSet<QString> expressionParentFormVariables( const QString &expression );
144 
145 
153  static bool expressionIsUsable( const QString &expression, const QgsFeature &feature, const QgsFeature &parentFeature = QgsFeature() );
154 
159  static QgsVectorLayer *resolveLayer( const QVariantMap &config, const QgsProject *project );
160 
161  QList<QgsVectorLayerRef> layerDependencies( const QVariantMap &config ) const override SIP_SKIP;
162 
163  QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const override;
164 };
165 
167 
168 #endif // QGSVALUERELATIONFIELDKIT_H
QgsFieldFormatter::createCache
virtual QVariant createCache(QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config) const
Create a cache for a given field.
Definition: qgsfieldformatter.cpp:64
qgsexpression.h
QgsFieldFormatter::id
virtual QString id() const =0
Returns a unique id for this field formatter.
QgsFieldFormatter::layerDependencies
virtual QList< QgsVectorLayerRef > layerDependencies(const QVariantMap &config) const
Returns a list of weak layer references to other layers required by this formatter for the given conf...
Definition: qgsfieldformatter.cpp:73
QgsFieldFormatterContext
Definition: qgsfieldformatter.h:33
QgsFieldFormatter::sortValue
virtual QVariant sortValue(QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const
If the default sort order should be overwritten for this widget, you can transform the value in here.
Definition: qgsfieldformatter.cpp:43
QgsProject
Definition: qgsproject.h:92
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
qgsexpressioncontext.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsFieldFormatter::availableValues
virtual QVariantList availableValues(const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context) const
Returns a list of the values that would be possible to select with this widget type On a RelationRefe...
Definition: qgsfieldformatter.cpp:79
QgsFieldFormatter::representValue
virtual QString representValue(QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const
Create a pretty String representation of the value.
Definition: qgsfieldformatter.cpp:24
QgsValueRelationFieldFormatter::ValueRelationCache
QVector< QgsValueRelationFieldFormatter::ValueRelationItem > ValueRelationCache
Definition: qgsvaluerelationfieldformatter.h:70
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsValueRelationFieldFormatter
Definition: qgsvaluerelationfieldformatter.h:36
QgsFeature
Definition: qgsfeature.h:55
QgsValueRelationFieldFormatter::ValueRelationItem
Definition: qgsvaluerelationfieldformatter.h:53
QgsFieldFormatter
Definition: qgsfieldformatter.h:72
qgsfieldformatter.h