The QgsFieldModel class is a model to display the list of fields in widgets (optionally associated with a vector layer).
More...
#include <qgsfieldmodel.h>
|
enum class | CustomRole : int {
FieldName = Qt::UserRole + 1
, FieldIndex = Qt::UserRole + 2
, Expression = Qt::UserRole + 3
, IsExpression = Qt::UserRole + 4
,
ExpressionValidity = Qt::UserRole + 5
, FieldType = Qt::UserRole + 6
, FieldOrigin = Qt::UserRole + 7
, IsEmpty = Qt::UserRole + 8
,
EditorWidgetType = Qt::UserRole + 9
, JoinedFieldIsEditable = Qt::UserRole + 10
, FieldIsWidgetEditable = Qt::UserRole + 11
} |
| Custom model roles. More...
|
|
|
| QgsFieldModel (QObject *parent=nullptr) |
| Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
|
|
bool | allowEmptyFieldName () const |
| Returns true if the model allows the empty field ("not set") choice.
|
|
bool | allowExpression () |
| Returns true if the model allows custom expressions to be created and displayed.
|
|
int | columnCount (const QModelIndex &parent) const override |
|
QVariant | data (const QModelIndex &index, int role) const override |
|
QgsFields | fields () const |
| Returns the fields currently shown in the model.
|
|
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
|
QModelIndex | indexFromName (const QString &fieldName) |
| Returns the index corresponding to a given fieldName.
|
|
bool | isField (const QString &expression) const |
| Returns true if a string represents a field reference, or false if it is an expression consisting of more than direct field reference.
|
|
QgsVectorLayer * | layer () |
| Returns the layer associated with the model.
|
|
QModelIndex | parent (const QModelIndex &child) const override |
|
void | removeExpression () |
| Removes any custom expression from the model.
|
|
int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
|
void | setAllowEmptyFieldName (bool allowEmpty) |
| Sets whether an optional empty field ("not set") option is present in the model.
|
|
void | setAllowExpression (bool allowExpression) |
| Sets whether custom expressions are accepted and displayed in the model.
|
|
void | setExpression (const QString &expression) |
| Sets a single expression to be added after the fields at the end of the model.
|
|
void | setFields (const QgsFields &fields) |
| Manually sets the fields to use for the model.
|
|
|
static QString | fieldToolTip (const QgsField &field) |
| Returns a HTML formatted tooltip string for a field, containing details like the field name, alias and type.
|
|
static QString | fieldToolTipExtended (const QgsField &field, const QgsVectorLayer *layer) |
| Returns a HTML formatted tooltip string for a field, containing details like the field name, alias, type and expression.
|
|
|
virtual void | updateModel () |
| Called when the model must be updated.
|
|
The QgsFieldModel class is a model to display the list of fields in widgets (optionally associated with a vector layer).
If allowed, expressions might be added to the end of the model. It can be associated with a QgsMapLayerModel to dynamically display a layer and its fields.
Definition at line 38 of file qgsfieldmodel.h.
◆ CustomRole
Custom model roles.
- Note
- Prior to QGIS 3.36 this was available as QgsFieldModel::FieldRoles
- Since
- QGIS 3.36
Enumerator |
---|
FieldName | Return field name if index corresponds to a field.
|
FieldIndex | Return field index if index corresponds to a field.
|
Expression | Return field name or expression.
|
IsExpression | Return if index corresponds to an expression.
|
ExpressionValidity | Return if expression is valid or not.
|
FieldType | Return the field type (if a field, return QVariant if expression)
|
FieldOrigin | Return the field origin (if a field, returns QVariant if expression)
|
IsEmpty | Return if the index corresponds to the empty value.
|
EditorWidgetType | Editor widget type.
|
JoinedFieldIsEditable | true if a joined field is editable (returns QVariant if not a joined field)
|
FieldIsWidgetEditable | true if a is editable from the widget
|
Definition at line 56 of file qgsfieldmodel.h.
◆ QgsFieldModel()
QgsFieldModel::QgsFieldModel |
( |
QObject * |
parent = nullptr | ) |
|
|
explicit |
◆ allowEmptyFieldName()
bool QgsFieldModel::allowEmptyFieldName |
( |
| ) |
const |
|
inline |
◆ allowExpression()
bool QgsFieldModel::allowExpression |
( |
| ) |
|
|
inline |
◆ columnCount()
int QgsFieldModel::columnCount |
( |
const QModelIndex & |
parent | ) |
const |
|
override |
◆ data()
QVariant QgsFieldModel::data |
( |
const QModelIndex & |
index, |
|
|
int |
role |
|
) |
| const |
|
override |
◆ fields()
Returns the fields currently shown in the model.
This will either be fields from the associated layer() or the fields manually set by a call to setFields().
- Since
- QGIS 3.14
Definition at line 526 of file qgsfieldmodel.cpp.
◆ fieldToolTip()
QString QgsFieldModel::fieldToolTip |
( |
const QgsField & |
field | ) |
|
|
static |
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias and type.
Definition at line 473 of file qgsfieldmodel.cpp.
◆ fieldToolTipExtended()
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias, type and expression.
- Since
- QGIS 3.14
Definition at line 497 of file qgsfieldmodel.cpp.
◆ index()
QModelIndex QgsFieldModel::index |
( |
int |
row, |
|
|
int |
column, |
|
|
const QModelIndex & |
parent = QModelIndex() |
|
) |
| const |
|
override |
◆ indexFromName()
QModelIndex QgsFieldModel::indexFromName |
( |
const QString & |
fieldName | ) |
|
Returns the index corresponding to a given fieldName.
Definition at line 29 of file qgsfieldmodel.cpp.
◆ isField()
bool QgsFieldModel::isField |
( |
const QString & |
expression | ) |
const |
Returns true
if a string represents a field reference, or false
if it is an expression consisting of more than direct field reference.
Definition at line 74 of file qgsfieldmodel.cpp.
◆ layer()
◆ parent()
QModelIndex QgsFieldModel::parent |
( |
const QModelIndex & |
child | ) |
const |
|
override |
◆ removeExpression()
void QgsFieldModel::removeExpression |
( |
| ) |
|
◆ rowCount()
int QgsFieldModel::rowCount |
( |
const QModelIndex & |
parent = QModelIndex() | ) |
const |
|
override |
◆ setAllowEmptyFieldName()
void QgsFieldModel::setAllowEmptyFieldName |
( |
bool |
allowEmpty | ) |
|
◆ setAllowExpression()
void QgsFieldModel::setAllowExpression |
( |
bool |
allowExpression | ) |
|
◆ setExpression()
void QgsFieldModel::setExpression |
( |
const QString & |
expression | ) |
|
◆ setFields()
void QgsFieldModel::setFields |
( |
const QgsFields & |
fields | ) |
|
Manually sets the fields to use for the model.
This method should only be used when the model ISN'T associated with a layer() and needs to show the fields from an arbitrary field collection instead. Calling setFields() will automatically clear any existing layer().
- See also
- fields()
- Since
- QGIS 3.14
Definition at line 518 of file qgsfieldmodel.cpp.
◆ setLayer
◆ updateModel
void QgsFieldModel::updateModel |
( |
| ) |
|
|
protectedvirtualslot |
◆ mAllowEmpty
bool QgsFieldModel::mAllowEmpty = false |
|
protected |
◆ mAllowExpression
bool QgsFieldModel::mAllowExpression = false |
|
protected |
◆ mExpression
QList<QString> QgsFieldModel::mExpression |
|
protected |
◆ mFields
◆ mLayer
◆ allowEmptyFieldName
bool QgsFieldModel::allowEmptyFieldName |
|
readwrite |
◆ allowExpression
bool QgsFieldModel::allowExpression |
|
readwrite |
◆ layer
The documentation for this class was generated from the following files: