QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
57 return tr(
"<Table frame>" );
66 for (
const QgsTableRow &row : qgis::as_const( mContents ) )
70 for (
int i = 0; i <
mColumns.count(); ++i )
72 if ( i < row.count() )
74 if ( row.at( i ).numericFormat() )
75 currentRow << row.at( i ).numericFormat()->formatDouble( row.at( i ).content().toDouble(), numericContext );
77 currentRow << row.at( i ).content().toString();
81 currentRow << QString();
93 if ( row < 0 || row >= mContents.size() )
97 if ( column < 0 || column > rowContents.size() )
102 if (
c.foregroundColor().isValid() )
104 if (
c.backgroundColor().isValid() )
125 mRowHeights = heights;
132 mColumnWidths = widths;
140 return mIncludeHeader;
145 mIncludeHeader = included;
147 if ( !mIncludeHeader )
174 tableElem.setAttribute( QStringLiteral(
"includeHeader" ), mIncludeHeader ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
177 QDomElement headersElem = doc.createElement( QStringLiteral(
"headers" ) );
180 QDomElement headerElem = doc.createElement( QStringLiteral(
"header" ) );
181 header.writeXml( headerElem, doc );
182 headersElem.appendChild( headerElem );
184 tableElem.appendChild( headersElem );
186 QDomElement contentsElement = doc.createElement( QStringLiteral(
"contents" ) );
189 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
190 for (
int i = 0; i <
mColumns.count(); ++i )
192 if ( i < row.count() )
197 contentsElement.appendChild( rowElement );
199 tableElem.appendChild( contentsElement );
201 QDomElement rowHeightsElement = doc.createElement( QStringLiteral(
"rowHeights" ) );
202 for (
double height : mRowHeights )
204 QDomElement rowElement = doc.createElement( QStringLiteral(
"row" ) );
205 rowElement.setAttribute( QStringLiteral(
"height" ), height );
206 rowHeightsElement.appendChild( rowElement );
208 tableElem.appendChild( rowHeightsElement );
210 QDomElement columnWidthsElement = doc.createElement( QStringLiteral(
"columnWidths" ) );
211 for (
double width : mColumnWidths )
213 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
214 columnElement.setAttribute( QStringLiteral(
"width" ), width );
215 columnWidthsElement.appendChild( columnElement );
217 tableElem.appendChild( columnWidthsElement );
227 mIncludeHeader = itemElem.attribute( QStringLiteral(
"includeHeader" ) ).toInt();
230 QDomNodeList headersList = itemElem.elementsByTagName( QStringLiteral(
"headers" ) );
231 if ( !headersList.isEmpty() )
233 QDomElement headersElem = headersList.at( 0 ).toElement();
234 QDomNodeList headerEntryList = headersElem.elementsByTagName( QStringLiteral(
"header" ) );
235 for (
int i = 0; i < headerEntryList.size(); ++i )
237 QDomElement headerElem = headerEntryList.at( i ).toElement();
240 mHeaders.append( header );
245 const QDomNodeList rowHeightNodeList = itemElem.firstChildElement( QStringLiteral(
"rowHeights" ) ).childNodes();
246 mRowHeights.reserve( rowHeightNodeList.size() );
247 for (
int r = 0; r < rowHeightNodeList.size(); ++r )
249 const QDomElement rowHeightElement = rowHeightNodeList.at( r ).toElement();
250 mRowHeights.append( rowHeightElement.attribute( QStringLiteral(
"height" ) ).toDouble() );
253 mColumnWidths.clear();
254 const QDomNodeList columnWidthNodeList = itemElem.firstChildElement( QStringLiteral(
"columnWidths" ) ).childNodes();
255 mColumnWidths.reserve( columnWidthNodeList.size() );
256 for (
int r = 0; r < columnWidthNodeList.size(); ++r )
258 const QDomElement columnWidthElement = columnWidthNodeList.at( r ).toElement();
259 mColumnWidths.append( columnWidthElement.attribute( QStringLiteral(
"width" ) ).toDouble() );
263 const QDomElement contentsElement = itemElem.firstChildElement( QStringLiteral(
"contents" ) );
264 const QDomNodeList rowNodeList = contentsElement.childNodes();
265 newContents.reserve( rowNodeList.size() );
266 for (
int r = 0; r < rowNodeList.size(); ++r )
269 const QDomElement rowElement = rowNodeList.at( r ).toElement();
270 const QDomNodeList cellNodeList = rowElement.childNodes();
271 row.reserve( cellNodeList.size() );
272 for (
int c = 0;
c < cellNodeList.size(); ++
c )
274 const QDomElement cellElement = cellNodeList.at(
c ).toElement();
292 QMap<int, double> newHeights;
296 const int row = it.key() - 1;
297 const double presetHeight = mRowHeights.value( row );
298 double thisRowHeight = it.value();
299 if ( presetHeight > 0 )
300 thisRowHeight = presetHeight;
301 newHeights.insert( row + 1, thisRowHeight );
307 void QgsLayoutItemManualTable::refreshColumns()
311 if ( !mContents.empty() )
315 columns.reserve( firstRow.size() );
320 newCol.setWidth( mColumnWidths.value( colIndex ) );
QgsLayoutTableColumns & headers()
Returns a reference to the list of headers shown in the table.
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.
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsTableContents tableContents() const
Returns the contents of the table.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
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.
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
QVector< QgsTableRow > QgsTableContents
A set of table rows.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
Encapsulates the contents and formatting of a single table cell.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
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.
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.
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.
QVector< QVariant > QgsLayoutTableRow
~QgsLayoutItemManualTable() override
QgsLayoutTableColumns mColumns
Columns to show in table.
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.
bool calculateMaxRowHeights() override
Calculates the maximum height of text shown in rows.