Class: QgsRasterAttributeTableModel

A model which represents a QgsRasterAttributeTable.

Added in version 3.30.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsRasterAttributeTableModel

Base classes

QAbstractTableModel

QAbstractItemModel

QObject

class qgis.gui.QgsRasterAttributeTableModel[source]

Bases: QAbstractTableModel

__init__(rat: QgsRasterAttributeTable | None, parent: QObject | None = None)

Creates a new QgsRasterAttributeTableModel from raster attribute table rat and optional parent.

Parameters:
editable(self) bool[source]

Returns true if the Raster Attribute Table is editable.

Return type:

bool

hasColor(self) bool[source]

Returns True if the Raster Attribute Table has color information.

Return type:

bool

hasRamp(self) bool[source]

Returns True if the Raster Attribute Table has ramp information.

Return type:

bool

headerNames(self) List[str][source]

Returns all the header names, including the “virtual” color header if the Raster Attribute Table has color or ramp.

Return type:

List[str]

headerTooltip(self, section: int) str[source]

Returns the tooltip for the given section.

Parameters:

section (int)

Return type:

str

insertColor(self, position: int)[source]

Create RGBA fields and inserts them at position, optionally reporting any error in errorMessage, returns True on success.

Parameters:

position (int) -> (bool)

insertField(self, position: int, name: str | None, usage: Qgis.RasterAttributeTableFieldUsage, type: QMetaType.Type)[source]

Inserts a field at the given position.

Parameters:
  • name (Optional[str]) – field name

  • usage (Qgis.RasterAttributeTableFieldUsage) – field usage

  • type (QMetaType.Type) -> (bool) – field type

  • position (int) – insertion point (before)

Returns:

  • true on success

  • errorMessage: error message

insertField(self, position: int, name: Optional[str], usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) -> (bool, Optional[str]) Inserts a field at the given position.

Parameters:
  • name – field name

  • usage – field usage

  • type – field type

  • position – insertion point (before)

Returns:

  • true on success

  • errorMessage: error message

Deprecated since version 3.38: Use the method with a QMetaType.Type argument instead.

insertRamp(self, position: int)[source]

Create RGBA minimum and maximum fields and inserts them at position, optionally reporting any error in errorMessage, returns True on success.

Parameters:

position (int) -> (bool)

insertRow(self, position: int, rowData: Iterable[Any])[source]

Inserts a new row before position, optionally reporting any error in errorMessage, returns True on success.

Parameters:
  • position (int)

  • rowData (Iterable[Any]) -> (bool)

isDirty(self) bool[source]

Returns True if the Raster Attribute Table was modified since it was last saved or read.

Return type:

bool

isValid(self)[source]

Checks if the Raster Attribute Table is valid, optionally returns validation errors in errorMessage.

removeColorOrRamp(self)[source]

Removes all color or ramp information, optionally reporting any error in errorMessage, returns True on success.

removeField(self, position: int)[source]

Remove the field at given position, optionally reporting any error in errorMessage, returns True on success.

Parameters:

position (int) -> (bool)

removeRow(self, position: int)[source]

Removes the row at position, optionally reporting any error in errorMessage, returns True on success.

Parameters:

position (int) -> (bool)

setEditable(self, editable: bool)[source]

Sets the Raster Attribute Table editable state to editable.

Parameters:

editable (bool)