38 qDeleteAll( mHeaders );
58 return tr(
"<Table frame>" );
67 for (
const QgsTableRow &row : qgis::as_const( mContents ) )
71 for (
int i = 0; i <
mColumns.count(); ++i )
73 if ( i < row.count() )
75 if ( row.at( i ).numericFormat() )
76 currentRow << row.at( i ).numericFormat()->formatDouble( row.at( i ).content().toDouble(), numericContext );
78 currentRow << row.at( i ).content().toString();
82 currentRow << QString();
85 contents << currentRow;
94 if ( row < 0 || row >= mContents.size() )
98 if ( column < 0 || column > rowContents.size() )
126 mRowHeights = heights;
133 mColumnWidths = widths;
141 return mIncludeHeader;
146 mIncludeHeader = included;
148 if ( !mIncludeHeader )
163 qDeleteAll( mHeaders );
166 mHeaders.append( headers );
176 tableElem.setAttribute( QStringLiteral(
"includeHeader" ), mIncludeHeader ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
179 QDomElement headersElem = doc.createElement( QStringLiteral(
"headers" ) );
182 QDomElement headerElem = doc.createElement( QStringLiteral(
"header" ) );
183 header->writeXml( headerElem, doc );
184 headersElem.appendChild( headerElem );
186 tableElem.appendChild( headersElem );
188 QDomElement contentsElement = doc.createElement( QStringLiteral(
"contents" ) );
191 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
192 for (
int i = 0; i <
mColumns.count(); ++i )
194 if ( i < row.count() )
199 contentsElement.appendChild( rowElement );
201 tableElem.appendChild( contentsElement );
203 QDomElement rowHeightsElement = doc.createElement( QStringLiteral(
"rowHeights" ) );
204 for (
double height : mRowHeights )
206 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
207 rowElement.setAttribute( QStringLiteral(
"height" ), height );
208 rowHeightsElement.appendChild( rowElement );
210 tableElem.appendChild( rowHeightsElement );
212 QDomElement columnWidthsElement = doc.createElement( QStringLiteral(
"columnWidths" ) );
213 for (
double width : mColumnWidths )
215 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
216 columnElement.setAttribute( QStringLiteral(
"width" ), width );
217 columnWidthsElement.appendChild( columnElement );
219 tableElem.appendChild( columnWidthsElement );
229 mIncludeHeader = itemElem.attribute( QStringLiteral(
"includeHeader" ) ).toInt();
231 qDeleteAll( mHeaders );
233 QDomNodeList headersList = itemElem.elementsByTagName( QStringLiteral(
"headers" ) );
234 if ( !headersList.isEmpty() )
236 QDomElement headersElem = headersList.at( 0 ).toElement();
237 QDomNodeList headerEntryList = headersElem.elementsByTagName( QStringLiteral(
"header" ) );
238 for (
int i = 0; i < headerEntryList.size(); ++i )
240 QDomElement headerElem = headerEntryList.at( i ).toElement();
243 mHeaders.append( header );
248 const QDomNodeList rowHeightNodeList = itemElem.firstChildElement( QStringLiteral(
"rowHeights" ) ).childNodes();
249 mRowHeights.reserve( rowHeightNodeList.size() );
250 for (
int r = 0; r < rowHeightNodeList.size(); ++r )
252 const QDomElement rowHeightElement = rowHeightNodeList.at( r ).toElement();
253 mRowHeights.append( rowHeightElement.attribute( QStringLiteral(
"height" ) ).toDouble() );
256 mColumnWidths.clear();
257 const QDomNodeList columnWidthNodeList = itemElem.firstChildElement( QStringLiteral(
"columnWidths" ) ).childNodes();
258 mColumnWidths.reserve( columnWidthNodeList.size() );
259 for (
int r = 0; r < columnWidthNodeList.size(); ++r )
261 const QDomElement columnWidthElement = columnWidthNodeList.at( r ).toElement();
262 mColumnWidths.append( columnWidthElement.attribute( QStringLiteral(
"width" ) ).toDouble() );
266 const QDomElement contentsElement = itemElem.firstChildElement( QStringLiteral(
"contents" ) );
267 const QDomNodeList rowNodeList = contentsElement.childNodes();
268 newContents.reserve( rowNodeList.size() );
269 for (
int r = 0; r < rowNodeList.size(); ++r )
272 const QDomElement rowElement = rowNodeList.at( r ).toElement();
273 const QDomNodeList cellNodeList = rowElement.childNodes();
274 row.reserve( cellNodeList.size() );
275 for (
int c = 0;
c < cellNodeList.size(); ++
c )
277 const QDomElement cellElement = cellNodeList.at(
c ).toElement();
295 QMap<int, double> newHeights;
299 const int row = it.key() - 1;
300 const double presetHeight = mRowHeights.value( row );
301 double thisRowHeight = it.value();
302 if ( presetHeight > 0 )
303 thisRowHeight = presetHeight;
304 newHeights.insert( row + 1, thisRowHeight );
310 void QgsLayoutItemManualTable::refreshColumns()
314 if ( !mContents.empty() )
318 columns.reserve( firstRow.size() );
322 std::unique_ptr< QgsLayoutTableColumn > newCol = qgis::make_unique< QgsLayoutTableColumn >( mHeaders.value( colIndex ) ? mHeaders.value( colIndex )->heading() : QString() );
323 newCol->setWidth( mColumnWidths.value( colIndex ) );
324 columns << newCol.release();
QgsLayoutItemManualTable(QgsLayout *layout)
Constructor for QgsLayoutItemManualTable, attached to the specified layout.
The class is used as a container of context for various read/write operations on other objects...
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
QColor backgroundColor() const
Returns the cell's background color, or an invalid color if a default color should be used for the ba...
bool getTableContents(QgsLayoutTableContents &contents) override
Fetches the contents used for the cells in the table.
virtual bool calculateMaxRowHeights()
Calculates the maximum height of text shown in rows.
void setIncludeTableHeader(bool included)
Sets whether the table includes a header row.
QString displayName() const override
Returns the multiframe display name.
void setTableContents(const QgsTableContents &contents)
Sets the contents of the table.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
A class to display a table in the print layout, and allow the table to span over multiple frames...
void setHeaders(const QgsLayoutTableColumns &headers)
Replaces the headers in the table with a specified list of QgsLayoutTableColumns. ...
Encapsulates the contents and formatting of a single table cell.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
QVector< QgsLayoutTableColumn *> QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setProperties(const QVariantMap &properties, const QgsReadWriteContext &context)
Sets the properties for the cell.
Stores properties of a column for a QgsLayoutTable.
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
No headers shown for table.
void setHeaderMode(HeaderMode mode)
Sets the display mode for headers in the table.
bool calculateMaxRowHeights() override
Calculates the maximum height of text shown in rows.
QgsTableContents tableContents() const
Returns the contents of the table.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
const QgsLayout * layout() const
Returns the layout the object is attached to.
Conditional styling for a rule.
void setRowHeights(const QList< double > &heights)
Sets the list of row heights (in millimeters) to use when rendering the table.
QgsLayoutTableColumns & headers()
Returns a reference to the list of headers shown in the table.
QgsConditionalStyle conditionalCellStyle(int row, int column) const override
Returns the conditional style to use for the cell at row, column.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
static QgsLayoutItemManualTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemManualTable for the specified parent layout.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
QIcon icon() const override
Returns the item's icon.
void setColumnWidths(const QList< double > &widths)
Sets the list of column widths (in millimeters) to use when rendering the table.
QVector< QgsTableRow > QgsTableContents
A set of table rows.
QgsLayoutTableColumns mColumns
Columns to show in table.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
~QgsLayoutItemManualTable() override
Headers shown on all frames.
A context for numeric formats.
A layout table subclass that displays manually entered (and formatted) content.
QgsLayoutTableColumns & columns()
Returns a reference to the list of QgsLayoutTableColumns shown in the table.
bool includeTableHeader() const
Returns true if the table includes a header row.
void setColumns(const QgsLayoutTableColumns &columns)
Replaces the columns in the table with a specified list of QgsLayoutTableColumns. ...
void changed()
Emitted when the object's properties change.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
int type() const override
Returns unique multiframe type id.
QColor foregroundColor() const
Returns the cell's foreground color, or an invalid color if a default color should be used for the fo...
QVector< QgsTableCell > QgsTableRow
A row of table cells.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
QVector< QVariant > QgsLayoutTableRow
List of QVariants, representing a the contents of a single row in a QgsLayoutTable.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
void setTextColor(const QColor &value)
Set the text color for the style.