QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
58 return tr(
"<Table frame>" );
70 for (
const QgsTableRow &row : std::as_const( mContents ) )
74 for (
int columnNumber = 0; columnNumber <
mColumns.count(); ++columnNumber )
76 if ( columnNumber < row.count() )
78 QVariant cellContent = row.at( columnNumber ).content();
84 cellContent = cellContent.value<
QgsProperty >().value( context );
87 if ( row.at( columnNumber ).numericFormat() )
88 currentRow << row.at( columnNumber ).numericFormat()->formatDouble( cellContent.toDouble(), numericContext );
90 currentRow << cellContent.toString();
94 currentRow << QString();
107 if ( row < 0 || row >= mContents.size() )
111 if ( column < 0 || column > rowContents.size() )
116 if (
c.foregroundColor().isValid() )
118 if (
c.backgroundColor().isValid() )
139 mRowHeights = heights;
146 mColumnWidths = widths;
154 return mIncludeHeader;
159 mIncludeHeader = included;
161 if ( !mIncludeHeader )
188 tableElem.setAttribute( QStringLiteral(
"includeHeader" ), mIncludeHeader ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
191 QDomElement headersElem = doc.createElement( QStringLiteral(
"headers" ) );
194 QDomElement headerElem = doc.createElement( QStringLiteral(
"header" ) );
195 header.writeXml( headerElem, doc );
196 headersElem.appendChild( headerElem );
198 tableElem.appendChild( headersElem );
200 QDomElement contentsElement = doc.createElement( QStringLiteral(
"contents" ) );
203 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
204 for (
int i = 0; i <
mColumns.count(); ++i )
206 if ( i < row.count() )
211 contentsElement.appendChild( rowElement );
213 tableElem.appendChild( contentsElement );
215 QDomElement rowHeightsElement = doc.createElement( QStringLiteral(
"rowHeights" ) );
216 for (
double height : mRowHeights )
218 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
219 rowElement.setAttribute( QStringLiteral(
"height" ), height );
220 rowHeightsElement.appendChild( rowElement );
222 tableElem.appendChild( rowHeightsElement );
224 QDomElement columnWidthsElement = doc.createElement( QStringLiteral(
"columnWidths" ) );
225 for (
double width : mColumnWidths )
227 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
228 columnElement.setAttribute( QStringLiteral(
"width" ), width );
229 columnWidthsElement.appendChild( columnElement );
231 tableElem.appendChild( columnWidthsElement );
241 mIncludeHeader = itemElem.attribute( QStringLiteral(
"includeHeader" ) ).toInt();
244 QDomNodeList headersList = itemElem.elementsByTagName( QStringLiteral(
"headers" ) );
245 if ( !headersList.isEmpty() )
247 QDomElement headersElem = headersList.at( 0 ).toElement();
248 QDomNodeList headerEntryList = headersElem.elementsByTagName( QStringLiteral(
"header" ) );
249 for (
int i = 0; i < headerEntryList.size(); ++i )
251 QDomElement headerElem = headerEntryList.at( i ).toElement();
254 mHeaders.append( header );
259 const QDomNodeList rowHeightNodeList = itemElem.firstChildElement( QStringLiteral(
"rowHeights" ) ).childNodes();
260 mRowHeights.reserve( rowHeightNodeList.size() );
261 for (
int r = 0; r < rowHeightNodeList.size(); ++r )
263 const QDomElement rowHeightElement = rowHeightNodeList.at( r ).toElement();
264 mRowHeights.append( rowHeightElement.attribute( QStringLiteral(
"height" ) ).toDouble() );
267 mColumnWidths.clear();
268 const QDomNodeList columnWidthNodeList = itemElem.firstChildElement( QStringLiteral(
"columnWidths" ) ).childNodes();
269 mColumnWidths.reserve( columnWidthNodeList.size() );
270 for (
int r = 0; r < columnWidthNodeList.size(); ++r )
272 const QDomElement columnWidthElement = columnWidthNodeList.at( r ).toElement();
273 mColumnWidths.append( columnWidthElement.attribute( QStringLiteral(
"width" ) ).toDouble() );
277 const QDomElement contentsElement = itemElem.firstChildElement( QStringLiteral(
"contents" ) );
278 const QDomNodeList rowNodeList = contentsElement.childNodes();
279 newContents.reserve( rowNodeList.size() );
280 for (
int r = 0; r < rowNodeList.size(); ++r )
283 const QDomElement rowElement = rowNodeList.at( r ).toElement();
284 const QDomNodeList cellNodeList = rowElement.childNodes();
285 row.reserve( cellNodeList.size() );
286 for (
int c = 0;
c < cellNodeList.size(); ++
c )
288 const QDomElement cellElement = cellNodeList.at(
c ).toElement();
306 QMap<int, double> newHeights;
310 const int row = it.key() - 1;
311 const double presetHeight = mRowHeights.value( row );
312 double thisRowHeight = it.value();
313 if ( presetHeight > 0 )
314 thisRowHeight = presetHeight;
315 newHeights.insert( row + 1, thisRowHeight );
329 if ( mContents.value( row ).value( column ).textFormat().isValid() )
330 return mContents.value( row ).value( column ).textFormat();
337 if ( row < mContents.size() && column < mContents.at( row ).size() )
338 return mContents.value( row ).value( column ).horizontalAlignment();
345 if ( row < mContents.size() && column < mContents.at( row ).size() )
346 return mContents.value( row ).value( column ).verticalAlignment();
351 void QgsLayoutItemManualTable::refreshColumns()
355 if ( !mContents.empty() )
359 columns.reserve( firstRow.size() );
364 newCol.setWidth( mColumnWidths.value( colIndex ) );
QgsLayoutTableColumns & headers()
Returns a reference to the list of headers shown in the table.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setHeaderMode(HeaderMode mode)
Sets the display mode for headers in the table.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
RAII class to pop scope from an expression context on destruction.
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
A store for object properties.
QgsTableContents tableContents() const
Returns the contents of the table.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
The class is used as a container of context for various read/write operations on other objects.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
void setTextColor(const QColor &value)
Set the text color for the style.
void setRowHeights(const QList< double > &heights)
Sets the list of row heights (in millimeters) to use when rendering the table.
QgsLayoutTableColumns & columns()
Returns a reference to the list of QgsLayoutTableColumns shown in the table.
QgsLayoutItemManualTable(QgsLayout *layout)
Constructor for QgsLayoutItemManualTable, attached to the specified layout.
QgsConditionalStyle conditionalCellStyle(int row, int column) const override
Returns the conditional style to use for the cell at row, column.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
void changed()
Emitted when the object's properties change.
void setTableContents(const QgsTableContents &contents)
Sets the contents of the table.
Conditional styling for a rule.
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
virtual QgsTextFormat textFormatForCell(int row, int column) const
Returns the text format to use for the cell at the specified row and column.
QVector< QgsTableRow > QgsTableContents
A set of table rows.
virtual Qt::Alignment verticalAlignmentForCell(int row, int column) const
Returns the vertical alignment to use for the cell at the specified row and column.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
Container for all settings relating to text rendering.
QgsTextFormat textFormatForHeader(int column) const override
Returns the text format to use for the header cell at the specified column.
Encapsulates the contents and formatting of a single table cell.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
Qt::Alignment horizontalAlignmentForCell(int row, int column) const override
Returns the horizontal alignment to use for the cell at the specified row and column.
virtual QgsExpressionContextScope * scopeForCell(int row, int column) const
Creates a new QgsExpressionContextScope for the cell at row, column.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
bool getTableContents(QgsLayoutTableContents &contents) override
Fetches the contents used for the cells in the table.
Qt::Alignment verticalAlignmentForCell(int row, int column) const override
Returns the vertical alignment to use for the cell at the specified row and column.
QString displayName() const override
Returns the multiframe display name.
@ NoHeaders
No headers shown for table.
bool includeTableHeader() const
Returns true if the table includes a header row.
void setHeaders(const QgsLayoutTableColumns &headers)
Replaces the headers in the table with a specified list of QgsLayoutTableColumns.
void setIncludeTableHeader(bool included)
Sets whether the table includes a header row.
virtual QgsTextFormat textFormatForHeader(int column) const
Returns the text format to use for the header cell at the specified column.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
QIcon icon() const override
Returns the item's icon.
A class to display a table in the print layout, and allow the table to span over multiple frames.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
virtual bool calculateMaxRowHeights()
Calculates the maximum height of text shown in rows.
void setProperties(const QVariantMap &properties, const QgsReadWriteContext &context)
Sets the properties for the cell.
int type() const override
Returns unique multiframe type id.
void setColumns(const QgsLayoutTableColumns &columns)
Replaces the columns in the table with a specified list of QgsLayoutTableColumns.
QVector< QgsTableCell > QgsTableRow
A row of table cells.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QVector< QVariant > QgsLayoutTableRow
List of QVariants, representing a the contents of a single row in a QgsLayoutTable.
~QgsLayoutItemManualTable() override
QgsLayoutTableColumns mColumns
Columns to show in table.
Stores properties of a column for a QgsLayoutTable.
virtual Qt::Alignment horizontalAlignmentForCell(int row, int column) const
Returns the horizontal alignment to use for the cell at the specified row and column.
QgsTextFormat textFormatForCell(int row, int column) const override
Returns the text format to use for the cell at the specified row and column.
void setColumnWidths(const QList< double > &widths)
Sets the list of column widths (in millimeters) to use when rendering the table.
static QgsLayoutItemManualTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemManualTable for the specified parent layout.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
@ LayoutManualTable
Manual (fixed) table.
@ AllFrames
Headers shown on all frames.
A layout table subclass that displays manually entered (and formatted) content.
bool calculateMaxRowHeights() override
Calculates the maximum height of text shown in rows.
A context for numeric formats.