Class: QgsFeatureListModel

A proxy model for feature lists.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsFeatureListModel

Base classes

QSortFilterProxyModel

QAbstractProxyModel

QAbstractItemModel

QObject

QgsFeatureModel

Base class for feature models.

Methods

displayExpression

featureByIndex

fidToIdx

Returns the model index corresponding to a feature ID.

fidToIndexList

idxToFid

Returns the feature ID corresponding to an index from the model.

injectNull

Returns the current state of null value injection

layerCache

Returns the vector layer cache which is being used to populate the model.

masterModel

onBeginInsertRows

Does nothing except for calling beginInsertRows()

onBeginRemoveRows

Does nothing except for calling beginRemoveRows()

onEndInsertRows

Does nothing except for calling endInsertRows()

onEndRemoveRows

Does nothing except for calling endRemoveRows()

parserErrorString

Returns a detailed message about errors while parsing a QgsExpression.

setDisplayExpression

Sets the display expression.

setInjectNull

If True is specified, a NULL value will be injected

setSortByDisplayExpression

Sort this model by its display expression.

sortByDisplayExpression

Sort this model by its display expression.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsFeatureListModel. See the FAQ for more details.

mapFromMaster

mapSelectionFromMaster

mapSelectionToMaster

mapToMaster

Attributes

FeatureInfoRole

FeatureRole

FeatureWithGeometryRole

class qgis.gui.QgsFeatureListModel[source]

Bases: QSortFilterProxyModel, QgsFeatureModel

__init__(sourceModel: QgsAttributeTableFilterModel | None, parent: QObject | None = None)

Constructor for QgsFeatureListModel

Parameters:
class FeatureInfo
class FeatureInfo(a0: QgsFeatureListModel.FeatureInfo)

Bases: object

isEdited: bool

True if feature has been edited.

isNew: bool

True if feature is a newly added feature.

FeatureInfoRole = 4096
FeatureRole = 4097
FeatureWithGeometryRole = 4098
class Role

Bases: int

displayExpression(self) str[source]
Return type:

str

featureByIndex(self, index: QModelIndex, feat: QgsFeature) bool[source]
Parameters:
Return type:

bool

fidToIdx(self, fid: int) QModelIndex[source]

Returns the model index corresponding to a feature ID.

See also

idxToFid()

Parameters:

fid (int)

Return type:

QModelIndex

fidToIndexList(self, fid: int) List[QModelIndex][source]
Parameters:

fid (int)

Return type:

List[QModelIndex]

idxToFid(self, index: QModelIndex) int[source]

Returns the feature ID corresponding to an index from the model.

See also

fidToIdx()

Parameters:

index (QModelIndex)

Return type:

int

injectNull(self) bool[source]

Returns the current state of null value injection

Return type:

bool

Returns:

If a NULL value is added

layerCache(self) QgsVectorLayerCache | None[source]

Returns the vector layer cache which is being used to populate the model.

Return type:

Optional[QgsVectorLayerCache]

virtual mapFromMaster(self, sourceIndex: QModelIndex) QModelIndex[source]
Parameters:

sourceIndex (QModelIndex)

Return type:

QModelIndex

virtual mapSelectionFromMaster(self, selection: QItemSelection) QItemSelection[source]
Parameters:

selection (QItemSelection)

Return type:

QItemSelection

virtual mapSelectionToMaster(self, selection: QItemSelection) QItemSelection[source]
Parameters:

selection (QItemSelection)

Return type:

QItemSelection

virtual mapToMaster(self, proxyIndex: QModelIndex) QModelIndex[source]
Parameters:

proxyIndex (QModelIndex)

Return type:

QModelIndex

masterModel(self) QgsAttributeTableModel | None[source]
Return type:

Optional[QgsAttributeTableModel]

onBeginInsertRows(self, parent: QModelIndex, first: int, last: int)[source]

Does nothing except for calling beginInsertRows()

Deprecated since version 3.40: Use beginInsertRows() instead.

Parameters:
  • parent (QModelIndex)

  • first (int)

  • last (int)

onBeginRemoveRows(self, parent: QModelIndex, first: int, last: int)[source]

Does nothing except for calling beginRemoveRows()

Deprecated since version 3.40: Use beginRemoveRows() instead.

Parameters:
  • parent (QModelIndex)

  • first (int)

  • last (int)

onEndInsertRows(self, parent: QModelIndex, first: int, last: int)[source]

Does nothing except for calling endInsertRows()

Deprecated since version 3.40: Use endInsertRows() instead.

Parameters:
  • parent (QModelIndex)

  • first (int)

  • last (int)

onEndRemoveRows(self, parent: QModelIndex, first: int, last: int)[source]

Does nothing except for calling endRemoveRows()

Deprecated since version 3.40: Use endRemoveRows() instead.

Parameters:
  • parent (QModelIndex)

  • first (int)

  • last (int)

parserErrorString(self) str[source]

Returns a detailed message about errors while parsing a QgsExpression.

Return type:

str

Returns:

A message containing information about the parser error.

setDisplayExpression(self, expression: str | None) bool[source]

Sets the display expression.

Parameters:

expression (Optional[str]) – A QgsExpression compatible string.

Return type:

bool

Returns:

True if the expression could be set, False if there was a parse error. If it fails, the old expression will still be applied. Call parserErrorString() for a meaningful error message.

setInjectNull(self, injectNull: bool)[source]

If True is specified, a NULL value will be injected

Parameters:

injectNull (bool) – state of null value injection

Note

If set to True, the sort by display expression cannot be used

setSortByDisplayExpression(self, sortByDisplayExpression: bool, order: Qt.SortOrder = Qt.AscendingOrder)[source]

Sort this model by its display expression.

Note

Not compatible with injectNull, if sorting by display expression is enabled, injectNull will automatically turned off.

Added in version 3.2.

Parameters:
  • sortByDisplayExpression (bool)

  • order (Qt.SortOrder = Qt.AscendingOrder)

sortByDisplayExpression(self) bool[source]

Sort this model by its display expression.

Added in version 3.2.

Return type:

bool