QGIS API Documentation  2.99.0-Master (8ec3eaf)
Public Types | Public Slots | Public Member Functions | Protected Slots | Protected Attributes | Properties | List of all members
QgsFieldModel Class Reference

The QgsFieldModel class is a model to display the list of fields of a layer in widgets. More...

#include <qgsfieldmodel.h>

Inheritance diagram for QgsFieldModel:
Inheritance graph
[legend]

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
}
 Roles utilised 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
 
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...
 
QgsVectorLayerlayer ()
 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...
 

Protected Slots

virtual void updateModel ()
 Called when the model must be updated. More...
 

Protected Attributes

bool mAllowEmpty
 
bool mAllowExpression
 
QList< QString > mExpression
 
QgsFields mFields
 
QgsVectorLayermLayer
 

Properties

bool allowEmptyFieldName
 
bool allowExpression
 
QgsVectorLayer layer
 

Detailed Description

The QgsFieldModel class is a model to display the list of fields of a layer in widgets.

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.

Note
added in 2.3

Definition at line 33 of file qgsfieldmodel.h.

Member Enumeration Documentation

§ FieldRoles

Roles utilised by the model.

Enumerator
FieldNameRole 

Return field name if index corresponds to a field.

FieldIndexRole 

Return field index if index corresponds to a field.

ExpressionRole 

Return field name or expression.

IsExpressionRole 

Return if index corresponds to an expression.

ExpressionValidityRole 

Return if expression is valid or not.

FieldTypeRole 

Return the field type (if a field, return QVariant if expression)

FieldOriginRole 

Return the field origin (if a field, returns QVariant if expression)

IsEmptyRole 

Return if the index corresponds to the empty value.

Definition at line 44 of file qgsfieldmodel.h.

Constructor & Destructor Documentation

§ QgsFieldModel()

QgsFieldModel::QgsFieldModel ( QObject *  parent = nullptr)
explicit

Constructor for QgsFieldModel - creates a model to display the fields of a given layer.

Definition at line 26 of file qgsfieldmodel.cpp.

Member Function Documentation

§ allowEmptyFieldName()

bool QgsFieldModel::allowEmptyFieldName ( ) const
inline

Returns true if the model allows the empty field ("not set") choice.

See also
setAllowEmptyFieldName()
Note
added in QGIS 3.0

Definition at line 91 of file qgsfieldmodel.h.

§ allowExpression()

bool QgsFieldModel::allowExpression ( )
inline

Returns true if the model allows custom expressions to be created and displayed.

See also
setAllowExpression()

Definition at line 77 of file qgsfieldmodel.h.

§ columnCount()

int QgsFieldModel::columnCount ( const QModelIndex &  parent) const
override

Definition at line 266 of file qgsfieldmodel.cpp.

§ data()

QVariant QgsFieldModel::data ( const QModelIndex &  index,
int  role 
) const
override

Definition at line 272 of file qgsfieldmodel.cpp.

§ index()

QModelIndex QgsFieldModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

Definition at line 240 of file qgsfieldmodel.cpp.

§ indexFromName()

QModelIndex QgsFieldModel::indexFromName ( const QString &  fieldName)

Returns the index corresponding to a given fieldName.

Definition at line 34 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 76 of file qgsfieldmodel.cpp.

§ layer()

QgsVectorLayer* QgsFieldModel::layer ( )
inline

Returns the layer associated with the model.

See also
setLayer()

Definition at line 118 of file qgsfieldmodel.h.

§ parent()

QModelIndex QgsFieldModel::parent ( const QModelIndex &  child) const
override

Definition at line 250 of file qgsfieldmodel.cpp.

§ removeExpression()

void QgsFieldModel::removeExpression ( )

Removes any custom expression from the model.

See also
setExpression()
allowExpression()

Definition at line 233 of file qgsfieldmodel.cpp.

§ rowCount()

int QgsFieldModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 256 of file qgsfieldmodel.cpp.

§ setAllowEmptyFieldName()

void QgsFieldModel::setAllowEmptyFieldName ( bool  allowEmpty)

Sets whether an optional empty field ("not set") option is present in the model.

See also
allowEmptyFieldName()
Note
added in QGIS 3.0

Definition at line 197 of file qgsfieldmodel.cpp.

§ setAllowExpression()

void QgsFieldModel::setAllowExpression ( bool  allowExpression)

Sets whether custom expressions are accepted and displayed in the model.

See also
allowExpression()
setExpression()

Definition at line 180 of file qgsfieldmodel.cpp.

§ setExpression()

void QgsFieldModel::setExpression ( const QString &  expression)

Sets a single expression to be added after the fields at the end of the model.

See also
setAllowExpression()
allowExpression()
removeExpression()

Definition at line 217 of file qgsfieldmodel.cpp.

§ setLayer

void QgsFieldModel::setLayer ( QgsVectorLayer layer)
slot

Set the layer from which fields are displayed.

See also
layer()

Definition at line 82 of file qgsfieldmodel.cpp.

§ updateModel

void QgsFieldModel::updateModel ( )
protectedvirtualslot

Called when the model must be updated.

Definition at line 107 of file qgsfieldmodel.cpp.

Member Data Documentation

§ mAllowEmpty

bool QgsFieldModel::mAllowEmpty
protected

Definition at line 151 of file qgsfieldmodel.h.

§ mAllowExpression

bool QgsFieldModel::mAllowExpression
protected

Definition at line 150 of file qgsfieldmodel.h.

§ mExpression

QList<QString> QgsFieldModel::mExpression
protected

Definition at line 147 of file qgsfieldmodel.h.

§ mFields

QgsFields QgsFieldModel::mFields
protected

Definition at line 146 of file qgsfieldmodel.h.

§ mLayer

QgsVectorLayer* QgsFieldModel::mLayer
protected

Definition at line 149 of file qgsfieldmodel.h.

Property Documentation

§ allowEmptyFieldName

bool QgsFieldModel::allowEmptyFieldName
readwrite

Definition at line 38 of file qgsfieldmodel.h.

§ allowExpression

bool QgsFieldModel::allowExpression
readwrite

Definition at line 37 of file qgsfieldmodel.h.

§ layer

QgsVectorLayer QgsFieldModel::layer
readwrite

Definition at line 39 of file qgsfieldmodel.h.


The documentation for this class was generated from the following files: