QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 "qgsfield.h"
19 #include "qgsvectorlayer.h"
20 
21 #include <QStringList>
22 
23 class QgsExpression;
24 
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 
55  ~QgsDataDefined();
56 
62  bool hasDefaultValues() const;
63 
64  bool isActive() const { return mActive; }
65  void setActive( bool active ) { mActive = active; }
66 
67  bool useExpression() const { return mUseExpression; }
68  void setUseExpression( bool use ) { mUseExpression = use; }
69 
70  QString expressionString() const { return mExpressionString; }
71  void setExpressionString( const QString& expr );
72 
73  // @note not available in python bindings
74  QMap<QString, QVariant> expressionParams() const { return mExpressionParams; }
75  // @note not available in python bindings
76  void setExpressionParams( QMap<QString, QVariant> params ) { mExpressionParams = params; }
77  void insertExpressionParam( QString key, QVariant param );
78 
79  bool prepareExpression( QgsVectorLayer* layer );
80  bool expressionIsPrepared() const { return mExpressionPrepared; }
81 
82  QgsExpression* expression() { return mExpression; }
83  QStringList referencedColumns( QgsVectorLayer* layer );
84 
85  QString field() const { return mField; }
86  void setField( const QString& field ) { mField = field; }
87 
88  // @note not available in python bindings
89  QMap< QString, QString > toMap();
90 
98  QDomElement toXmlElement( QDomDocument &document, const QString &elementName ) const;
99 
107  bool setFromXmlElement( const QDomElement& element );
108 
109  bool operator==( const QgsDataDefined &other ) const;
110  bool operator!=( const QgsDataDefined &other ) const;
111 
112  private:
113  QgsExpression* mExpression;
114 
115  bool mActive;
116  bool mUseExpression;
117  QString mExpressionString;
118  QString mField;
119 
120  QMap<QString, QVariant> mExpressionParams;
121  bool mExpressionPrepared;
122  QStringList mExprRefColmuns;
123 };
124 
125 #endif // QGSDATADEFINED_H