QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsdatadefined.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatadefined.h - Data defined container class
3  --------------------------------------
4  Date : 9-May-2013
5  Copyright : (C) 2013 by Larry Shaffer
6  Email : larrys at dakcarto 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 #ifndef QGSDATADEFINED_H
16 #define QGSDATADEFINED_H
17 
18 #include <QStringList>
19 #include <QDomElement>
20 #include <QMap>
21 
22 class QgsExpression;
23 class QgsVectorLayer;
24 class QgsFields;
25 
31 class CORE_EXPORT QgsDataDefined
32 {
33  public:
42  QgsDataDefined( bool active = false,
43  bool useexpr = false,
44  const QString& expr = QString(),
45  const QString& field = QString() );
46 
53  explicit QgsDataDefined( const QgsExpression * expression );
54 
59  QgsDataDefined( const QgsDataDefined& other );
60 
61  ~QgsDataDefined();
62 
68  bool hasDefaultValues() const;
69 
70  bool isActive() const { return mActive; }
71  void setActive( bool active ) { mActive = active; }
72 
73  bool useExpression() const { return mUseExpression; }
74  void setUseExpression( bool use ) { mUseExpression = use; }
75 
76  QString expressionString() const { return mExpressionString; }
77  void setExpressionString( const QString& expr );
78 
79  // @note not available in python bindings
80  QMap<QString, QVariant> expressionParams() const { return mExpressionParams; }
81  // @note not available in python bindings
82  void setExpressionParams( QMap<QString, QVariant> params ) { mExpressionParams = params; }
83  void insertExpressionParam( QString key, QVariant param );
84 
89  bool prepareExpression( QgsVectorLayer* layer );
90 
96  bool prepareExpression( const QgsFields &fields );
97 
101  bool expressionIsPrepared() const { return mExpressionPrepared; }
102 
103  QgsExpression* expression() { return mExpression; }
104  QStringList referencedColumns( QgsVectorLayer* layer );
105 
106  QString field() const { return mField; }
107  void setField( const QString& field ) { mField = field; }
108 
109  // @note not available in python bindings
110  QMap< QString, QString > toMap();
111 
119  QDomElement toXmlElement( QDomDocument &document, const QString &elementName ) const;
120 
128  bool setFromXmlElement( const QDomElement& element );
129 
130  bool operator==( const QgsDataDefined &other ) const;
131  bool operator!=( const QgsDataDefined &other ) const;
132 
136  QgsDataDefined& operator=( QgsDataDefined const & rhs );
137 
138  private:
139  QgsExpression* mExpression;
140 
141  bool mActive;
142  bool mUseExpression;
143  QString mExpressionString;
144  QString mField;
145 
146  QMap<QString, QVariant> mExpressionParams;
147  bool mExpressionPrepared;
148  QStringList mExprRefColumns;
149 
150 };
151 
152 #endif // QGSDATADEFINED_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
void setActive(bool active)
A container class for data source field mapping or expression.
QgsExpression * expression()
QString field() const
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Container of fields for a vector layer.
Definition: qgsfield.h:172
QString expressionString() const
void setUseExpression(bool use)
void setField(const QString &field)
void setExpressionParams(QMap< QString, QVariant > params)
QMap< QString, QVariant > expressionParams() const
bool useExpression() const
bool expressionIsPrepared() const
Returns whether the data defined object's expression is prepared.
Represents a vector layer which manages a vector based data sets.
bool isActive() const