QGIS API Documentation  2.17.0-Master (3a3b9ab7)
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  FieldOriginRole = Qt::UserRole + 7,
44  };
45 
49  explicit QgsFieldModel( QObject *parent = nullptr );
50 
52  QModelIndex indexFromName( const QString &fieldName );
53 
55  void setAllowExpression( bool allowExpression );
56  bool allowExpression() { return mAllowExpression; }
57 
58  bool isField( const QString& expression );
59 
63  void setExpression( const QString &expression );
64 
66  void removeExpression();
67 
69  QgsVectorLayer* layer() { return mLayer; }
70 
71  // QAbstractItemModel interface
72  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
73  QModelIndex parent( const QModelIndex &child ) const override;
74  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
75  int columnCount( const QModelIndex &parent ) const override;
76  QVariant data( const QModelIndex &index, int role ) const override;
77 
78  public slots:
80  void setLayer( QgsVectorLayer *layer );
81 
82  protected slots:
83  virtual void updateModel();
84 
85  private slots:
86  void layerDeleted();
87 
88  protected:
91 
94 
95  private:
96  void fetchFeature();
97 };
98 
99 #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:209
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:69
virtual QVariant data(const QModelIndex &index, int role) const =0
bool mAllowExpression
Definition: qgsfieldmodel.h:93
virtual int columnCount(const QModelIndex &parent) const =0
QgsFields mFields
Definition: qgsfieldmodel.h:89
QList< QString > mExpression
Definition: qgsfieldmodel.h:90
QgsVectorLayer * mLayer
Definition: qgsfieldmodel.h:92
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
bool allowExpression()
Definition: qgsfieldmodel.h:56