QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
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
28class QgsVectorLayer;
29
38class CORE_EXPORT QgsFieldModel : public QAbstractItemModel
39{
40 Q_OBJECT
41
42 Q_PROPERTY( bool allowExpression READ allowExpression WRITE setAllowExpression )
43 Q_PROPERTY( bool allowEmptyFieldName READ allowEmptyFieldName WRITE setAllowEmptyFieldName )
44 Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer )
45
46 public:
47
50 {
51 FieldNameRole = Qt::UserRole + 1,
52 FieldIndexRole = Qt::UserRole + 2,
53 ExpressionRole = Qt::UserRole + 3,
54 IsExpressionRole = Qt::UserRole + 4,
55 ExpressionValidityRole = Qt::UserRole + 5,
56 FieldTypeRole = Qt::UserRole + 6,
57 FieldOriginRole = Qt::UserRole + 7,
58 IsEmptyRole = Qt::UserRole + 8,
59 EditorWidgetType = Qt::UserRole + 9,
60 JoinedFieldIsEditable = Qt::UserRole + 10,
61 FieldIsWidgetEditable = Qt::UserRole + 11,
62 };
63
67 explicit QgsFieldModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
68
72 QModelIndex indexFromName( const QString &fieldName );
73
79 void setAllowExpression( bool allowExpression );
80
85 bool allowExpression() { return mAllowExpression; }
86
92 void setAllowEmptyFieldName( bool allowEmpty );
93
99 bool allowEmptyFieldName() const { return mAllowEmpty; }
100
105 bool isField( const QString &expression ) const;
106
113 void setExpression( const QString &expression );
114
120 void removeExpression();
121
126 QgsVectorLayer *layer() { return mLayer; }
127
128 // QAbstractItemModel interface
129 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
130 QModelIndex parent( const QModelIndex &child ) const override;
131 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
132 int columnCount( const QModelIndex &parent ) const override;
133 QVariant data( const QModelIndex &index, int role ) const override;
134
140 static QString fieldToolTip( const QgsField &field );
141
147 static QString fieldToolTipExtended( const QgsField &field, const QgsVectorLayer *layer );
148
159 void setFields( const QgsFields &fields );
160
169 QgsFields fields() const;
170
171 public slots:
172
177 void setLayer( QgsVectorLayer *layer );
178
179 protected slots:
180
184 virtual void updateModel();
185
186 private slots:
187 void layerDeleted();
188
189 protected:
191 QList<QString> mExpression;
192
193 QgsVectorLayer *mLayer = nullptr;
194 bool mAllowExpression = false;
195 bool mAllowEmpty = false;
196
197 private:
198 void fetchFeature();
199};
200
201#endif // QGSFIELDMODEL_H
The QgsFieldModel class is a model to display the list of fields in widgets (optionally associated wi...
Definition: qgsfieldmodel.h:39
FieldRoles
Roles utilized by the model.
Definition: qgsfieldmodel.h:50
bool allowEmptyFieldName() const
Returns true if the model allows the empty field ("not set") choice.
Definition: qgsfieldmodel.h:99
QgsVectorLayer * layer()
Returns the layer associated with the model.
QgsFields mFields
bool allowExpression()
Returns true if the model allows custom expressions to be created and displayed.
Definition: qgsfieldmodel.h:85
QList< QString > mExpression
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:52
Container of fields for a vector layer.
Definition: qgsfields.h:45
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
const QgsField & field
Definition: qgsfield.h:501