QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 <QComboBox>
21 #include <QItemSelectionModel>
22 
23 #include "qgsfields.h"
24 #include "qgis_core.h"
25 
26 #include "qgis_sip.h"
27 
28 class QgsVectorLayer;
29 
37 class CORE_EXPORT QgsFieldModel : public QAbstractItemModel
38 {
39  Q_OBJECT
40 
41  Q_PROPERTY( bool allowExpression READ allowExpression WRITE setAllowExpression )
42  Q_PROPERTY( bool allowEmptyFieldName READ allowEmptyFieldName WRITE setAllowEmptyFieldName )
43  Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer )
44 
45  public:
46 
49  {
50  FieldNameRole = Qt::UserRole + 1,
51  FieldIndexRole = Qt::UserRole + 2,
52  ExpressionRole = Qt::UserRole + 3,
53  IsExpressionRole = Qt::UserRole + 4,
54  ExpressionValidityRole = Qt::UserRole + 5,
55  FieldTypeRole = Qt::UserRole + 6,
56  FieldOriginRole = Qt::UserRole + 7,
57  IsEmptyRole = Qt::UserRole + 8,
58  EditorWidgetType = Qt::UserRole + 9,
59  JoinedFieldIsEditable = Qt::UserRole + 10,
60  };
61 
65  explicit QgsFieldModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
66 
70  QModelIndex indexFromName( const QString &fieldName );
71 
77  void setAllowExpression( bool allowExpression );
78 
83  bool allowExpression() { return mAllowExpression; }
84 
90  void setAllowEmptyFieldName( bool allowEmpty );
91 
97  bool allowEmptyFieldName() const { return mAllowEmpty; }
98 
103  bool isField( const QString &expression ) const;
104 
111  void setExpression( const QString &expression );
112 
118  void removeExpression();
119 
124  QgsVectorLayer *layer() { return mLayer; }
125 
126  // QAbstractItemModel interface
127  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
128  QModelIndex parent( const QModelIndex &child ) const override;
129  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
130  int columnCount( const QModelIndex &parent ) const override;
131  QVariant data( const QModelIndex &index, int role ) const override;
132 
138  static QString fieldToolTip( const QgsField &field );
139 
140  public slots:
141 
146  void setLayer( QgsVectorLayer *layer );
147 
148  protected slots:
149 
153  virtual void updateModel();
154 
155  private slots:
156  void layerDeleted();
157 
158  protected:
160  QList<QString> mExpression;
161 
162  QgsVectorLayer *mLayer = nullptr;
163  bool mAllowExpression = false;
164  bool mAllowEmpty = false;
165 
166  private:
167  void fetchFeature();
168 };
169 
170 #endif // QGSFIELDMODEL_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Container of fields for a vector layer.
Definition: qgsfields.h:42
The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
Definition: qgsfieldmodel.h:37
QgsVectorLayer * layer()
Returns the layer associated with the model.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
FieldRoles
Roles utilized by the model.
Definition: qgsfieldmodel.h:48
QgsFields mFields
QList< QString > mExpression
bool allowEmptyFieldName() const
Returns true if the model allows the empty field ("not set") choice.
Definition: qgsfieldmodel.h:97
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:83