19#include "moc_qgslayoutitemmanualtable.cpp"
59 return tr(
"<Table frame>" );
71 for (
const QgsTableRow &row : std::as_const( mContents ) )
75 for (
int columnNumber = 0; columnNumber <
mColumns.count(); ++columnNumber )
77 if ( columnNumber < row.count() )
79 QVariant cellContent = row.at( columnNumber ).content();
81 if ( cellContent.userType() == qMetaTypeId<QgsProperty>() )
85 cellContent = cellContent.value<
QgsProperty >().value( context );
88 if ( row.at( columnNumber ).numericFormat() )
89 currentRow << row.at( columnNumber ).numericFormat()->formatDouble( cellContent.toDouble(), numericContext );
91 currentRow << cellContent.toString();
95 currentRow << QString();
108 if ( row < 0 || row >= mContents.size() )
112 if ( column < 0 || column > rowContents.size() )
117 if (
c.foregroundColor().isValid() )
119 if (
c.backgroundColor().isValid() )
140 mRowHeights = heights;
147 mColumnWidths = widths;
155 return mIncludeHeader;
160 mIncludeHeader = included;
162 if ( !mIncludeHeader )
189 tableElem.setAttribute( QStringLiteral(
"includeHeader" ), mIncludeHeader ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
192 QDomElement headersElem = doc.createElement( QStringLiteral(
"headers" ) );
195 QDomElement headerElem = doc.createElement( QStringLiteral(
"header" ) );
196 header.writeXml( headerElem, doc );
197 headersElem.appendChild( headerElem );
199 tableElem.appendChild( headersElem );
201 QDomElement contentsElement = doc.createElement( QStringLiteral(
"contents" ) );
204 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
205 for (
int i = 0; i <
mColumns.count(); ++i )
207 if ( i < row.count() )
212 contentsElement.appendChild( rowElement );
214 tableElem.appendChild( contentsElement );
216 QDomElement rowHeightsElement = doc.createElement( QStringLiteral(
"rowHeights" ) );
217 for (
double height : mRowHeights )
219 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
220 rowElement.setAttribute( QStringLiteral(
"height" ), height );
221 rowHeightsElement.appendChild( rowElement );
223 tableElem.appendChild( rowHeightsElement );
225 QDomElement columnWidthsElement = doc.createElement( QStringLiteral(
"columnWidths" ) );
226 for (
double width : mColumnWidths )
228 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
229 columnElement.setAttribute( QStringLiteral(
"width" ), width );
230 columnWidthsElement.appendChild( columnElement );
232 tableElem.appendChild( columnWidthsElement );
242 mIncludeHeader = itemElem.attribute( QStringLiteral(
"includeHeader" ) ).toInt();
245 QDomNodeList headersList = itemElem.elementsByTagName( QStringLiteral(
"headers" ) );
246 if ( !headersList.isEmpty() )
248 QDomElement headersElem = headersList.at( 0 ).toElement();
249 QDomNodeList headerEntryList = headersElem.elementsByTagName( QStringLiteral(
"header" ) );
250 for (
int i = 0; i < headerEntryList.size(); ++i )
252 QDomElement headerElem = headerEntryList.at( i ).toElement();
255 mHeaders.append( header );
260 const QDomNodeList rowHeightNodeList = itemElem.firstChildElement( QStringLiteral(
"rowHeights" ) ).childNodes();
261 mRowHeights.reserve( rowHeightNodeList.size() );
262 for (
int r = 0; r < rowHeightNodeList.size(); ++r )
264 const QDomElement rowHeightElement = rowHeightNodeList.at( r ).toElement();
265 mRowHeights.append( rowHeightElement.attribute( QStringLiteral(
"height" ) ).toDouble() );
268 mColumnWidths.clear();
269 const QDomNodeList columnWidthNodeList = itemElem.firstChildElement( QStringLiteral(
"columnWidths" ) ).childNodes();
270 mColumnWidths.reserve( columnWidthNodeList.size() );
271 for (
int r = 0; r < columnWidthNodeList.size(); ++r )
273 const QDomElement columnWidthElement = columnWidthNodeList.at( r ).toElement();
274 mColumnWidths.append( columnWidthElement.attribute( QStringLiteral(
"width" ) ).toDouble() );
278 const QDomElement contentsElement = itemElem.firstChildElement( QStringLiteral(
"contents" ) );
279 const QDomNodeList rowNodeList = contentsElement.childNodes();
280 newContents.reserve( rowNodeList.size() );
281 for (
int r = 0; r < rowNodeList.size(); ++r )
284 const QDomElement rowElement = rowNodeList.at( r ).toElement();
285 const QDomNodeList cellNodeList = rowElement.childNodes();
286 row.reserve( cellNodeList.size() );
287 for (
int c = 0;
c < cellNodeList.size(); ++
c )
289 const QDomElement cellElement = cellNodeList.at(
c ).toElement();
307 QMap<int, double> newHeights;
311 const int row = it.key() - 1;
312 const double presetHeight = mRowHeights.value( row );
313 double thisRowHeight = it.value();
314 if ( presetHeight > 0 )
315 thisRowHeight = presetHeight;
316 newHeights.insert( row + 1, thisRowHeight );
330 if ( mContents.value( row ).value( column ).textFormat().isValid() )
331 return mContents.value( row ).value( column ).textFormat();
338 if ( row < mContents.size() && column < mContents.at( row ).size() )
339 return mContents.value( row ).value( column ).horizontalAlignment();
346 if ( row < mContents.size() && column < mContents.at( row ).size() )
347 return mContents.value( row ).value( column ).verticalAlignment();
354 if ( row < mContents.size() && column < mContents.at( row ).size() )
355 return mContents.value( row ).value( column ).rowSpan();
361 if ( row < mContents.size() && column < mContents.at( row ).size() )
362 return mContents.value( row ).value( column ).columnSpan();
366void QgsLayoutItemManualTable::refreshColumns()
370 if ( !mContents.empty() )
374 columns.reserve( firstRow.size() );
379 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...
A layout table subclass that displays manually entered (and formatted) content.
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.
A class to display a table in the print layout, and allow the table to span over multiple frames.
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.
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.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
A context for numeric formats.
A store for object properties.
The class is used as a container of context for various read/write operations on other 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.