QGIS API Documentation 4.1.0-Master (60fea48833c)
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 "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsfields.h"
22
23#include <QAbstractItemModel>
24#include <QComboBox>
25#include <QItemSelectionModel>
26
27class QgsVectorLayer;
28
37class CORE_EXPORT QgsFieldModel : public QAbstractItemModel
38{
39 Q_OBJECT
40
43 Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer )
44
45 public:
46 // *INDENT-OFF*
47
55 {
56 FieldName SIP_MONKEYPATCH_COMPAT_NAME( FieldNameRole ) = Qt::UserRole + 1,
57 FieldIndex SIP_MONKEYPATCH_COMPAT_NAME( FieldIndexRole ) = Qt::UserRole + 2,
58 Expression SIP_MONKEYPATCH_COMPAT_NAME( ExpressionRole ) = Qt::UserRole + 3,
59 IsExpression SIP_MONKEYPATCH_COMPAT_NAME( IsExpressionRole ) = Qt::UserRole + 4,
60 ExpressionValidity SIP_MONKEYPATCH_COMPAT_NAME( ExpressionValidityRole ) = Qt::UserRole + 5,
61 FieldType SIP_MONKEYPATCH_COMPAT_NAME( FieldTypeRole ) = Qt::UserRole + 6,
62 FieldOrigin SIP_MONKEYPATCH_COMPAT_NAME( FieldOriginRole ) = Qt::UserRole + 7,
63 IsEmpty SIP_MONKEYPATCH_COMPAT_NAME( IsEmptyRole ) = Qt::UserRole + 8,
64 EditorWidgetType = Qt::UserRole + 9,
65 JoinedFieldIsEditable = Qt::UserRole + 10,
66 FieldIsWidgetEditable = Qt::UserRole + 11,
67 };
68 Q_ENUM( CustomRole )
69 // *INDENT-ON*
70
71
74 explicit QgsFieldModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
75
79 QModelIndex indexFromName( const QString &fieldName );
80
86 void setAllowExpression( bool allowExpression );
87
92 bool allowExpression() const { return mAllowExpression; }
93
98 void setAllowEmptyFieldName( bool allowEmpty );
99
104 bool allowEmptyFieldName() const { return mAllowEmpty; }
105
110 bool isField( const QString &expression ) const;
111
118 void setExpression( const QString &expression );
119
125 void removeExpression();
126
132
133 // QAbstractItemModel interface
134 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
135 QModelIndex parent( const QModelIndex &child ) const override;
136 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
137 int columnCount( const QModelIndex &parent ) const override;
138 QVariant data( const QModelIndex &index, int role ) const override;
139
144 static QString fieldToolTip( const QgsField &field );
145
151 static QString fieldToolTipExtended( const QgsField &field, const QgsVectorLayer *layer );
152
163 void setFields( const QgsFields &fields );
164
173 QgsFields fields() const;
174
175 public slots:
176
181 void setLayer( QgsVectorLayer *layer );
182
183 protected slots:
184
188 virtual void updateModel();
189
190 private slots:
191 void layerDeleted();
192
193 protected:
195 QList<QString> mExpression;
196
198 bool mAllowExpression = false;
199 bool mAllowEmpty = false;
200
201 private:
202 void fetchFeature();
203};
204
205#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.
void setAllowExpression(bool allowExpression)
Sets whether custom expressions are accepted and displayed in the model.
CustomRole
Custom model roles.
void setLayer(QgsVectorLayer *layer)
Set the layer from which fields are displayed.
QgsVectorLayer * layer()
Returns the layer associated with the model.
QgsFields mFields
QgsFieldModel(QObject *parent=nullptr)
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
bool allowExpression() const
Returns true if the model allows custom expressions to be created and displayed.
bool allowEmptyFieldName
QgsVectorLayer * layer
QList< QString > mExpression
void setAllowEmptyFieldName(bool allowEmpty)
Sets whether an optional empty field ("not set") option is present in the model.
QgsVectorLayer * mLayer
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
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:52
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269