QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
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 "qgis_core.h"
20
#include "
qgis_sip.h
"
21
#include "
qgsfields.h
"
22
23
#include <QAbstractItemModel>
24
#include <QComboBox>
25
#include <QItemSelectionModel>
26
27
class
QgsVectorLayer
;
28
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
// *INDENT-OFF*
47
54
enum class
CustomRole
SIP_MONKEYPATCH_SCOPEENUM_UNNEST
(
QgsFieldModel
, FieldRoles ) :
int
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
131
QgsVectorLayer
*
layer
() {
return
mLayer
; }
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
145
static
QString fieldToolTip(
const
QgsField
&field,
const
QString &predefinedComment = QString() );
146
153
static
QString fieldToolTipExtended(
const
QgsField
&field,
const
QgsVectorLayer
*layer,
const
QString &predefinedComment = QString() );
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
:
196
QgsFields
mFields
;
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
QgsFieldModel
A model which displays the list of fields in widgets (optionally associated with a vector layer).
Definition
qgsfieldmodel.h:38
QgsFieldModel::mAllowEmpty
bool mAllowEmpty
Definition
qgsfieldmodel.h:201
QgsFieldModel::allowEmptyFieldName
bool allowEmptyFieldName() const
Returns true if the model allows the empty field ("not set") choice.
Definition
qgsfieldmodel.h:104
QgsFieldModel::setAllowExpression
void setAllowExpression(bool allowExpression)
Sets whether custom expressions are accepted and displayed in the model.
Definition
qgsfieldmodel.cpp:182
QgsFieldModel::CustomRole
CustomRole
Custom model roles.
Definition
qgsfieldmodel.h:55
QgsFieldModel::setLayer
void setLayer(QgsVectorLayer *layer)
Set the layer from which fields are displayed.
Definition
qgsfieldmodel.cpp:84
QgsFieldModel::layer
QgsVectorLayer * layer()
Returns the layer associated with the model.
Definition
qgsfieldmodel.h:131
QgsFieldModel::mFields
QgsFields mFields
Definition
qgsfieldmodel.h:196
QgsFieldModel::QgsFieldModel
QgsFieldModel(QObject *parent=nullptr)
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
Definition
qgsfieldmodel.cpp:29
QgsFieldModel::allowExpression
bool allowExpression
Definition
qgsfieldmodel.h:41
QgsFieldModel::allowExpression
bool allowExpression() const
Returns true if the model allows custom expressions to be created and displayed.
Definition
qgsfieldmodel.h:92
QgsFieldModel::allowEmptyFieldName
bool allowEmptyFieldName
Definition
qgsfieldmodel.h:42
QgsFieldModel::mAllowExpression
bool mAllowExpression
Definition
qgsfieldmodel.h:200
QgsFieldModel::layer
QgsVectorLayer * layer
Definition
qgsfieldmodel.h:43
QgsFieldModel::mExpression
QList< QString > mExpression
Definition
qgsfieldmodel.h:197
QgsFieldModel::setAllowEmptyFieldName
void setAllowEmptyFieldName(bool allowEmpty)
Sets whether an optional empty field ("not set") option is present in the model.
Definition
qgsfieldmodel.cpp:199
QgsFieldModel::mLayer
QgsVectorLayer * mLayer
Definition
qgsfieldmodel.h:199
QgsField
Encapsulate a field in an attribute table or data source.
Definition
qgsfield.h:56
QgsFields
Container of fields for a vector layer.
Definition
qgsfields.h:45
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
qgis_sip.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition
qgis_sip.h:52
SIP_MONKEYPATCH_SCOPEENUM_UNNEST
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition
qgis_sip.h:270
SIP_MONKEYPATCH_COMPAT_NAME
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition
qgis_sip.h:272
qgsfields.h
Generated on
for QGIS API Documentation by
1.17.0