QGIS API Documentation 3.39.0-Master (67e056379ed)
Loading...
Searching...
No Matches
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
37class 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
47 // *INDENT-OFF*
48
56 {
57 FieldName SIP_MONKEYPATCH_COMPAT_NAME(FieldNameRole) = Qt::UserRole + 1,
58 FieldIndex SIP_MONKEYPATCH_COMPAT_NAME(FieldIndexRole) = Qt::UserRole + 2,
59 Expression SIP_MONKEYPATCH_COMPAT_NAME(ExpressionRole) = Qt::UserRole + 3,
60 IsExpression SIP_MONKEYPATCH_COMPAT_NAME(IsExpressionRole) = Qt::UserRole + 4,
61 ExpressionValidity SIP_MONKEYPATCH_COMPAT_NAME(ExpressionValidityRole) = Qt::UserRole + 5,
62 FieldType SIP_MONKEYPATCH_COMPAT_NAME(FieldTypeRole) = Qt::UserRole + 6,
63 FieldOrigin SIP_MONKEYPATCH_COMPAT_NAME(FieldOriginRole) = Qt::UserRole + 7,
64 IsEmpty SIP_MONKEYPATCH_COMPAT_NAME(IsEmptyRole) = Qt::UserRole + 8,
65 EditorWidgetType = Qt::UserRole + 9,
66 JoinedFieldIsEditable = Qt::UserRole + 10,
67 FieldIsWidgetEditable = Qt::UserRole + 11,
68 };
69 Q_ENUM( CustomRole )
70 // *INDENT-ON*
71
72
75 explicit QgsFieldModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
76
80 QModelIndex indexFromName( const QString &fieldName );
81
87 void setAllowExpression( bool allowExpression );
88
93 bool allowExpression() { return mAllowExpression; }
94
99 void setAllowEmptyFieldName( bool allowEmpty );
100
105 bool allowEmptyFieldName() const { return mAllowEmpty; }
106
111 bool isField( const QString &expression ) const;
112
119 void setExpression( const QString &expression );
120
126 void removeExpression();
127
132 QgsVectorLayer *layer() { return mLayer; }
133
134 // QAbstractItemModel interface
135 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
136 QModelIndex parent( const QModelIndex &child ) const override;
137 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
138 int columnCount( const QModelIndex &parent ) const override;
139 QVariant data( const QModelIndex &index, int role ) const override;
140
145 static QString fieldToolTip( const QgsField &field );
146
152 static QString fieldToolTipExtended( const QgsField &field, const QgsVectorLayer *layer );
153
164 void setFields( const QgsFields &fields );
165
174 QgsFields fields() const;
175
176 public slots:
177
182 void setLayer( QgsVectorLayer *layer );
183
184 protected slots:
185
189 virtual void updateModel();
190
191 private slots:
192 void layerDeleted();
193
194 protected:
196 QList<QString> mExpression;
197
198 QgsVectorLayer *mLayer = nullptr;
199 bool mAllowExpression = false;
200 bool mAllowEmpty = false;
201
202 private:
203 void fetchFeature();
204};
205
206#endif // QGSFIELDMODEL_H
The QgsFieldModel class is a model to display the list of fields in widgets (optionally associated wi...
bool allowEmptyFieldName() const
Returns true if the model allows the empty field ("not set") choice.
CustomRole
Custom model roles.
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.
QList< QString > mExpression
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273