QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsLayoutItemAttributeTable Class Reference

A layout table subclass that displays attributes from a vector layer. More...

#include <qgslayoutitemattributetable.h>

Inheritance diagram for QgsLayoutItemAttributeTable:
Inheritance graph
[legend]

Public Types

enum  ContentSource { LayerAttributes = 0 , AtlasFeature , RelationChildren }
 Specifies the content source for the attribute table. More...
 
- Public Types inherited from QgsLayoutTable
enum  CellStyleGroup {
  OddColumns , EvenColumns , OddRows , EvenRows ,
  FirstColumn , LastColumn , HeaderRow , FirstRow ,
  LastRow
}
 Row or column groups for cell styling. More...
 
enum  EmptyTableMode { HeadersOnly = 0 , HideTable , ShowMessage }
 Controls how empty tables are displayed. More...
 
enum  HeaderHAlignment { FollowColumn , HeaderLeft , HeaderCenter , HeaderRight }
 Controls how headers are horizontally aligned in a table. More...
 
enum  HeaderMode { FirstFrame = 0 , AllFrames , NoHeaders }
 Controls where headers are shown in the table. More...
 
enum  WrapBehavior { TruncateText = 0 , WrapText }
 Controls how long strings in the table are handled. More...
 
- Public Types inherited from QgsLayoutMultiFrame
enum  ResizeMode { UseExistingFrames = 0 , ExtendToNextPage , RepeatOnEveryPage , RepeatUntilFinished }
 Specifies the behavior for creating new frames to fit the multiframe's content. More...
 
enum  UndoCommand {
  UndoHtmlBreakDistance , UndoHtmlSource , UndoHtmlStylesheet , UndoTableCellStyle ,
  UndoTableMaximumFeatures , UndoTableMargin , UndoTableHeaderFontColor , UndoTableContentFontColor ,
  UndoTableGridStrokeWidth , UndoTableGridColor , UndoTableBackgroundColor , UndoNone = -1
}
 Multiframe item undo commands, used for collapsing undo commands. More...
 
- Public Types inherited from QgsLayoutObject
enum  DataDefinedProperty {
  NoProperty = 0 , AllProperties , TestProperty , PresetPaperSize ,
  PaperWidth , PaperHeight , NumPages , PaperOrientation ,
  PageNumber , PositionX , PositionY , ItemWidth ,
  ItemHeight , ItemRotation , Transparency , Opacity ,
  BlendMode , ExcludeFromExports , FrameColor , BackgroundColor ,
  MapRotation , MapScale , MapXMin , MapYMin ,
  MapXMax , MapYMax , MapAtlasMargin , MapLayers ,
  MapStylePreset , MapLabelMargin , MapGridEnabled , MapGridIntervalX ,
  MapGridIntervalY , MapGridOffsetX , MapGridOffsetY , MapGridFrameSize ,
  MapGridFrameMargin , MapGridLabelDistance , MapGridCrossSize , MapGridFrameLineThickness ,
  MapGridAnnotationDisplayLeft , MapGridAnnotationDisplayRight , MapGridAnnotationDisplayTop , MapGridAnnotationDisplayBottom ,
  MapGridFrameDivisionsLeft , MapGridFrameDivisionsRight , MapGridFrameDivisionsTop , MapGridFrameDivisionsBottom ,
  PictureSource , PictureSvgBackgroundColor , PictureSvgStrokeColor , PictureSvgStrokeWidth ,
  SourceUrl , LegendTitle , LegendColumnCount , ScalebarLeftSegments ,
  ScalebarRightSegments , ScalebarSegmentWidth , ScalebarMinimumWidth , ScalebarMaximumWidth ,
  ScalebarHeight , ScalebarRightSegmentSubdivisions , ScalebarSubdivisionHeight , ScalebarFillColor ,
  ScalebarFillColor2 , ScalebarLineColor , ScalebarLineWidth , AttributeTableSourceLayer ,
  MapCrs , StartDateTime , EndDateTime
}
 Data defined properties for different item types. More...
 
enum  PropertyValueType { EvaluatedValue = 0 , OriginalValue }
 Specifies whether the value returned by a function should be the original, user set value, or the current evaluated value for the property. More...
 

Public Member Functions

 QgsLayoutItemAttributeTable (QgsLayout *layout)
 Constructor for QgsLayoutItemAttributeTable, attached to the specified layout. More...
 
QgsConditionalStyle conditionalCellStyle (int row, int column) const override
 Returns the conditional style to use for the cell at row, column. More...
 
QgsExpressionContext createExpressionContext () const override
 This method needs to be reimplemented in all classes which implement this interface and return an expression context. More...
 
QString displayName () const override
 Returns the multiframe display name. More...
 
bool displayOnlyVisibleFeatures () const
 Returns true if the table is set to show only features visible on a corresponding map item. More...
 
QString featureFilter () const
 Returns the current expression used to filter features for the table. More...
 
bool filterFeatures () const
 Returns true if a feature filter is active on the attribute table. More...
 
bool filterToAtlasFeature () const
 Returns true if the table is set to only show features which intersect the current atlas feature. More...
 
void finalizeRestoreFromXml () override
 Called after all pending items have been restored from XML. More...
 
bool getTableContents (QgsLayoutTableContents &contents) override
 Queries the attribute table's vector layer for attributes to show in the table. More...
 
QIcon icon () const override
 Returns the item's icon. More...
 
QgsLayoutItemMapmap () const
 Returns the layout map whose extents are controlling the features shown in the table. More...
 
int maximumNumberOfFeatures () const
 Returns the maximum number of features to be shown by the table. More...
 
void refreshDataDefinedProperty (QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties) override
 Refreshes a data defined property for the multi frame by reevaluating the property's value and redrawing the item with this new value. More...
 
QString relationId () const
 Returns the relation id which the table displays child features from. More...
 
void resetColumns ()
 Resets the attribute table's columns to match the vector layer's fields. More...
 
QgsExpressionContextScopescopeForCell (int row, int column) const override
 Creates a new QgsExpressionContextScope for the cell at row, column. More...
 
void setDisplayedFields (const QStringList &fields, bool refresh=true)
 Sets the attributes to display in the table. More...
 
void setDisplayOnlyVisibleFeatures (bool visibleOnly)
 Sets the attribute table to only show features which are visible in a map item. More...
 
void setFeatureFilter (const QString &expression)
 Sets the expression used for filtering features in the table. More...
 
void setFilterFeatures (bool filter)
 Sets whether the feature filter is active for the attribute table. More...
 
void setFilterToAtlasFeature (bool filterToAtlas)
 Sets attribute table to only show features which intersect the current atlas feature. More...
 
void setMap (QgsLayoutItemMap *map)
 Sets a layout map to use to limit the extent of features shown in the attribute table. More...
 
void setMaximumNumberOfFeatures (int features)
 Sets the maximum number of features shown by the table. More...
 
void setRelationId (const QString &id)
 Sets the relation id from which to display child features. More...
 
void setSource (ContentSource source)
 Sets the source for attributes to show in table body. More...
 
void setUniqueRowsOnly (bool uniqueOnly)
 Sets attribute table to only show unique rows. More...
 
void setUseConditionalStyling (bool enabled)
 Sets whether the attribute table will be rendered using the conditional styling properties of the linked vector layer. More...
 
void setVectorLayer (QgsVectorLayer *layer)
 Sets the vector layer from which to display feature attributes. More...
 
void setWrapString (const QString &wrapString)
 Sets a string to wrap the contents of the table cells by. More...
 
ContentSource source () const
 Returns the source for attributes shown in the table body. More...
 
QgsVectorLayersourceLayer () const
 Returns the source layer for the table, considering the table source mode. More...
 
QgsTextFormat textFormatForCell (int row, int column) const override
 Returns the text format to use for the cell at the specified row and column. More...
 
int type () const override
 Returns unique multiframe type id. More...
 
bool uniqueRowsOnly () const
 Returns true if the table is set to show only unique rows. More...
 
bool useConditionalStyling () const
 Returns true if the attribute table will be rendered using the conditional styling properties of the linked vector layer. More...
 
QgsVectorLayervectorLayer () const
 Returns the vector layer the attribute table is currently using. More...
 
QString wrapString () const
 Returns the string used to wrap the contents of the table cells by. More...
 
- Public Member Functions inherited from QgsLayoutTable
 QgsLayoutTable (QgsLayout *layout)
 Constructor for QgsLayoutTable, belonging to the specified layout. More...
 
 ~QgsLayoutTable () override
 
QColor backgroundColor () const
 Returns the color used for the background of the table. More...
 
double cellMargin () const
 Returns the margin distance between cell borders and their contents in mm. More...
 
const QgsLayoutTableStylecellStyle (CellStyleGroup group) const
 Returns the cell style for a cell group. More...
 
QgsLayoutTableColumnscolumns ()
 Returns a reference to the list of QgsLayoutTableColumns shown in the table. More...
 
virtual QgsConditionalStyle conditionalCellStyle (int row, int column) const
 Returns the conditional style to use for the cell at row, column. More...
 
Q_DECL_DEPRECATED QFont contentFont () const
 Returns the font used to draw text in table body cells. More...
 
Q_DECL_DEPRECATED QColor contentFontColor () const
 Returns the color used to draw text in table body cells. More...
 
QgsLayoutTableContentscontents ()
 Returns the current contents of the table. More...
 
QgsTextFormat contentTextFormat () const
 Returns the format used to draw content text in the table. More...
 
EmptyTableMode emptyTableBehavior () const
 Returns the behavior mode for empty tables. More...
 
QString emptyTableMessage () const
 Returns the message for empty tables with no content rows. More...
 
QSizeF fixedFrameSize (int frameIndex=-1) const override
 Returns the fixed size for a frame, if desired. More...
 
virtual bool getTableContents (QgsLayoutTableContents &contents)=0
 Fetches the contents used for the cells in the table. More...
 
QColor gridColor () const
 Returns the color used for grid lines in the table. More...
 
double gridStrokeWidth () const
 Returns the width of grid lines in the table in mm. More...
 
Q_DECL_DEPRECATED QFont headerFont () const
 Returns the font used to draw header text in the table. More...
 
Q_DECL_DEPRECATED QColor headerFontColor () const
 Returns the color used to draw header text in the table. More...
 
HeaderHAlignment headerHAlignment () const
 Returns the horizontal alignment for table headers. More...
 
virtual QMap< int, QString > headerLabels () const
 Returns the text used in the column headers for the table. More...
 
HeaderMode headerMode () const
 Returns the display mode for headers in the table. More...
 
QgsTextFormat headerTextFormat () const
 Returns the format used to draw header text in the table. More...
 
bool horizontalGrid () const
 Returns whether the grid's horizontal lines are drawn in the table. More...
 
QSizeF minFrameSize (int frameIndex=-1) const override
 Returns the minimum size for a frames, if desired. More...
 
bool readPropertiesFromElement (const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
 Sets multiframe state from a DOM element. More...
 
void render (QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex) override
 Renders a portion of the multiframe's content into a render context. More...
 
virtual QgsExpressionContextScopescopeForCell (int row, int column) const
 Creates a new QgsExpressionContextScope for the cell at row, column. More...
 
void setBackgroundColor (const QColor &color)
 Sets the color used for background of table. More...
 
void setCellMargin (double margin)
 Sets the margin distance in mm between cell borders and their contents. More...
 
void setCellStyle (CellStyleGroup group, const QgsLayoutTableStyle &style)
 Sets the cell style for a cell group. More...
 
void setColumns (const QgsLayoutTableColumns &columns)
 Replaces the columns in the table with a specified list of QgsLayoutTableColumns. More...
 
Q_DECL_DEPRECATED void setContentFont (const QFont &font)
 Sets the font used to draw text in table body cells. More...
 
Q_DECL_DEPRECATED void setContentFontColor (const QColor &color)
 Sets the color used to draw text in table body cells. More...
 
void setContentTextFormat (const QgsTextFormat &format)
 Sets the format used to draw content text in the table. More...
 
void setEmptyTableBehavior (EmptyTableMode mode)
 Sets the behavior mode for empty tables with no content rows. More...
 
void setEmptyTableMessage (const QString &message)
 Sets the message for empty tables with no content rows. More...
 
void setGridColor (const QColor &color)
 Sets the color used for grid lines in the table. More...
 
void setGridStrokeWidth (double width)
 Sets the width in mm for grid lines in the table. More...
 
Q_DECL_DEPRECATED void setHeaderFont (const QFont &font)
 Sets the font used to draw header text in the table. More...
 
Q_DECL_DEPRECATED void setHeaderFontColor (const QColor &color)
 Sets the color used to draw header text in the table. More...
 
void setHeaderHAlignment (HeaderHAlignment alignment)
 Sets the horizontal alignment for table headers. More...
 
void setHeaderMode (HeaderMode mode)
 Sets the display mode for headers in the table. More...
 
void setHeaderTextFormat (const QgsTextFormat &format)
 Sets the format used to draw header text in the table. More...
 
void setHorizontalGrid (bool horizontalGrid)
 Sets whether the grid's horizontal lines should be drawn in the table. More...
 
void setShowEmptyRows (bool showEmpty)
 Sets whether empty rows should be drawn. More...
 
void setShowGrid (bool showGrid)
 Sets whether grid lines should be drawn in the table. More...
 
void setSortColumns (const QgsLayoutTableSortColumns &sortColumns)
 Replaces the sorting columns in the table with a specified list of QgsLayoutTableSortColumns. More...
 
void setVerticalGrid (bool verticalGrid)
 Sets whether the grid's vertical lines should be drawn in the table. More...
 
void setWrapBehavior (WrapBehavior behavior)
 Sets the wrap behavior for the table, which controls how text within cells is automatically wrapped. More...
 
bool showEmptyRows () const
 Returns whether empty rows are drawn in the table. More...
 
bool showGrid () const
 Returns whether grid lines are drawn in the table. More...
 
QgsLayoutTableSortColumnssortColumns ()
 Returns a reference to the list of QgsLayoutTableSortColumns shown in the table. More...
 
QSizeF totalSize () const override
 Returns the total size of the multiframe's content, in layout units. More...
 
bool verticalGrid () const
 Returns whether the grid's vertical lines are drawn in the table. More...
 
WrapBehavior wrapBehavior () const
 Returns the wrap behavior for the table, which controls how text within cells is automatically wrapped. More...
 
bool writePropertiesToElement (QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
 Stores multiframe state within an XML DOM element. More...
 
- Public Member Functions inherited from QgsLayoutMultiFrame
 QgsLayoutMultiFrame (QgsLayout *layout)
 Construct a new multiframe item, attached to the specified layout. More...
 
 ~QgsLayoutMultiFrame () override
 
virtual void addFrame (QgsLayoutFrame *frame, bool recalcFrameSizes=true)
 Adds a frame to the multiframe. More...
 
void beginCommand (const QString &commandText, UndoCommand command=UndoNone)
 Starts new undo command for this item. More...
 
void cancelCommand ()
 Cancels the current item command and discards it. More...
 
QgsAbstractLayoutUndoCommandcreateCommand (const QString &text, int id, QUndoCommand *parent=nullptr) override
 Creates a new layout undo command with the specified text and parent. More...
 
QgsExpressionContext createExpressionContext () const override
 This method needs to be reimplemented in all classes which implement this interface and return an expression context. More...
 
QgsLayoutFramecreateNewFrame (QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size)
 Creates a new frame and adds it to the multi frame and layout. More...
 
void deleteFrames ()
 Removes and deletes all child frames. More...
 
virtual QString displayName () const
 Returns the multiframe display name. More...
 
void endCommand ()
 Completes the current item command and push it onto the layout's undo stack. More...
 
virtual void finalizeRestoreFromXml ()
 Called after all pending items have been restored from XML. More...
 
virtual double findNearbyPageBreak (double yPos)
 Finds the optimal position to break a frame at. More...
 
virtual QSizeF fixedFrameSize (int frameIndex=-1) const
 Returns the fixed size for a frame, if desired. More...
 
QgsLayoutFrameframe (int index) const
 Returns the child frame at a specified index from the multiframe. More...
 
int frameCount () const
 Returns the number of frames associated with this multiframe. More...
 
int frameIndex (QgsLayoutFrame *frame) const
 Returns the index of a frame within the multiframe. More...
 
QList< QgsLayoutFrame * > frames () const
 Returns a list of all child frames for this multiframe. More...
 
virtual QIcon icon () const
 Returns the item's icon. More...
 
virtual QSizeF minFrameSize (int frameIndex=-1) const
 Returns the minimum size for a frames, if desired. More...
 
bool readXml (const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames=false)
 Sets the item state from a DOM element. More...
 
void removeFrame (int index, bool removeEmptyPages=false)
 Removes a frame by index from the multiframe. More...
 
virtual void render (QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex)=0
 Renders a portion of the multiframe's content into a render context. More...
 
ResizeMode resizeMode () const
 Returns the resize mode for the multiframe. More...
 
void setResizeMode (ResizeMode mode)
 Sets the resize mode for the multiframe, and recalculates frame sizes to match. More...
 
virtual QSizeF totalSize () const =0
 Returns the total size of the multiframe's content, in layout units. More...
 
virtual int type () const =0
 Returns unique multiframe type id. More...
 
QString uuid () const
 Returns the multiframe identification string. More...
 
bool writeXml (QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context, bool includeFrames=false) const
 Stores the multiframe state in a DOM element. More...
 
- Public Member Functions inherited from QgsLayoutObject
 QgsLayoutObject (QgsLayout *layout)
 Constructor for QgsLayoutObject, with the specified parent layout. More...
 
QgsExpressionContext createExpressionContext () const override
 Creates an expression context relating to the objects' current state. More...
 
QStringList customProperties () const
 Returns list of keys stored in custom properties for the object. More...
 
QVariant customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const
 Read a custom property from the object. More...
 
QgsPropertyCollectiondataDefinedProperties ()
 Returns a reference to the object's property collection, used for data defined overrides. More...
 
const QgsPropertyCollectiondataDefinedProperties () const
 Returns a reference to the object's property collection, used for data defined overrides. More...
 
QgsLayoutlayout ()
 Returns the layout the object is attached to. More...
 
const QgsLayoutlayout () const
 Returns the layout the object is attached to. More...
 
void removeCustomProperty (const QString &key)
 Remove a custom property from the object. More...
 
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for the object. More...
 
void setDataDefinedProperties (const QgsPropertyCollection &collection)
 Sets the objects's property collection, used for data defined overrides. More...
 
- Public Member Functions inherited from QgsExpressionContextGenerator
virtual ~QgsExpressionContextGenerator ()=default
 
virtual QgsExpressionContext createExpressionContext () const =0
 This method needs to be reimplemented in all classes which implement this interface and return an expression context. More...
 
- Public Member Functions inherited from QgsLayoutUndoObjectInterface
virtual ~QgsLayoutUndoObjectInterface ()=default
 Destructor for QgsLayoutUndoObjectInterface. More...
 
virtual QgsAbstractLayoutUndoCommandcreateCommand (const QString &text, int id=0, QUndoCommand *parent=nullptr)=0
 Creates a new layout undo command with the specified text and parent. More...
 

Static Public Member Functions

static QgsLayoutItemAttributeTablecreate (QgsLayout *layout)
 Returns a new QgsLayoutItemAttributeTable for the specified parent layout. More...
 
- Static Public Member Functions inherited from QgsLayoutObject
static bool propertyAssociatesWithParentMultiframe (DataDefinedProperty property)
 Returns true if the specified property key is normally associated with the parent QgsLayoutMultiFrame object instead of a child QgsLayoutFrame object. More...
 
static const QgsPropertiesDefinitionpropertyDefinitions ()
 Returns the layout object property definitions. More...
 

Protected Member Functions

bool readPropertiesFromElement (const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
 Sets multiframe state from a DOM element. More...
 
bool writePropertiesToElement (QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
 Stores multiframe state within an XML DOM element. More...
 
- Protected Member Functions inherited from QgsLayoutTable
virtual bool calculateMaxColumnWidths ()
 Calculates the maximum width of text shown in columns. More...
 
virtual bool calculateMaxRowHeights ()
 Calculates the maximum height of text shown in rows. More...
 
bool contentsContainsRow (const QgsLayoutTableContents &contents, const QgsLayoutTableRow &row) const
 Checks whether a table contents contains a given row. More...
 
void drawHorizontalGridLines (QgsLayoutItemRenderContext &context, int firstRow, int lastRow, bool drawHeaderLines) const
 Draws the horizontal grid lines for the table. More...
 
void drawVerticalGridLines (QgsLayoutItemRenderContext &context, const QMap< int, double > &maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells=false) const
 Draws the vertical grid lines for the table. More...
 
virtual Qt::Alignment horizontalAlignmentForCell (int row, int column) const
 Returns the horizontal alignment to use for the cell at the specified row and column. More...
 
void recalculateTableSize ()
 Recalculates and updates the size of the table and all table frames. More...
 
QPair< int, int > rowRange (QgsRenderContext &context, int frameIndex) const
 Calculates a range of rows which should be visible in a given frame. More...
 
int rowsVisible (QgsRenderContext &context, double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows) const
 Calculates how many content rows would be visible within a frame of the specified height. More...
 
int rowsVisible (QgsRenderContext &context, int frameIndex, int firstRow, bool includeEmptyRows) const
 Calculates how many content rows are visible within a given frame. More...
 
virtual QgsTextFormat textFormatForCell (int row, int column) const
 Returns the text format to use for the cell at the specified row and column. More...
 
virtual QgsTextFormat textFormatForHeader (int column) const
 Returns the text format to use for the header cell at the specified column. More...
 
double totalHeight ()
 Returns total height of table contents. More...
 
double totalWidth ()
 Returns total width of table contents. More...
 
virtual Qt::Alignment verticalAlignmentForCell (int row, int column) const
 Returns the vertical alignment to use for the cell at the specified row and column. More...
 
virtual bool readPropertiesFromElement (const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
 Sets multiframe state from a DOM element. More...
 
virtual bool writePropertiesToElement (QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
 Stores multiframe state within an XML DOM element. More...
 
- Protected Member Functions inherited from QgsLayoutObject
bool readObjectPropertiesFromElement (const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
 Sets object properties from a DOM element. More...
 
bool writeObjectPropertiesToElement (QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
 Stores object properties within an XML DOM element. More...
 

Additional Inherited Members

- Public Slots inherited from QgsLayoutTable
void recalculateFrameSizes () override
 
void refresh () override
 
virtual void refreshAttributes ()
 Refreshes the contents shown in the table by querying for new data. More...
 
- Public Slots inherited from QgsLayoutMultiFrame
void recalculateFrameRects ()
 Forces a recalculation of all the associated frame's scene rectangles. More...
 
virtual void recalculateFrameSizes ()
 Recalculates the portion of the multiframe item which is shown in each of its component frames. More...
 
void refresh () override
 Refreshes the multiframe, causing a recalculation of any property overrides. More...
 
virtual void refreshDataDefinedProperty (QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
 Refreshes a data defined property for the multi frame by reevaluating the property's value and redrawing the item with this new value. More...
 
void update ()
 Forces a redraw of all child frames. More...
 
- Public Slots inherited from QgsLayoutObject
virtual void refresh ()
 Refreshes the object, causing a recalculation of any property overrides. More...
 
- Signals inherited from QgsLayoutMultiFrame
void contentsChanged ()
 Emitted when the contents of the multi frame have changed and the frames must be redrawn. More...
 
- Signals inherited from QgsLayoutObject
void changed ()
 Emitted when the object's properties change. More...
 
- Protected Attributes inherited from QgsLayoutTable
QColor mBackgroundColor = Qt::white
 Color for table background. More...
 
double mCellMargin = 1.0
 Margin between cell borders and cell text. More...
 
QMap< CellStyleGroup, QgsLayoutTableStyle * > mCellStyles
 
QgsLayoutTableColumns mColumns
 Columns to show in table. More...
 
QgsTextFormat mContentTextFormat
 
QString mEmptyTableMessage
 String to show in empty tables. More...
 
EmptyTableMode mEmptyTableMode = HeadersOnly
 Behavior for empty tables. More...
 
QColor mGridColor = Qt::black
 Color for grid lines. More...
 
double mGridStrokeWidth = 0.5
 Width of grid lines. More...
 
HeaderHAlignment mHeaderHAlignment = FollowColumn
 Alignment for table headers. More...
 
HeaderMode mHeaderMode = FirstFrame
 Header display mode. More...
 
QgsTextFormat mHeaderTextFormat
 
bool mHorizontalGrid = true
 True if grid should be shown. More...
 
QMap< int, double > mMaxColumnWidthMap
 Map of maximum width for each column. More...
 
QMap< int, double > mMaxRowHeightMap
 Map of maximum height for each row. More...
 
bool mShowEmptyRows = false
 True if empty rows should be shown in the table. More...
 
bool mShowGrid = true
 True if grid should be shown. More...
 
QgsLayoutTableSortColumns mSortColumns
 Columns to sort the table. More...
 
QgsLayoutTableContents mTableContents
 Contents to show in table. More...
 
QSizeF mTableSize
 
bool mVerticalGrid = true
 True if grid should be shown. More...
 
WrapBehavior mWrapBehavior = TruncateText
 
- Protected Attributes inherited from QgsLayoutMultiFrame
QList< QgsLayoutFrame * > mFrameItems
 
ResizeMode mResizeMode = UseExistingFrames
 
- Protected Attributes inherited from QgsLayoutObject
QgsObjectCustomProperties mCustomProperties
 Custom properties for object. More...
 
QgsPropertyCollection mDataDefinedProperties
 
QPointer< QgsLayoutmLayout
 

Detailed Description

A layout table subclass that displays attributes from a vector layer.

Since
QGIS 3.0

Definition at line 34 of file qgslayoutitemattributetable.h.

Member Enumeration Documentation

◆ ContentSource

Specifies the content source for the attribute table.

Enumerator
LayerAttributes 

Table shows attributes from features in a vector layer.

AtlasFeature 

Table shows attributes from the current atlas feature.

RelationChildren 

Table shows attributes from related child features.

Definition at line 43 of file qgslayoutitemattributetable.h.

Constructor & Destructor Documentation

◆ QgsLayoutItemAttributeTable()

QgsLayoutItemAttributeTable::QgsLayoutItemAttributeTable ( QgsLayout layout)

Constructor for QgsLayoutItemAttributeTable, attached to the specified layout.

Ownership is transferred to the layout.

Definition at line 44 of file qgslayoutitemattributetable.cpp.

Member Function Documentation

◆ conditionalCellStyle()

QgsConditionalStyle QgsLayoutItemAttributeTable::conditionalCellStyle ( int  row,
int  column 
) const
overridevirtual

Returns the conditional style to use for the cell at row, column.

Since
QGIS 3.12

Reimplemented from QgsLayoutTable.

Definition at line 659 of file qgslayoutitemattributetable.cpp.

◆ create()

QgsLayoutItemAttributeTable * QgsLayoutItemAttributeTable::create ( QgsLayout layout)
static

Returns a new QgsLayoutItemAttributeTable for the specified parent layout.

Definition at line 67 of file qgslayoutitemattributetable.cpp.

◆ createExpressionContext()

QgsExpressionContext QgsLayoutItemAttributeTable::createExpressionContext ( ) const
overridevirtual

This method needs to be reimplemented in all classes which implement this interface and return an expression context.

Since
QGIS 3.0

Implements QgsExpressionContextGenerator.

Definition at line 716 of file qgslayoutitemattributetable.cpp.

◆ displayName()

QString QgsLayoutItemAttributeTable::displayName ( ) const
overridevirtual

Returns the multiframe display name.

Reimplemented from QgsLayoutMultiFrame.

Definition at line 72 of file qgslayoutitemattributetable.cpp.

◆ displayOnlyVisibleFeatures()

bool QgsLayoutItemAttributeTable::displayOnlyVisibleFeatures ( ) const
inline

Returns true if the table is set to show only features visible on a corresponding map item.

See also
map()
setDisplayOnlyVisibleFeatures()

Definition at line 194 of file qgslayoutitemattributetable.h.

◆ featureFilter()

QString QgsLayoutItemAttributeTable::featureFilter ( ) const
inline

Returns the current expression used to filter features for the table.

The filter is only active if filterFeatures() is true.

See also
setFeatureFilter()
filterFeatures()

Definition at line 236 of file qgslayoutitemattributetable.h.

◆ filterFeatures()

bool QgsLayoutItemAttributeTable::filterFeatures ( ) const
inline

Returns true if a feature filter is active on the attribute table.

See also
setFilterFeatures()
featureFilter()

Definition at line 218 of file qgslayoutitemattributetable.h.

◆ filterToAtlasFeature()

bool QgsLayoutItemAttributeTable::filterToAtlasFeature ( ) const
inline

Returns true if the table is set to only show features which intersect the current atlas feature.

See also
setFilterToAtlasFeature()

Definition at line 210 of file qgslayoutitemattributetable.h.

◆ finalizeRestoreFromXml()

void QgsLayoutItemAttributeTable::finalizeRestoreFromXml ( )
overridevirtual

Called after all pending items have been restored from XML.

Multiframes can use this method to run steps which must take place after all items have been restored to the layout, such as connecting to signals emitted by other items, which may not have existed in the layout at the time readXml() was called. E.g. a scalebar can use this to connect to its linked map item after restoration from XML.

See also
readXml()

Reimplemented from QgsLayoutMultiFrame.

Definition at line 728 of file qgslayoutitemattributetable.cpp.

◆ getTableContents()

bool QgsLayoutItemAttributeTable::getTableContents ( QgsLayoutTableContents contents)
overridevirtual

Queries the attribute table's vector layer for attributes to show in the table.

Parameters
contentstable content
Returns
true if attributes were successfully fetched

Implements QgsLayoutTable.

Definition at line 391 of file qgslayoutitemattributetable.cpp.

◆ icon()

QIcon QgsLayoutItemAttributeTable::icon ( ) const
overridevirtual

Returns the item's icon.

Reimplemented from QgsLayoutMultiFrame.

Definition at line 62 of file qgslayoutitemattributetable.cpp.

◆ map()

QgsLayoutItemMap * QgsLayoutItemAttributeTable::map ( ) const
inline

Returns the layout map whose extents are controlling the features shown in the table.

The extents of the map are only used if displayOnlyVisibleFeatures() is true.

See also
setMap()
displayOnlyVisibleFeatures()

Definition at line 144 of file qgslayoutitemattributetable.h.

◆ maximumNumberOfFeatures()

int QgsLayoutItemAttributeTable::maximumNumberOfFeatures ( ) const
inline

Returns the maximum number of features to be shown by the table.

See also
setMaximumNumberOfFeatures()

Definition at line 158 of file qgslayoutitemattributetable.h.

◆ readPropertiesFromElement()

bool QgsLayoutItemAttributeTable::readPropertiesFromElement ( const QDomElement &  element,
const QDomDocument &  document,
const QgsReadWriteContext context 
)
overrideprotectedvirtual

Sets multiframe state from a DOM element.

Parameters
elementis the DOM element for the multiframe
documentDOM document
contextread write context
See also
writePropertiesToElement()

Note that item subclasses should not rely on all other items being present in the layout at the time this method is called. Instead, any connections and links to other items must be made in the finalizeRestoreFromXml() method. E.g. when restoring a scalebar, the connection to the linked map's signals should be implemented in finalizeRestoreFromXml(), not readPropertiesFromElement().

See also
readXml()

Reimplemented from QgsLayoutMultiFrame.

Definition at line 913 of file qgslayoutitemattributetable.cpp.

◆ refreshDataDefinedProperty()

void QgsLayoutItemAttributeTable::refreshDataDefinedProperty ( QgsLayoutObject::DataDefinedProperty  property = QgsLayoutObject::AllProperties)
overridevirtual

Refreshes a data defined property for the multi frame by reevaluating the property's value and redrawing the item with this new value.

If property is set to QgsLayoutObject::AllProperties then all data defined properties for the item will be refreshed.

Reimplemented from QgsLayoutMultiFrame.

Definition at line 743 of file qgslayoutitemattributetable.cpp.

◆ relationId()

QString QgsLayoutItemAttributeTable::relationId ( ) const
inline

Returns the relation id which the table displays child features from.

See also
setRelationId()
source()
Note
Only used if table source() is set to RelationChildren.

Definition at line 119 of file qgslayoutitemattributetable.h.

◆ resetColumns()

void QgsLayoutItemAttributeTable::resetColumns ( )

Resets the attribute table's columns to match the vector layer's fields.

See also
setVectorLayer()

Definition at line 169 of file qgslayoutitemattributetable.cpp.

◆ scopeForCell()

QgsExpressionContextScope * QgsLayoutItemAttributeTable::scopeForCell ( int  row,
int  column 
) const
overridevirtual

Creates a new QgsExpressionContextScope for the cell at row, column.

Since
QGIS 3.16

Reimplemented from QgsLayoutTable.

Definition at line 708 of file qgslayoutitemattributetable.cpp.

◆ setDisplayedFields()

void QgsLayoutItemAttributeTable::setDisplayedFields ( const QStringList &  fields,
bool  refresh = true 
)

Sets the attributes to display in the table.

Parameters
fieldslist of fields names from the vector layer to show. Set to an empty list to show all feature attributes.
refreshset 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.

Definition at line 319 of file qgslayoutitemattributetable.cpp.

◆ setDisplayOnlyVisibleFeatures()

void QgsLayoutItemAttributeTable::setDisplayOnlyVisibleFeatures ( bool  visibleOnly)

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
displayOnlyVisibleFeatures()
setMap()

Definition at line 271 of file qgslayoutitemattributetable.cpp.

◆ setFeatureFilter()

void QgsLayoutItemAttributeTable::setFeatureFilter ( const QString &  expression)

Sets the expression used for filtering features in the table.

The filter is only active if filterFeatures() is set to true. 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
featureFilter()
setFilterFeatures()

Definition at line 307 of file qgslayoutitemattributetable.cpp.

◆ setFilterFeatures()

void QgsLayoutItemAttributeTable::setFilterFeatures ( bool  filter)

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
filterFeatures()
setFeatureFilter()

Definition at line 295 of file qgslayoutitemattributetable.cpp.

◆ setFilterToAtlasFeature()

void QgsLayoutItemAttributeTable::setFilterToAtlasFeature ( bool  filterToAtlas)

Sets attribute table to only show features which intersect the current atlas feature.

See also
filterToAtlasFeature()

Definition at line 283 of file qgslayoutitemattributetable.cpp.

◆ setMap()

void QgsLayoutItemAttributeTable::setMap ( QgsLayoutItemMap map)

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 to true. 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
map()
setDisplayOnlyVisibleFeatures

Definition at line 226 of file qgslayoutitemattributetable.cpp.

◆ setMaximumNumberOfFeatures()

void QgsLayoutItemAttributeTable::setMaximumNumberOfFeatures ( int  features)

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
maximumNumberOfFeatures()

Definition at line 247 of file qgslayoutitemattributetable.cpp.

◆ setRelationId()

void QgsLayoutItemAttributeTable::setRelationId ( const QString &  id)

Sets the relation id from which to display child features.

See also
relationId()
setSource()
Note
Only used if table source() is set to RelationChildren.

Definition at line 107 of file qgslayoutitemattributetable.cpp.

◆ setSource()

void QgsLayoutItemAttributeTable::setSource ( const QgsLayoutItemAttributeTable::ContentSource  source)

Sets the source for attributes to show in table body.

See also
source()

Definition at line 969 of file qgslayoutitemattributetable.cpp.

◆ setUniqueRowsOnly()

void QgsLayoutItemAttributeTable::setUniqueRowsOnly ( bool  uniqueOnly)

Sets attribute table to only show unique rows.

Set uniqueOnly to true to show only unique rows. Duplicate rows will be stripped from the table.

See also
uniqueRowsOnly()

Definition at line 259 of file qgslayoutitemattributetable.cpp.

◆ setUseConditionalStyling()

void QgsLayoutItemAttributeTable::setUseConditionalStyling ( bool  enabled)

Sets whether the attribute table will be rendered using the conditional styling properties of the linked vector layer.

See also
useConditionalStyling()
Since
QGIS 3.12

Definition at line 214 of file qgslayoutitemattributetable.cpp.

◆ setVectorLayer()

void QgsLayoutItemAttributeTable::setVectorLayer ( QgsVectorLayer layer)

Sets the vector layer from which to display feature attributes.

This is only considered if the table source() is LayerAttributes.

See also
vectorLayer()

Definition at line 77 of file qgslayoutitemattributetable.cpp.

◆ setWrapString()

void QgsLayoutItemAttributeTable::setWrapString ( const QString &  wrapString)

Sets a string to wrap the contents of the table cells by.

Occurrences of this string will be replaced by a line break.

Parameters
wrapStringstring to replace with line break
See also
wrapString()

Definition at line 870 of file qgslayoutitemattributetable.cpp.

◆ source()

ContentSource QgsLayoutItemAttributeTable::source ( ) const
inline

Returns the source for attributes shown in the table body.

See also
setSource()

Definition at line 76 of file qgslayoutitemattributetable.h.

◆ sourceLayer()

QgsVectorLayer * QgsLayoutItemAttributeTable::sourceLayer ( ) const

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.

Definition at line 835 of file qgslayoutitemattributetable.cpp.

◆ textFormatForCell()

QgsTextFormat QgsLayoutItemAttributeTable::textFormatForCell ( int  row,
int  column 
) const
overridevirtual

Returns the text format to use for the cell at the specified row and column.

See also
textFormatForHeader()
Since
QGIS 3.16

Reimplemented from QgsLayoutTable.

Definition at line 667 of file qgslayoutitemattributetable.cpp.

◆ type()

int QgsLayoutItemAttributeTable::type ( ) const
overridevirtual

Returns unique multiframe type id.

Implements QgsLayoutMultiFrame.

Definition at line 57 of file qgslayoutitemattributetable.cpp.

◆ uniqueRowsOnly()

bool QgsLayoutItemAttributeTable::uniqueRowsOnly ( ) const
inline

Returns true if the table is set to show only unique rows.

See also
setUniqueRowsOnly()

Definition at line 175 of file qgslayoutitemattributetable.h.

◆ useConditionalStyling()

bool QgsLayoutItemAttributeTable::useConditionalStyling ( ) const

Returns true if the attribute table will be rendered using the conditional styling properties of the linked vector layer.

See also
setUseConditionalStyling()
Since
QGIS 3.12

Definition at line 209 of file qgslayoutitemattributetable.cpp.

◆ vectorLayer()

QgsVectorLayer * QgsLayoutItemAttributeTable::vectorLayer ( ) const
inline

Returns the vector layer the attribute table is currently using.

This is only considered if the table source() is LayerAttributes.

See also
setVectorLayer()
sourceLayer()

Definition at line 103 of file qgslayoutitemattributetable.h.

◆ wrapString()

QString QgsLayoutItemAttributeTable::wrapString ( ) const
inline

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
setWrapString()

Definition at line 272 of file qgslayoutitemattributetable.h.

◆ writePropertiesToElement()

bool QgsLayoutItemAttributeTable::writePropertiesToElement ( QDomElement &  element,
QDomDocument &  document,
const QgsReadWriteContext context 
) const
overrideprotectedvirtual

Stores multiframe state within an XML DOM element.

Parameters
elementis the DOM element to store the multiframe's properties in
documentDOM document
contextread write context
See also
writeXml()
readPropertiesFromElement()

Reimplemented from QgsLayoutMultiFrame.

Definition at line 882 of file qgslayoutitemattributetable.cpp.


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