QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
QgsAttributesFormModel Class Referenceabstract

Abstract class for tree models allowing for configuration of attributes forms. More...

#include <qgsattributesformmodel.h>

Inheritance diagram for QgsAttributesFormModel:

Public Types

enum  ItemRoles {
  ItemDataRole = Qt::UserRole , ItemFieldConfigRole , ItemNameRole , ItemIdRole ,
  ItemTypeRole , ItemDisplayRole
}
 Custom model roles. More...

Public Slots

virtual void populate ()=0
 Populates the model with initial data read from the layer.

Signals

void fieldConfigDataChanged (QgsAttributesFormItem *item)
 Notifies other objects that the field config data has changed in the item.

Public Member Functions

 QgsAttributesFormModel (QgsVectorLayer *layer, QgsProject *project, QObject *parent=nullptr)
 Constructor for QgsAttributesFormModel, with the given parent.
 ~QgsAttributesFormModel () override
int columnCount (const QModelIndex &parent=QModelIndex()) const override
QModelIndex firstRecursiveMatchingModelIndex (const QgsAttributesFormData::AttributesFormItemType &itemType, const QString &itemId) const
 Returns the first model index that matches the given itemType and itemId, recursively.
QModelIndex firstTopMatchingModelIndex (const QgsAttributesFormData::AttributesFormItemType &itemType, const QString &itemId) const
 Returns the first top-level model index that matches the given itemType and itemId.
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsAttributesFormItemitemForIndex (const QModelIndex &index) const
 Returns the underlying item that corresponds to the given index.
QModelIndex parent (const QModelIndex &index) const override
QgsAttributesFormItemrootItem () const
 Returns the root item in this model.
int rowCount (const QModelIndex &parent=QModelIndex()) const override
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
void setShowAliases (bool show)
 Sets whether field aliases should be preferred over field names as item text.
bool showAliases () const
 Returns whether field aliases are preferred over field names as item text.

Protected Member Functions

void emitDataChangedRecursively (const QModelIndex &parent=QModelIndex(), const QVector< int > &roles=QVector< int >())
 Emits dataChanged signal for all parent items in a model.
bool indexLessThan (const QModelIndex &a, const QModelIndex &b) const
 Auxiliary function to sort indexes, returning true if index a is less than index b.
QVector< int > rootToLeafPath (QgsAttributesFormItem *item) const
 Returns a QVector of iterative positions from root item to the given item.

Protected Attributes

QgsVectorLayermLayer
QgsProjectmProject
std::unique_ptr< QgsAttributesFormItemmRootItem
bool mShowAliases = false

Detailed Description

Abstract class for tree models allowing for configuration of attributes forms.

Warning
Not part of stable API and may change in future QGIS releases.
Since
QGIS 3.44

Definition at line 550 of file qgsattributesformmodel.h.

Member Enumeration Documentation

◆ ItemRoles

Custom model roles.

Note
Prior to QGIS 3.44 this was available as QgsAttributesFormProperties::FieldPropertiesRoles
Since
QGIS 3.44
Enumerator
ItemDataRole 

Prior to QGIS 3.44, this was available as DnDTreeRole.

ItemFieldConfigRole 

Prior to QGIS 3.44, this was available as FieldConfigRole.

ItemNameRole 

Prior to QGIS 3.44, this was available as FieldNameRole.

ItemIdRole 

Items may have ids to ease comparison. Used by Relations, fields, actions and containers.

ItemTypeRole 

Type of the item.

ItemDisplayRole 

Display text for the item.

Definition at line 561 of file qgsattributesformmodel.h.

Constructor & Destructor Documentation

◆ QgsAttributesFormModel()

QgsAttributesFormModel::QgsAttributesFormModel ( QgsVectorLayer * layer,
QgsProject * project,
QObject * parent = nullptr )
explicit

Constructor for QgsAttributesFormModel, with the given parent.

The given layer and project are data sources to populate the model.

Definition at line 370 of file qgsattributesformmodel.cpp.

◆ ~QgsAttributesFormModel()

QgsAttributesFormModel::~QgsAttributesFormModel ( )
overridedefault

Member Function Documentation

◆ columnCount()

int QgsAttributesFormModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 406 of file qgsattributesformmodel.cpp.

◆ emitDataChangedRecursively()

void QgsAttributesFormModel::emitDataChangedRecursively ( const QModelIndex & parent = QModelIndex(),
const QVector< int > & roles = QVector<int>() )
protected

Emits dataChanged signal for all parent items in a model.

In practice, this lets views know that the whole model has changed.

Parameters
parentModel index representing the parent item.
rolesList of roles that have changed in the model.

Definition at line 510 of file qgsattributesformmodel.cpp.

◆ fieldConfigDataChanged

void QgsAttributesFormModel::fieldConfigDataChanged ( QgsAttributesFormItem * item)
signal

Notifies other objects that the field config data has changed in the item.

Since
QGIS 4.0

◆ firstRecursiveMatchingModelIndex()

QModelIndex QgsAttributesFormModel::firstRecursiveMatchingModelIndex ( const QgsAttributesFormData::AttributesFormItemType & itemType,
const QString & itemId ) const

Returns the first model index that matches the given itemType and itemId, recursively.

If there is no matching model index in the whole hierarchy an invalid index is returned.

Definition at line 471 of file qgsattributesformmodel.cpp.

◆ firstTopMatchingModelIndex()

QModelIndex QgsAttributesFormModel::firstTopMatchingModelIndex ( const QgsAttributesFormData::AttributesFormItemType & itemType,
const QString & itemId ) const

Returns the first top-level model index that matches the given itemType and itemId.

If there is no matching top-level model index an invalid index is returned.

Definition at line 465 of file qgsattributesformmodel.cpp.

◆ index()

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

Definition at line 437 of file qgsattributesformmodel.cpp.

◆ indexLessThan()

bool QgsAttributesFormModel::indexLessThan ( const QModelIndex & a,
const QModelIndex & b ) const
protected

Auxiliary function to sort indexes, returning true if index a is less than index b.

Regardless of items depth, an index nearer to the root (imagine all items in a top-down flat list) should be returned first when sorting.

For instance, index 0-19-2 (where 0 is the grandparent position and 19 the parent position) will be less than index 1-0.

See also
rootToLeafPath()

Definition at line 411 of file qgsattributesformmodel.cpp.

◆ itemForIndex()

QgsAttributesFormItem * QgsAttributesFormModel::itemForIndex ( const QModelIndex & index) const

Returns the underlying item that corresponds to the given index.

If the given index is not valid the root item is returned.

Definition at line 380 of file qgsattributesformmodel.cpp.

◆ parent()

QModelIndex QgsAttributesFormModel::parent ( const QModelIndex & index) const
override

Definition at line 452 of file qgsattributesformmodel.cpp.

◆ populate

virtual void QgsAttributesFormModel::populate ( )
pure virtualslot

Populates the model with initial data read from the layer.

◆ rootItem()

QgsAttributesFormItem * QgsAttributesFormModel::rootItem ( ) const

Returns the root item in this model.

Since
QGIS 4.0

Definition at line 390 of file qgsattributesformmodel.cpp.

◆ rootToLeafPath()

QVector< int > QgsAttributesFormModel::rootToLeafPath ( QgsAttributesFormItem * item) const
protected

Returns a QVector of iterative positions from root item to the given item.

See also
indexLessThan()

Definition at line 427 of file qgsattributesformmodel.cpp.

◆ rowCount()

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

Definition at line 396 of file qgsattributesformmodel.cpp.

◆ setData()

bool QgsAttributesFormModel::setData ( const QModelIndex & index,
const QVariant & value,
int role = Qt::EditRole )
override

Definition at line 477 of file qgsattributesformmodel.cpp.

◆ setShowAliases()

void QgsAttributesFormModel::setShowAliases ( bool show)

Sets whether field aliases should be preferred over field names as item text.

See also
showAliases()

Definition at line 503 of file qgsattributesformmodel.cpp.

◆ showAliases()

bool QgsAttributesFormModel::showAliases ( ) const

Returns whether field aliases are preferred over field names as item text.

See also
setShowAliases()

Definition at line 498 of file qgsattributesformmodel.cpp.

Member Data Documentation

◆ mLayer

QgsVectorLayer* QgsAttributesFormModel::mLayer
protected

Definition at line 679 of file qgsattributesformmodel.h.

◆ mProject

QgsProject* QgsAttributesFormModel::mProject
protected

Definition at line 680 of file qgsattributesformmodel.h.

◆ mRootItem

std::unique_ptr< QgsAttributesFormItem > QgsAttributesFormModel::mRootItem
protected

Definition at line 678 of file qgsattributesformmodel.h.

◆ mShowAliases

bool QgsAttributesFormModel::mShowAliases = false
protected

Definition at line 682 of file qgsattributesformmodel.h.


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