QGIS API Documentation 3.43.0-Master (c67cf405802)
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 <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
48 // *INDENT-OFF*
49
57 {
58 FieldName SIP_MONKEYPATCH_COMPAT_NAME(FieldNameRole) = Qt::UserRole + 1,
59 FieldIndex SIP_MONKEYPATCH_COMPAT_NAME(FieldIndexRole) = Qt::UserRole + 2,
60 Expression SIP_MONKEYPATCH_COMPAT_NAME(ExpressionRole) = Qt::UserRole + 3,
61 IsExpression SIP_MONKEYPATCH_COMPAT_NAME(IsExpressionRole) = Qt::UserRole + 4,
62 ExpressionValidity SIP_MONKEYPATCH_COMPAT_NAME(ExpressionValidityRole) = Qt::UserRole + 5,
63 FieldType SIP_MONKEYPATCH_COMPAT_NAME(FieldTypeRole) = Qt::UserRole + 6,
64 FieldOrigin SIP_MONKEYPATCH_COMPAT_NAME(FieldOriginRole) = Qt::UserRole + 7,
65 IsEmpty SIP_MONKEYPATCH_COMPAT_NAME(IsEmptyRole) = Qt::UserRole + 8,
66 EditorWidgetType = Qt::UserRole + 9,
67 JoinedFieldIsEditable = Qt::UserRole + 10,
68 FieldIsWidgetEditable = Qt::UserRole + 11,
69 };
70 Q_ENUM( CustomRole )
71 // *INDENT-ON*
72
73
76 explicit QgsFieldModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
77
81 QModelIndex indexFromName( const QString &fieldName );
82
88 void setAllowExpression( bool allowExpression );
89
94 bool allowExpression() { return mAllowExpression; }
95
100 void setAllowEmptyFieldName( bool allowEmpty );
101
106 bool allowEmptyFieldName() const { return mAllowEmpty; }
107
112 bool isField( const QString &expression ) const;
113
120 void setExpression( const QString &expression );
121
127 void removeExpression();
128
133 QgsVectorLayer *layer() { return mLayer; }
134
135 // QAbstractItemModel interface
136 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
137 QModelIndex parent( const QModelIndex &child ) const override;
138 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
139 int columnCount( const QModelIndex &parent ) const override;
140 QVariant data( const QModelIndex &index, int role ) const override;
141
146 static QString fieldToolTip( const QgsField &field );
147
153 static QString fieldToolTipExtended( const QgsField &field, const QgsVectorLayer *layer );
154
165 void setFields( const QgsFields &fields );
166
175 QgsFields fields() const;
176
177 public slots:
178
183 void setLayer( QgsVectorLayer *layer );
184
185 protected slots:
186
190 virtual void updateModel();
191
192 private slots:
193 void layerDeleted();
194
195 protected:
197 QList<QString> mExpression;
198
199 QgsVectorLayer *mLayer = nullptr;
200 bool mAllowExpression = false;
201 bool mAllowEmpty = false;
202
203 private:
204 void fetchFeature();
205};
206
207#endif // QGSFIELDMODEL_H
A model which displays the list of fields in widgets (optionally associated with a vector layer).
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 dataset.
#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