Class: QgsLayoutItemAttributeTable¶
- class qgis.core.QgsLayoutItemAttributeTable¶
Bases:
QgsLayoutTable
A layout table subclass that displays attributes from a vector layer.
New in version 3.0.
QgsLayoutItemAttributeTable(layout:
QgsLayout
) Constructor forQgsLayoutItemAttributeTable
, attached to the specifiedlayout
.Ownership is transferred to the layout.
Methods
Calculates the maximum width of text shown in columns.
Calculates the maximum height of text shown in rows.
- param row
Checks whether a table contents contains a given row
Returns a new
QgsLayoutItemAttributeTable
for the specified parentlayout
.- rtype
QgsExpressionContext
- rtype
str
Returns
True
if the table is set to show only features visible on a corresponding map item.Draws the horizontal grid lines for the table.
Returns the current expression used to filter features for the table.
Returns
True
if a feature filter is active on the attribute table.Returns
True
if the table is set to only show features which intersect the current atlas feature.Queries the attribute table's vector layer for attributes to show in the table.
Returns the horizontal alignment to use for the cell at the specified
row
andcolumn
.- rtype
QIcon
Returns the layout map whose extents are controlling the features shown in the table.
Returns the maximum number of features to be shown by the table.
Sets object properties from a DOM element
- param itemElem
Recalculates and updates the size of the table and all table frames.
- param property
Returns the relation id which the table displays child features from.
Resets the attribute table's columns to match the vector layer's fields.
Calculates a range of rows which should be visible in a given frame.
Calculates how many content rows would be visible within a frame of the specified height.
- param row
Sets the attribute table to only show features which are visible in a map item.
Sets the attributes to display in the table.
Sets the
expression
used for filtering features in the table.Sets whether the feature filter is active for the attribute table.
Sets attribute table to only show features which intersect the current atlas feature.
Sets a layout
map
to use to limit the extent of features shown in the attribute table.Sets the maximum number of
features
shown by the table.Sets the relation
id
from which to display child featuresSets the
source
for attributes to show in table body.Sets attribute table to only show unique rows.
Sets whether the attribute table will be rendered using the conditional styling properties of the linked vector layer.
Sets the vector
layer
from which to display feature attributes.Sets a string to wrap the contents of the table cells by.
Returns the source for attributes shown in the table body.
Returns the source layer for the table, considering the table source mode.
- param row
Returns the text format to use for the header cell at the specified
column
.- rtype
int
Returns
True
if the table is set to show only unique rows.Returns
True
if the attribute table will be rendered using the conditional styling properties of the linked vector layer.Returns the vector layer the attribute table is currently using.
Returns the vertical alignment to use for the cell at the specified
row
andcolumn
.Returns the string used to wrap the contents of the table cells by.
Stores object properties within an XML DOM element.
- param elem
Attributes
- AtlasFeature = 1¶
- class ContentSource¶
Bases:
int
- LayerAttributes = 0¶
- RelationChildren = 2¶
- calculateMaxColumnWidths(self) bool ¶
Calculates the maximum width of text shown in columns.
- calculateMaxRowHeights(self) bool ¶
Calculates the maximum height of text shown in rows.
- childEvent(self, QChildEvent)¶
- conditionalCellStyle(self, row: int, column: int) QgsConditionalStyle ¶
- Parameters
row (int) –
column (int) –
- Return type
- connectNotify(self, QMetaMethod)¶
- contentsContainsRow(self, contents: object, row: Iterable[Any]) bool ¶
Checks whether a table contents contains a given row
- Parameters
contents – table contents to check
row – row to check for
- Returns
True
if contents contains rows
- create(layout: QgsLayout) QgsLayoutItemAttributeTable ¶
Returns a new
QgsLayoutItemAttributeTable
for the specified parentlayout
.- Parameters
layout (QgsLayout) –
- Return type
- createExpressionContext(self) QgsExpressionContext ¶
- Return type
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- displayName(self) str ¶
- Return type
str
- displayOnlyVisibleFeatures(self) bool ¶
Returns
True
if the table is set to show only features visible on a corresponding map item.See also
See also
- Return type
bool
- drawHorizontalGridLines(self, context: QgsLayoutItemRenderContext, firstRow: int, lastRow: int, drawHeaderLines: bool)¶
Draws the horizontal grid lines for the table.
- Parameters
context – destination render context
firstRow – index corresponding to first row shown in frame
lastRow – index corresponding to last row shown in frame. If greater than the number of content rows in the table, then the default row height will be used for the remaining rows.
drawHeaderLines – set to
True
to include for the table header
See also
drawVerticalGridLines()
- featureFilter(self) str ¶
Returns the current expression used to filter features for the table. The filter is only active if
filterFeatures()
isTrue
.See also
See also
- Return type
str
- filterFeatures(self) bool ¶
Returns
True
if a feature filter is active on the attribute table.See also
See also
- Return type
bool
- filterToAtlasFeature(self) bool ¶
Returns
True
if the table is set to only show features which intersect the current atlas feature.See also
- Return type
bool
- finalizeRestoreFromXml(self)¶
- getTableContents(self, contents: object) bool ¶
Queries the attribute table’s vector layer for attributes to show in the table.
- Parameters
contents (object) – table content
- Return type
bool
- Returns
True
if attributes were successfully fetched
- horizontalAlignmentForCell(self, row: int, column: int) Qt.Alignment ¶
Returns the horizontal alignment to use for the cell at the specified
row
andcolumn
.See also
New in version 3.16.
- icon(self) QIcon ¶
- Return type
QIcon
- isSignalConnected(self, QMetaMethod) bool ¶
- map(self) QgsLayoutItemMap ¶
Returns the layout map whose extents are controlling the features shown in the table. The extents of the map are only used if
displayOnlyVisibleFeatures()
isTrue
.See also
See also
- Return type
- maximumNumberOfFeatures(self) int ¶
Returns the maximum number of features to be shown by the table.
See also
- Return type
int
- readObjectPropertiesFromElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool ¶
Sets object properties from a DOM element
- Parameters
parentElement – is the parent DOM element for the object
document – DOM document
context – read write context
- Returns
True
if read was successful
See also
- readPropertiesFromElement(self, itemElem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) bool ¶
- Parameters
itemElem (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool
- recalculateTableSize(self)¶
Recalculates and updates the size of the table and all table frames.
- receivers(self, PYQT_SIGNAL) int ¶
- refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)¶
- Parameters
property (QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties) –
- relationId(self) str ¶
Returns the relation id which the table displays child features from.
See also
See also
Note
Only used if table
source()
is set to RelationChildren.- Return type
str
- resetColumns(self)¶
Resets the attribute table’s columns to match the vector layer’s fields.
See also
- rowRange(self, context: QgsRenderContext, frameIndex: int) Tuple[int, int] ¶
Calculates a range of rows which should be visible in a given frame.
- Parameters
context – render context
frameIndex – index number for frame
- Returns
row range
- rowsVisible(self, context: QgsRenderContext, frameHeight: float, firstRow: int, includeHeader: bool, includeEmptyRows: bool) int ¶
Calculates how many content rows would be visible within a frame of the specified height.
- Parameters
context – render context
frameHeight – height of frame
firstRow – index of first row visible in frame (where 0 = first row in table)
includeHeader – set to
True
if frame would include a header rowincludeEmptyRows – set to
True
to also include rows which would be empty in the returned count. For instance, if the frame would include all table content rows and have space left for extra rows then setting this parameter toTrue
would also include a count of these extra blank rows.
- Returns
number of visible content rows (excluding header row)
rowsVisible(self, context:
QgsRenderContext
, frameIndex: int, firstRow: int, includeEmptyRows: bool) -> int Calculates how many content rows are visible within a given frame.- Parameters
context – render context
frameIndex – index number for frame
firstRow – index of first row visible in frame (where 0 = first row in table)
includeEmptyRows – set to
True
to also include rows which would be empty in the returned count. For instance, if the frame would include all table content rows and have space left for extra rows then setting this parameter toTrue
would also include a count of these extra blank rows.
- Returns
number of visible content rows (excludes header rows)
- scopeForCell(self, row: int, column: int) QgsExpressionContextScope ¶
- Parameters
row (int) –
column (int) –
- Return type
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setDisplayOnlyVisibleFeatures(self, visibleOnly: bool)¶
Sets the attribute table to only show features which are visible in a map item. Changing this setting forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.
See also
See also
- Parameters
visibleOnly (bool) –
- setDisplayedFields(self, fields: Iterable[str], refresh: bool = True)¶
Sets the attributes to display in the table.
- Parameters
fields (Iterable[str]) – list of fields names from the vector layer to show. Set to an empty list to show all feature attributes.
refresh (bool = True) – set to
True
to force the table to refetch features from its vector layer and immediately update the display of the table. This may result in the table changing size to accommodate the new displayed feature attributes.
- setFeatureFilter(self, expression: str)¶
Sets the
expression
used for filtering features in the table. The filter is only active iffilterFeatures()
is set toTrue
. Changing this setting forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.See also
See also
- Parameters
expression (str) –
- setFilterFeatures(self, filter: bool)¶
Sets whether the feature filter is active for the attribute table. Changing this setting forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.
See also
See also
- Parameters
filter (bool) –
- setFilterToAtlasFeature(self, filterToAtlas: bool)¶
Sets attribute table to only show features which intersect the current atlas feature.
See also
- Parameters
filterToAtlas (bool) –
- setMap(self, map: QgsLayoutItemMap)¶
Sets a layout
map
to use to limit the extent of features shown in the attribute table. This setting only has an effect if setDisplayOnlyVisibleFeatures is set toTrue
. Changing the map forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.See also
See also
- Parameters
map (QgsLayoutItemMap) –
- setMaximumNumberOfFeatures(self, features: int)¶
Sets the maximum number of
features
shown by the table. Changing this setting may result in the attribute table changing its size to accommodate the new number of rows, and requires the table to refetch features from its vector layer.See also
- Parameters
features (int) –
- setRelationId(self, id: str)¶
Sets the relation
id
from which to display child featuresSee also
See also
Note
Only used if table
source()
is set to RelationChildren.- Parameters
id (str) –
- setSource(self, source: QgsLayoutItemAttributeTable.ContentSource)¶
Sets the
source
for attributes to show in table body.See also
- Parameters
source (QgsLayoutItemAttributeTable.ContentSource) –
- setUniqueRowsOnly(self, uniqueOnly: bool)¶
Sets attribute table to only show unique rows.
Set
uniqueOnly
toTrue
to show only unique rows. Duplicate rows will be stripped from the table.See also
- Parameters
uniqueOnly (bool) –
- setUseConditionalStyling(self, enabled: bool)¶
Sets whether the attribute table will be rendered using the conditional styling properties of the linked vector layer.
See also
New in version 3.12.
- Parameters
enabled (bool) –
- setVectorLayer(self, layer: QgsVectorLayer)¶
Sets the vector
layer
from which to display feature attributes.This is only considered if the table
source()
is LayerAttributes.See also
- Parameters
layer (QgsVectorLayer) –
- setWrapString(self, wrapString: str)¶
Sets a string to wrap the contents of the table cells by. Occurrences of this string will be replaced by a line break.
- Parameters
wrapString (str) – string to replace with line break
See also
- source(self) QgsLayoutItemAttributeTable.ContentSource ¶
Returns the source for attributes shown in the table body.
See also
- Return type
- sourceLayer(self) QgsVectorLayer ¶
Returns the source layer for the table, considering the table source mode. For example, if the table is set to atlas feature mode, then the source layer will be the atlas coverage layer. If the table is set to layer attributes mode, then the source layer will be the user specified vector layer.
- Return type
- textFormatForCell(self, row: int, column: int) QgsTextFormat ¶
- Parameters
row (int) –
column (int) –
- Return type
- textFormatForHeader(self, column: int) QgsTextFormat ¶
Returns the text format to use for the header cell at the specified
column
.See also
New in version 3.16.
- timerEvent(self, QTimerEvent)¶
- totalHeight(self) float ¶
- totalWidth(self) float ¶
- type(self) int ¶
- Return type
int
- uniqueRowsOnly(self) bool ¶
Returns
True
if the table is set to show only unique rows.See also
- Return type
bool
- useConditionalStyling(self) bool ¶
Returns
True
if the attribute table will be rendered using the conditional styling properties of the linked vector layer.See also
New in version 3.12.
- Return type
bool
- vectorLayer(self) QgsVectorLayer ¶
Returns the vector layer the attribute table is currently using.
This is only considered if the table
source()
is LayerAttributes.See also
See also
- Return type
- verticalAlignmentForCell(self, row: int, column: int) Qt.Alignment ¶
Returns the vertical alignment to use for the cell at the specified
row
andcolumn
.See also
New in version 3.16.
- wrapString(self) str ¶
Returns the string used to wrap the contents of the table cells by. Occurrences of this string will be replaced by a line break.
See also
- Return type
str
- writeObjectPropertiesToElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool ¶
Stores object properties within an XML DOM element.
- Parameters
parentElement – is the parent DOM element to store the object’s properties in
document – DOM document
context – read write context
- Returns
True
if write was successful
See also
- writePropertiesToElement(self, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) bool ¶
- Parameters
elem (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool