27#include "moc_qgslayoutitemmanualtable.cpp"
61 return tr(
"<Table frame>" );
73 for (
const QgsTableRow &row : std::as_const( mContents ) )
77 for (
int columnNumber = 0; columnNumber <
mColumns.count(); ++columnNumber )
79 if ( columnNumber < row.count() )
81 QVariant cellContent = row.at( columnNumber ).content();
83 if ( cellContent.userType() == qMetaTypeId<QgsProperty>() )
87 cellContent = cellContent.value<
QgsProperty >().value( context );
90 if ( row.at( columnNumber ).numericFormat() )
91 currentRow << row.at( columnNumber ).numericFormat()->formatDouble( cellContent.toDouble(), numericContext );
93 currentRow << cellContent.toString();
97 currentRow << QString();
110 if ( row < 0 || row >= mContents.size() )
114 if ( column < 0 || column > rowContents.size() )
119 if (
c.foregroundColor().isValid() )
121 if (
c.backgroundColor().isValid() )
142 mRowHeights = heights;
149 mColumnWidths = widths;
157 return mIncludeHeader;
162 mIncludeHeader = included;
164 if ( !mIncludeHeader )
191 tableElem.setAttribute( QStringLiteral(
"includeHeader" ), mIncludeHeader ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
194 QDomElement headersElem = doc.createElement( QStringLiteral(
"headers" ) );
197 QDomElement headerElem = doc.createElement( QStringLiteral(
"header" ) );
198 header.writeXml( headerElem, doc );
199 headersElem.appendChild( headerElem );
201 tableElem.appendChild( headersElem );
203 QDomElement contentsElement = doc.createElement( QStringLiteral(
"contents" ) );
206 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
207 for (
int i = 0; i <
mColumns.count(); ++i )
209 if ( i < row.count() )
214 contentsElement.appendChild( rowElement );
216 tableElem.appendChild( contentsElement );
218 QDomElement rowHeightsElement = doc.createElement( QStringLiteral(
"rowHeights" ) );
219 for (
double height : mRowHeights )
221 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
222 rowElement.setAttribute( QStringLiteral(
"height" ), height );
223 rowHeightsElement.appendChild( rowElement );
225 tableElem.appendChild( rowHeightsElement );
227 QDomElement columnWidthsElement = doc.createElement( QStringLiteral(
"columnWidths" ) );
228 for (
double width : mColumnWidths )
230 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
231 columnElement.setAttribute( QStringLiteral(
"width" ), width );
232 columnWidthsElement.appendChild( columnElement );
234 tableElem.appendChild( columnWidthsElement );
244 mIncludeHeader = itemElem.attribute( QStringLiteral(
"includeHeader" ) ).toInt();
247 QDomNodeList headersList = itemElem.elementsByTagName( QStringLiteral(
"headers" ) );
248 if ( !headersList.isEmpty() )
250 QDomElement headersElem = headersList.at( 0 ).toElement();
251 QDomNodeList headerEntryList = headersElem.elementsByTagName( QStringLiteral(
"header" ) );
252 for (
int i = 0; i < headerEntryList.size(); ++i )
254 QDomElement headerElem = headerEntryList.at( i ).toElement();
257 mHeaders.append( header );
262 const QDomNodeList rowHeightNodeList = itemElem.firstChildElement( QStringLiteral(
"rowHeights" ) ).childNodes();
263 mRowHeights.reserve( rowHeightNodeList.size() );
264 for (
int r = 0; r < rowHeightNodeList.size(); ++r )
266 const QDomElement rowHeightElement = rowHeightNodeList.at( r ).toElement();
267 mRowHeights.append( rowHeightElement.attribute( QStringLiteral(
"height" ) ).toDouble() );
270 mColumnWidths.clear();
271 const QDomNodeList columnWidthNodeList = itemElem.firstChildElement( QStringLiteral(
"columnWidths" ) ).childNodes();
272 mColumnWidths.reserve( columnWidthNodeList.size() );
273 for (
int r = 0; r < columnWidthNodeList.size(); ++r )
275 const QDomElement columnWidthElement = columnWidthNodeList.at( r ).toElement();
276 mColumnWidths.append( columnWidthElement.attribute( QStringLiteral(
"width" ) ).toDouble() );
280 const QDomElement contentsElement = itemElem.firstChildElement( QStringLiteral(
"contents" ) );
281 const QDomNodeList rowNodeList = contentsElement.childNodes();
282 newContents.reserve( rowNodeList.size() );
283 for (
int r = 0; r < rowNodeList.size(); ++r )
286 const QDomElement rowElement = rowNodeList.at( r ).toElement();
287 const QDomNodeList cellNodeList = rowElement.childNodes();
288 row.reserve( cellNodeList.size() );
289 for (
int c = 0;
c < cellNodeList.size(); ++
c )
291 const QDomElement cellElement = cellNodeList.at(
c ).toElement();
309 QMap<int, double> newHeights;
313 const int row = it.key() - 1;
314 const double presetHeight = mRowHeights.value( row );
315 double thisRowHeight = it.value();
316 if ( presetHeight > 0 )
317 thisRowHeight = presetHeight;
318 newHeights.insert( row + 1, thisRowHeight );
332 if ( mContents.value( row ).value( column ).textFormat().isValid() )
333 return mContents.value( row ).value( column ).textFormat();
340 if ( row < mContents.size() && column < mContents.at( row ).size() )
341 return mContents.value( row ).value( column ).horizontalAlignment();
348 if ( row < mContents.size() && column < mContents.at( row ).size() )
349 return mContents.value( row ).value( column ).verticalAlignment();
356 if ( row < mContents.size() && column < mContents.at( row ).size() )
357 return mContents.value( row ).value( column ).rowSpan();
363 if ( row < mContents.size() && column < mContents.at( row ).size() )
364 return mContents.value( row ).value( column ).columnSpan();
368void QgsLayoutItemManualTable::refreshColumns()
372 if ( !mContents.empty() )
376 columns.reserve( firstRow.size() );
381 newCol.setWidth( mColumnWidths.value( colIndex ) );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Conditional styling for a rule.
void setTextColor(const QColor &value)
Set the text color for the style.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
RAII class to pop scope from an expression context on destruction.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool calculateMaxRowHeights() override
Calculates the maximum height of text shown in rows.
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.
Qt::Alignment horizontalAlignmentForCell(int row, int column) const override
Returns the horizontal alignment to use for the cell at the specified row and column.
QString displayName() const override
Returns the multiframe display name.
int rowSpan(int row, int column) const override
Returns the row span for the cell a row, column.
~QgsLayoutItemManualTable() override
QgsConditionalStyle conditionalCellStyle(int row, int column) const override
Returns the conditional style to use for the cell at row, column.
Qt::Alignment verticalAlignmentForCell(int row, int column) const override
Returns the vertical alignment to use for the cell at the specified row and column.
static QgsLayoutItemManualTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemManualTable for the specified parent layout.
void setIncludeTableHeader(bool included)
Sets whether the table includes a header row.
void setHeaders(const QgsLayoutTableColumns &headers)
Replaces the headers in the table with a specified list of QgsLayoutTableColumns.
QgsTextFormat textFormatForCell(int row, int column) const override
Returns the text format to use for the cell at the specified row and column.
void setTableContents(const QgsTableContents &contents)
Sets the contents of the table.
int columnSpan(int row, int column) const override
Returns the column span for the cell a row, column.
QgsTextFormat textFormatForHeader(int column) const override
Returns the text format to use for the header cell at the specified column.
int type() const override
Returns unique multiframe type id.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
void setRowHeights(const QList< double > &heights)
Sets the list of row heights (in millimeters) to use when rendering the table.
bool includeTableHeader() const
Returns true if the table includes a header row.
QgsLayoutTableColumns & headers()
Returns a reference to the list of headers shown in the table.
QgsLayoutItemManualTable(QgsLayout *layout)
Constructor for QgsLayoutItemManualTable, attached to the specified layout.
QgsTableContents tableContents() const
Returns the contents of the table.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
bool getTableContents(QgsLayoutTableContents &contents) override
Fetches the contents used for the cells in the table.
@ LayoutManualTable
Manual (fixed) table.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
Stores properties of a column for a QgsLayoutTable.
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
QgsLayoutTableColumns & columns()
Returns a reference to the list of QgsLayoutTableColumns shown in the table.
void setColumns(const QgsLayoutTableColumns &columns)
Replaces the columns in the table with a specified list of QgsLayoutTableColumns.
QgsLayoutTable(QgsLayout *layout)
Constructor for QgsLayoutTable, belonging to the specified layout.
virtual Qt::Alignment horizontalAlignmentForCell(int row, int column) const
Returns the horizontal alignment to use for the cell at the specified row and column.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
virtual QgsTextFormat textFormatForHeader(int column) const
Returns the text format to use for the header cell at the specified column.
void setHeaderMode(HeaderMode mode)
Sets the display mode for headers in the table.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
virtual QgsExpressionContextScope * scopeForCell(int row, int column) const
Creates a new QgsExpressionContextScope for the cell at row, column.
@ AllFrames
Headers shown on all frames.
@ NoHeaders
No headers shown for table.
QgsLayoutTableColumns mColumns
Columns to show in table.
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 writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
virtual QgsTextFormat textFormatForCell(int row, int column) const
Returns the text format 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.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
virtual bool calculateMaxRowHeights()
Calculates the maximum height of text shown in rows.
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
A context for numeric formats.
A store for object properties.
A container for the context for various read/write operations on objects.
Encapsulates the contents and formatting of a single table cell.
void setProperties(const QVariantMap &properties, const QgsReadWriteContext &context)
Sets the properties for the cell.
Container for all settings relating to text rendering.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
QVector< QVariant > QgsLayoutTableRow
List of QVariants, representing a the contents of a single row in 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
QVector< QgsTableRow > QgsTableContents
A set of table rows.
QVector< QgsTableCell > QgsTableRow
A row of table cells.