QGIS API Documentation 3.43.0-Master (56aa1fd18d7)
Public Types | Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsAttributesFormModel Class Referenceabstract

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

#include <qgsattributesformmodel.h>

Inheritance diagram for QgsAttributesFormModel:
Inheritance graph
[legend]

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.
 

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
 
QModelIndex parent (const QModelIndex &index) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const 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

bool indexLessThan (const QModelIndex &a, const QModelIndex &b) const
 Auxiliary function to sort indexes, returning true if index a is less than index b.
 
QgsAttributesFormItemitemForIndex (const QModelIndex &index) const
 Returns the underlying item that corresponds to the given index.
 
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 531 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 542 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 351 of file qgsattributesformmodel.cpp.

◆ ~QgsAttributesFormModel()

QgsAttributesFormModel::~QgsAttributesFormModel ( )
overridedefault

Member Function Documentation

◆ columnCount()

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

Definition at line 381 of file qgsattributesformmodel.cpp.

◆ 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 446 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 440 of file qgsattributesformmodel.cpp.

◆ index()

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

Definition at line 412 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 386 of file qgsattributesformmodel.cpp.

◆ itemForIndex()

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

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 361 of file qgsattributesformmodel.cpp.

◆ parent()

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

Definition at line 427 of file qgsattributesformmodel.cpp.

◆ populate

virtual void QgsAttributesFormModel::populate ( )
pure virtualslot

Populates the model with initial data read from the layer.

◆ 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 402 of file qgsattributesformmodel.cpp.

◆ rowCount()

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

Definition at line 371 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 457 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 452 of file qgsattributesformmodel.cpp.

Member Data Documentation

◆ mLayer

QgsVectorLayer* QgsAttributesFormModel::mLayer
protected

Definition at line 630 of file qgsattributesformmodel.h.

◆ mProject

QgsProject* QgsAttributesFormModel::mProject
protected

Definition at line 631 of file qgsattributesformmodel.h.

◆ mRootItem

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

Definition at line 629 of file qgsattributesformmodel.h.

◆ mShowAliases

bool QgsAttributesFormModel::mShowAliases = false
protected

Definition at line 633 of file qgsattributesformmodel.h.


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