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 
52  explicit QgsDataDefined( const QgsExpression * expression );
53 
60  explicit QgsDataDefined( const QString& string );
61 
66  QgsDataDefined( const QgsDataDefined& other );
67 
68  virtual ~QgsDataDefined();
69 
75  bool hasDefaultValues() const;
76 
77  bool isActive() const { return mActive; }
78  void setActive( bool active ) { mActive = active; }
79 
80  bool useExpression() const { return mUseExpression; }
81  void setUseExpression( bool use ) { mUseExpression = use; }
82 
83  QString expressionString() const { return mExpressionString; }
84  void setExpressionString( const QString& expr );
85 
86  // @note not available in python bindings
87  QMap<QString, QVariant> expressionParams() const { return mExpressionParams; }
88  // @note not available in python bindings
89  void setExpressionParams( QMap<QString, QVariant> params ) { mExpressionParams = params; }
90  void insertExpressionParam( QString key, QVariant param );
91 
96  bool prepareExpression( QgsVectorLayer* layer );
97 
103  bool prepareExpression( const QgsFields &fields );
104 
108  bool expressionIsPrepared() const { return mExpressionPrepared; }
109 
110  QgsExpression* expression() { return mExpression; }
111  QStringList referencedColumns( QgsVectorLayer* layer );
112 
113  QString field() const { return mField; }
114  void setField( const QString& field ) { mField = field; }
115 
116  // @note not available in python bindings
117  QMap< QString, QString > toMap();
118 
126  QDomElement toXmlElement( QDomDocument &document, const QString &elementName ) const;
127 
135  bool setFromXmlElement( const QDomElement& element );
136 
137  bool operator==( const QgsDataDefined &other ) const;
138  bool operator!=( const QgsDataDefined &other ) const;
139 
143  QgsDataDefined& operator=( QgsDataDefined const & rhs );
144 
145  private:
146  QgsExpression* mExpression;
147 
148  bool mActive;
149  bool mUseExpression;
150  QString mExpressionString;
151  QString mField;
152 
153  QMap<QString, QVariant> mExpressionParams;
154  bool mExpressionPrepared;
155  QStringList mExprRefColumns;
156 
157 };
158 
159 #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:167
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