QGIS API Documentation  2.99.0-Master (08ee180)
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 #include "qgsfields.h"
23 
24 class QgsVectorLayer;
25 
33 class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
34 {
35  Q_OBJECT
36 
37  Q_PROPERTY( bool allowExpression READ allowExpression WRITE setAllowExpression )
38  Q_PROPERTY( bool allowEmptyFieldName READ allowEmptyFieldName WRITE setAllowEmptyFieldName )
39  Q_PROPERTY( QgsVectorLayer* layer READ layer WRITE setLayer )
40 
41  public:
42 
45  {
46  FieldNameRole = Qt::UserRole + 1,
47  FieldIndexRole = Qt::UserRole + 2,
48  ExpressionRole = Qt::UserRole + 3,
49  IsExpressionRole = Qt::UserRole + 4,
50  ExpressionValidityRole = Qt::UserRole + 5,
51  FieldTypeRole = Qt::UserRole + 6,
52  FieldOriginRole = Qt::UserRole + 7,
53  IsEmptyRole = Qt::UserRole + 8,
54  };
55 
59  explicit QgsFieldModel( QObject *parent = nullptr );
60 
64  QModelIndex indexFromName( const QString &fieldName );
65 
71  void setAllowExpression( bool allowExpression );
72 
77  bool allowExpression() { return mAllowExpression; }
78 
84  void setAllowEmptyFieldName( bool allowEmpty );
85 
91  bool allowEmptyFieldName() const { return mAllowEmpty; }
92 
97  bool isField( const QString& expression ) const;
98 
105  void setExpression( const QString &expression );
106 
112  void removeExpression();
113 
118  QgsVectorLayer* layer() { return mLayer; }
119 
120  // QAbstractItemModel interface
121  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
122  QModelIndex parent( const QModelIndex &child ) const override;
123  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
124  int columnCount( const QModelIndex &parent ) const override;
125  QVariant data( const QModelIndex &index, int role ) const override;
126 
127  public slots:
128 
133  void setLayer( QgsVectorLayer *layer );
134 
135  protected slots:
136 
140  virtual void updateModel();
141 
142  private slots:
143  void layerDeleted();
144 
145  protected:
147  QList<QString> mExpression;
148 
152 
153  private:
154  void fetchFeature();
155 };
156 
157 #endif // QGSFIELDMODEL_H
static unsigned index
Container of fields for a vector layer.
Definition: qgsfields.h:36
The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
Definition: qgsfieldmodel.h:33
QgsVectorLayer * layer()
Returns the layer associated with the model.
bool allowEmptyFieldName() const
Returns true if the model allows the empty field ("not set") choice.
Definition: qgsfieldmodel.h:91
FieldRoles
Roles utilised by the model.
Definition: qgsfieldmodel.h:44
QgsFields mFields
QList< QString > mExpression
QgsVectorLayer * mLayer
Represents a vector layer which manages a vector based data sets.
bool allowExpression()
Returns true if the model allows custom expressions to be created and displayed.
Definition: qgsfieldmodel.h:77