QGIS API Documentation  2.99.0-Master (08c2e66)
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 : denis.rouzaud@gmail.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 
16 #ifndef QGSFIELDMODEL_H
17 #define QGSFIELDMODEL_H
18 
19 #include <QAbstractItemModel>
20 #include <QItemSelectionModel>
21 #include <QComboBox>
22 #include "qgsfields.h"
23 #include "qgis_gui.h"
24 
25 class QgsVectorLayer;
26 
34 class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
35 {
36  Q_OBJECT
37 
38  Q_PROPERTY( bool allowExpression READ allowExpression WRITE setAllowExpression )
39  Q_PROPERTY( bool allowEmptyFieldName READ allowEmptyFieldName WRITE setAllowEmptyFieldName )
40  Q_PROPERTY( QgsVectorLayer* layer READ layer WRITE setLayer )
41 
42  public:
43 
46  {
47  FieldNameRole = Qt::UserRole + 1,
48  FieldIndexRole = Qt::UserRole + 2,
49  ExpressionRole = Qt::UserRole + 3,
50  IsExpressionRole = Qt::UserRole + 4,
51  ExpressionValidityRole = Qt::UserRole + 5,
52  FieldTypeRole = Qt::UserRole + 6,
53  FieldOriginRole = Qt::UserRole + 7,
54  IsEmptyRole = Qt::UserRole + 8,
55  };
56 
60  explicit QgsFieldModel( QObject *parent = nullptr );
61 
65  QModelIndex indexFromName( const QString &fieldName );
66 
72  void setAllowExpression( bool allowExpression );
73 
78  bool allowExpression() { return mAllowExpression; }
79 
85  void setAllowEmptyFieldName( bool allowEmpty );
86 
92  bool allowEmptyFieldName() const { return mAllowEmpty; }
93 
98  bool isField( const QString& expression ) const;
99 
106  void setExpression( const QString &expression );
107 
113  void removeExpression();
114 
119  QgsVectorLayer* layer() { return mLayer; }
120 
121  // QAbstractItemModel interface
122  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
123  QModelIndex parent( const QModelIndex &child ) const override;
124  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
125  int columnCount( const QModelIndex &parent ) const override;
126  QVariant data( const QModelIndex &index, int role ) const override;
127 
128  public slots:
129 
134  void setLayer( QgsVectorLayer *layer );
135 
136  protected slots:
137 
141  virtual void updateModel();
142 
143  private slots:
144  void layerDeleted();
145 
146  protected:
148  QList<QString> mExpression;
149 
150  QgsVectorLayer* mLayer = nullptr;
153 
154  private:
155  void fetchFeature();
156 };
157 
158 #endif // QGSFIELDMODEL_H
static unsigned index
Container of fields for a vector layer.
Definition: qgsfields.h:39
The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
Definition: qgsfieldmodel.h:34
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:92
FieldRoles
Roles utilised by the model.
Definition: qgsfieldmodel.h:45
QgsFields mFields
QList< QString > mExpression
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:78