QGIS API Documentation  2.14.0-Essen
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,
38  FieldIndexRole = Qt::UserRole + 2,
39  ExpressionRole = Qt::UserRole + 3,
40  IsExpressionRole = Qt::UserRole + 4,
41  ExpressionValidityRole = Qt::UserRole + 5,
42  FieldTypeRole = Qt::UserRole + 6
43  };
44 
48  explicit QgsFieldModel( QObject *parent = nullptr );
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  // QAbstractItemModel interface
71  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
72  QModelIndex parent( const QModelIndex &child ) const override;
73  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
74  int columnCount( const QModelIndex &parent ) const override;
75  QVariant data( const QModelIndex &index, int role ) const override;
76 
77  public slots:
79  void setLayer( QgsVectorLayer *layer );
80 
81  protected slots:
82  virtual void updateModel();
83 
84  private slots:
85  void layerDeleted();
86 
87  protected:
90 
93 
94  private:
95  void fetchFeature();
96 };
97 
98 #endif // QGSFIELDMODEL_H
virtual int rowCount(const QModelIndex &parent) const =0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
Container of fields for a vector layer.
Definition: qgsfield.h:187
The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
Definition: qgsfieldmodel.h:31
QgsVectorLayer * layer()
returns the currently used layer
Definition: qgsfieldmodel.h:68
virtual QVariant data(const QModelIndex &index, int role) const =0
bool mAllowExpression
Definition: qgsfieldmodel.h:92
virtual int columnCount(const QModelIndex &parent) const =0
QgsFields mFields
Definition: qgsfieldmodel.h:88
QList< QString > mExpression
Definition: qgsfieldmodel.h:89
QgsVectorLayer * mLayer
Definition: qgsfieldmodel.h:91
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
bool allowExpression()
Definition: qgsfieldmodel.h:55