QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
|
The QgsFieldModel class is a model to display the list of fields in widgets (optionally associated with a vector layer). More...
#include <qgsfieldmodel.h>
Public Types | |
enum | FieldRoles { FieldNameRole = Qt::UserRole + 1 , FieldIndexRole = Qt::UserRole + 2 , ExpressionRole = Qt::UserRole + 3 , IsExpressionRole = Qt::UserRole + 4 , ExpressionValidityRole = Qt::UserRole + 5 , FieldTypeRole = Qt::UserRole + 6 , FieldOriginRole = Qt::UserRole + 7 , IsEmptyRole = Qt::UserRole + 8 , EditorWidgetType = Qt::UserRole + 9 , JoinedFieldIsEditable = Qt::UserRole + 10 , FieldIsWidgetEditable = Qt::UserRole + 11 } |
Roles utilized by the model. More... | |
Public Slots | |
void | setLayer (QgsVectorLayer *layer) |
Set the layer from which fields are displayed. More... | |
Public Member Functions | |
QgsFieldModel (QObject *parent=nullptr) | |
Constructor for QgsFieldModel - creates a model to display the fields of a given layer. More... | |
bool | allowEmptyFieldName () const |
Returns true if the model allows the empty field ("not set") choice. More... | |
bool | allowExpression () |
Returns true if the model allows custom expressions to be created and displayed. More... | |
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. More... | |
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. More... | |
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. More... | |
QgsVectorLayer * | layer () |
Returns the layer associated with the model. More... | |
QModelIndex | parent (const QModelIndex &child) const override |
void | removeExpression () |
Removes any custom expression from the model. More... | |
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. More... | |
void | setAllowExpression (bool allowExpression) |
Sets whether custom expressions are accepted and displayed in the model. More... | |
void | setExpression (const QString &expression) |
Sets a single expression to be added after the fields at the end of the model. More... | |
void | setFields (const QgsFields &fields) |
Manually sets the fields to use for the model. More... | |
Static Public Member Functions | |
static QString | fieldToolTip (const QgsField &field) |
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias and type. More... | |
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. More... | |
Protected Slots | |
virtual void | updateModel () |
Called when the model must be updated. More... | |
Protected Attributes | |
bool | mAllowEmpty = false |
bool | mAllowExpression = false |
QList< QString > | mExpression |
QgsFields | mFields |
QgsVectorLayer * | mLayer = nullptr |
Properties | |
bool | allowEmptyFieldName |
bool | allowExpression |
QgsVectorLayer * | layer |
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.
Roles utilized by the model.
Definition at line 49 of file qgsfieldmodel.h.
|
explicit |
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
Definition at line 27 of file qgsfieldmodel.cpp.
|
inline |
Returns true
if the model allows the empty field ("not set") choice.
Definition at line 99 of file qgsfieldmodel.h.
|
inline |
Returns true
if the model allows custom expressions to be created and displayed.
Definition at line 85 of file qgsfieldmodel.h.
|
override |
Definition at line 267 of file qgsfieldmodel.cpp.
|
override |
Definition at line 273 of file qgsfieldmodel.cpp.
QgsFields QgsFieldModel::fields | ( | ) | const |
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().
Definition at line 529 of file qgsfieldmodel.cpp.
|
static |
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias and type.
Definition at line 476 of file qgsfieldmodel.cpp.
|
static |
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias, type and expression.
Definition at line 500 of file qgsfieldmodel.cpp.
|
override |
Definition at line 241 of file qgsfieldmodel.cpp.
QModelIndex QgsFieldModel::indexFromName | ( | const QString & | fieldName | ) |
Returns the index corresponding to a given fieldName.
Definition at line 32 of file qgsfieldmodel.cpp.
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 77 of file qgsfieldmodel.cpp.
|
inline |
Returns the layer associated with the model.
Definition at line 126 of file qgsfieldmodel.h.
|
override |
Definition at line 251 of file qgsfieldmodel.cpp.
void QgsFieldModel::removeExpression | ( | ) |
Removes any custom expression from the model.
Definition at line 234 of file qgsfieldmodel.cpp.
|
override |
Definition at line 257 of file qgsfieldmodel.cpp.
void QgsFieldModel::setAllowEmptyFieldName | ( | bool | allowEmpty | ) |
Sets whether an optional empty field ("not set") option is present in the model.
Definition at line 198 of file qgsfieldmodel.cpp.
void QgsFieldModel::setAllowExpression | ( | bool | allowExpression | ) |
Sets whether custom expressions are accepted and displayed in the model.
Definition at line 181 of file qgsfieldmodel.cpp.
void QgsFieldModel::setExpression | ( | const QString & | expression | ) |
Sets a single expression to be added after the fields at the end of the model.
Definition at line 218 of file qgsfieldmodel.cpp.
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().
Definition at line 521 of file qgsfieldmodel.cpp.
|
slot |
Set the layer from which fields are displayed.
Definition at line 83 of file qgsfieldmodel.cpp.
|
protectedvirtualslot |
Called when the model must be updated.
Definition at line 108 of file qgsfieldmodel.cpp.
|
protected |
Definition at line 195 of file qgsfieldmodel.h.
|
protected |
Definition at line 194 of file qgsfieldmodel.h.
|
protected |
Definition at line 191 of file qgsfieldmodel.h.
|
protected |
Definition at line 190 of file qgsfieldmodel.h.
|
protected |
Definition at line 193 of file qgsfieldmodel.h.
|
readwrite |
Definition at line 38 of file qgsfieldmodel.h.
|
readwrite |
Definition at line 38 of file qgsfieldmodel.h.
|
readwrite |
Definition at line 38 of file qgsfieldmodel.h.