QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsfieldmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldmodel.h
3  --------------------------------------
4  Date : 01.04.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
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 
16 #ifndef QGSFIELDMODEL_H
17 #define QGSFIELDMODEL_H
18 
19 #include <QAbstractItemModel>
20 #include <QItemSelectionModel>
21 #include <QComboBox>
22 
23 #include "qgsvectorlayer.h"
24 
31 class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
32 {
33  Q_OBJECT
34  public:
36  {
37  FieldNameRole = Qt::UserRole + 1, /* return field name if index corresponds to a field */
38  FieldIndexRole = Qt::UserRole + 2, /* return field index if index corresponds to a field */
39  ExpressionRole = Qt::UserRole + 3, /* return field name or expression */
40  IsExpressionRole = Qt::UserRole + 4, /* return if index corresponds to an expression */
41  ExpressionValidityRole = Qt::UserRole + 5, /* return if expression is valid or not */
42  FieldTypeRole = Qt::UserRole + 6 /* return the field type (if a field, return QVariant if expression) */
43  };
44 
48  explicit QgsFieldModel( QObject *parent = 0 );
49 
51  QModelIndex indexFromName( const QString &fieldName );
52 
54  void setAllowExpression( bool allowExpression );
55  bool allowExpression() { return mAllowExpression; }
56 
57  bool isField( const QString& expression );
58 
62  void setExpression( const QString &expression );
63 
65  void removeExpression();
66 
68  QgsVectorLayer* layer() { return mLayer; }
69 
70  public slots:
72  void setLayer( QgsVectorLayer *layer );
73 
74  protected slots:
75  virtual void updateModel();
76 
77  private slots:
78  void layerDeleted();
79 
80  protected:
82  QList<QString> mExpression;
83 
86 
87  private:
88  void fetchFeature();
89 
90  // QAbstractItemModel interface
91  public:
92  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
93  QModelIndex parent( const QModelIndex &child ) const override;
94  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
95  int columnCount( const QModelIndex &parent ) const override;
96  QVariant data( const QModelIndex &index, int role ) const override;
97 };
98 
99 #endif // QGSFIELDMODEL_H