37 styleElem.setAttribute( QStringLiteral(
"enabled" ),
enabled );
44 enabled = ( styleElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
70 elem.setAttribute( QStringLiteral(
"cellMargin" ), QString::number(
mCellMargin ) );
71 elem.setAttribute( QStringLiteral(
"emptyTableMode" ), QString::number(
static_cast< int >(
mEmptyTableMode ) ) );
73 elem.setAttribute( QStringLiteral(
"showEmptyRows" ),
mShowEmptyRows );
75 QDomElement headerElem = doc.createElement( QStringLiteral(
"headerTextFormat" ) );
77 headerElem.appendChild( headerTextElem );
78 elem.appendChild( headerElem );
79 elem.setAttribute( QStringLiteral(
"headerHAlignment" ), QString::number(
static_cast< int >(
mHeaderHAlignment ) ) );
80 elem.setAttribute( QStringLiteral(
"headerMode" ), QString::number(
static_cast< int >(
mHeaderMode ) ) );
82 QDomElement contentElem = doc.createElement( QStringLiteral(
"contentTextFormat" ) );
84 contentElem.appendChild( contentTextElem );
85 elem.appendChild( contentElem );
86 elem.setAttribute( QStringLiteral(
"gridStrokeWidth" ), QString::number(
mGridStrokeWidth ) );
88 elem.setAttribute( QStringLiteral(
"horizontalGrid" ),
mHorizontalGrid );
89 elem.setAttribute( QStringLiteral(
"verticalGrid" ),
mVerticalGrid );
90 elem.setAttribute( QStringLiteral(
"showGrid" ),
mShowGrid );
92 elem.setAttribute( QStringLiteral(
"wrapBehavior" ), QString::number(
static_cast< int >(
mWrapBehavior ) ) );
95 QDomElement displayColumnsElem = doc.createElement( QStringLiteral(
"displayColumns" ) );
98 QDomElement columnElem = doc.createElement( QStringLiteral(
"column" ) );
99 column.writeXml( columnElem, doc );
100 displayColumnsElem.appendChild( columnElem );
102 elem.appendChild( displayColumnsElem );
104 QDomElement sortColumnsElem = doc.createElement( QStringLiteral(
"sortColumns" ) );
107 QDomElement columnElem = doc.createElement( QStringLiteral(
"column" ) );
108 column.writeXml( columnElem, doc );
109 sortColumnsElem.appendChild( columnElem );
111 elem.appendChild( sortColumnsElem );
115 QDomElement stylesElem = doc.createElement( QStringLiteral(
"cellStyles" ) );
116 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
117 for ( ; it != mCellStyleNames.constEnd(); ++it )
119 QString styleName = it.value();
120 QDomElement styleElem = doc.createElement( styleName );
125 stylesElem.appendChild( styleElem );
128 elem.appendChild( stylesElem );
135 mEmptyTableMessage = itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), tr(
"No matching records" ) );
136 mShowEmptyRows = itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt();
138 const QDomElement
headerTextFormat = itemElem.firstChildElement( QStringLiteral(
"headerTextFormat" ) );
141 QDomNodeList textFormatNodeList =
headerTextFormat.elementsByTagName( QStringLiteral(
"text-style" ) );
142 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
150 headerFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
170 const QDomElement
contentTextFormat = itemElem.firstChildElement( QStringLiteral(
"contentTextFormat" ) );
173 QDomNodeList textFormatNodeList =
contentTextFormat.elementsByTagName( QStringLiteral(
"text-style" ) );
174 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
182 contentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
199 mCellMargin = itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble();
200 mGridStrokeWidth = itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble();
201 mHorizontalGrid = itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt();
202 mVerticalGrid = itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt();
203 mShowGrid = itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt();
210 QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
211 if ( !columnsList.isEmpty() )
213 QDomElement columnsElem = columnsList.at( 0 ).toElement();
214 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
215 for (
int i = 0; i < columnEntryList.size(); ++i )
217 QDomElement columnElem = columnEntryList.at( i ).toElement();
225 QDomNodeList sortColumnsList = itemElem.elementsByTagName( QStringLiteral(
"sortColumns" ) );
226 if ( !sortColumnsList.isEmpty() )
228 QDomElement columnsElem = sortColumnsList.at( 0 ).toElement();
229 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
230 for (
int i = 0; i < columnEntryList.size(); ++i )
232 QDomElement columnElem = columnEntryList.at( i ).toElement();
249 QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
250 if ( !stylesList.isEmpty() )
252 QDomElement stylesElem = stylesList.at( 0 ).toElement();
254 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
255 for ( ; it != mCellStyleNames.constEnd(); ++it )
257 QString styleName = it.value();
258 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
259 if ( !styleList.isEmpty() )
261 QDomElement styleElem = styleList.at( 0 ).toElement();
287 double headerHeight = 0;
299 double contentHeight = frameHeight - headerHeight;
303 int currentRow = firstRow;
304 while ( contentHeight > 0 && currentRow <=
mTableContents.count() )
307 contentHeight -= currentRowHeight;
311 if ( includeEmptyRows && contentHeight > 0 )
315 currentRow += std::max( std::floor( contentHeight / rowHeight ), 0.0 );
318 return currentRow - firstRow - 1;
330 bool includeHeader =
false;
334 includeHeader =
true;
336 return rowsVisible( context, frameExtent.height(), firstRow, includeHeader, includeEmptyRows );
345 return qMakePair( 0, 0 );
350 int rowsAlreadyShown = 0;
353 rowsAlreadyShown +=
rowsVisible( context, idx, rowsAlreadyShown,
false );
357 int firstVisible = std::min( rowsAlreadyShown,
static_cast<int>(
mTableContents.length() ) );
359 int lastVisible = std::min( firstVisible + possibleRowsVisible,
static_cast<int>(
mTableContents.length() ) );
361 return qMakePair( firstVisible, lastVisible );
373 if ( !
mLayout->renderContext().isPreviewRender() )
398 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
399 int numberEmptyRows = 0;
403 numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
405 bool mergeCells =
false;
420 p->setPen( Qt::SolidLine );
422 double currentX = gridSizeX;
423 double currentY = gridSizeY;
430 std::unique_ptr< QgsExpressionContextScope > headerCellScope = std::make_unique< QgsExpressionContextScope >();
431 headerCellScope->setVariable( QStringLiteral(
"column_number" ), col + 1,
true );
437 p->setPen( Qt::NoPen );
454 headerAlign = Qgis::TextHorizontalAlignment::Left;
457 headerAlign = Qgis::TextHorizontalAlignment::Center;
460 headerAlign = Qgis::TextHorizontalAlignment::Right;
466 const QStringList
str = column.heading().split(
'\n' );
475 headerAlign,
str, context.
renderContext(), headerFormat,
true, Qgis::TextVerticalAlignment::VerticalCenter,
482 currentX += gridSizeX;
486 currentY += cellHeaderHeight;
487 currentY += gridSizeY;
495 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
498 currentX = gridSizeX;
510 p->setPen( Qt::NoPen );
512 p->drawRect( fullCell );
519 const QString localizedString { QgsExpressionUtils::toLocalizedString( cellContents ) };
520 const QStringList
str = localizedString.split(
'\n' );
527 p->setClipRect( fullCell );
531 QColor foreColor = cellFormat.
color();
552 currentX += gridSizeX;
555 currentY += rowHeight;
556 currentY += gridSizeY;
560 if ( numberRowsToDraw > rowsDrawn )
563 p->setPen( Qt::NoPen );
566 for (
int row = rowsDrawn; row < numberRowsToDraw; ++row )
568 currentX = gridSizeX;
574 p->drawRect( QRectF( gridSizeX, currentY,
mTableSize.width() - 2 * gridSizeX, cellBodyHeightForEmptyRows ) );
590 currentX += gridSizeX;
594 currentY += cellBodyHeightForEmptyRows + gridSizeY;
605 gridPen.setJoinStyle( Qt::MiterJoin );
606 p->setPen( gridPen );
621 double messageY = gridSizeY + ( drawHeader ? cellHeaderHeight + gridSizeY : 0 );
622 cell = QRectF( messageX, messageY,
mTableSize.width() - messageX, cellBodyHeightForEmptyRows );
698 if ( font.pointSizeF() > 0 )
703 else if ( font.pixelSize() > 0 )
782 if ( font.pointSizeF() > 0 )
787 else if ( font.pixelSize() > 0 )
942 if ( !newSortColumns.isEmpty() )
973 QMap<int, QString> headers;
978 headers.insert( i, col.heading() );
986 std::unique_ptr< QgsExpressionContextScope > cellScope = std::make_unique< QgsExpressionContextScope >();
987 cellScope->setVariable( QStringLiteral(
"row_number" ), row + 1,
true );
988 cellScope->setVariable( QStringLiteral(
"column_number" ), column + 1,
true );
989 return cellScope.release();
1013 for (
int col = 0; col <
mColumns.size(); ++ col )
1018 return QSizeF( 0, height );
1040void QgsLayoutTable::initStyles()
1052 mCellStyleNames.insert(
OddColumns, QStringLiteral(
"oddColumns" ) );
1053 mCellStyleNames.insert(
EvenColumns, QStringLiteral(
"evenColumns" ) );
1054 mCellStyleNames.insert(
OddRows, QStringLiteral(
"oddRows" ) );
1055 mCellStyleNames.insert(
EvenRows, QStringLiteral(
"evenRows" ) );
1056 mCellStyleNames.insert(
FirstColumn, QStringLiteral(
"firstColumn" ) );
1057 mCellStyleNames.insert(
LastColumn, QStringLiteral(
"lastColumn" ) );
1058 mCellStyleNames.insert(
HeaderRow, QStringLiteral(
"headerRow" ) );
1059 mCellStyleNames.insert(
FirstRow, QStringLiteral(
"firstRow" ) );
1060 mCellStyleNames.insert(
LastRow, QStringLiteral(
"lastRow" ) );
1070 QVector< double > widths( cells );
1072 double currentCellTextWidth;
1081 if ( col.width() > 0 )
1084 widths[i] = col.width();
1088 std::unique_ptr< QgsExpressionContextScope > headerCellScope = std::make_unique< QgsExpressionContextScope >();
1089 headerCellScope->setVariable( QStringLiteral(
"column_number" ), i + 1,
true );
1093 const QStringList multiLineSplit = col.heading().split(
'\n' );
1095 widths[i] = currentCellTextWidth;
1105 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
1109 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
1111 for ( ; colIt != rowIt->constEnd(); ++colIt )
1113 if (
mColumns.at( col ).width() <= 0 )
1116 const QStringList multiLineSplit = QgsExpressionUtils::toLocalizedString( *colIt ).split(
'\n' );
1123 widths[ row * cols + col ] = currentCellTextWidth;
1127 widths[ row * cols + col ] = 0;
1136 for (
int col = 0; col < cols; ++col )
1138 double maxColWidth = 0;
1141 maxColWidth = std::max( widths[ row * cols + col ], maxColWidth );
1156 QVector< double > heights( cells );
1165 std::unique_ptr< QgsExpressionContextScope > headerCellScope = std::make_unique< QgsExpressionContextScope >();
1166 headerCellScope->setVariable( QStringLiteral(
"column_number" ), i + 1,
true );
1180 QStringList() << col.heading(), Qgis::TextLayoutMode::Rectangle,
1192 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
1196 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
1198 for ( ; colIt != rowIt->constEnd(); ++colIt )
1204 const QString localizedString { QgsExpressionUtils::toLocalizedString( *colIt ) };
1208 QStringList() << localizedString.split(
'\n' ),
1209 Qgis::TextLayoutMode::Rectangle,
1223 double maxRowHeight = 0;
1224 for (
int col = 0; col < cols; ++col )
1226 maxRowHeight = std::max( heights[ row * cols + col ], maxRowHeight );
1270 int rowsAlreadyShown = 0;
1272 int rowsVisibleInLastFrame = 0;
1273 double heightOfLastFrame = 0;
1274 for (
int idx = 0; idx < numberExistingFrames; ++idx )
1278 heightOfLastFrame =
frame( idx )->rect().height();
1279 rowsVisibleInLastFrame =
rowsVisible( context, heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1280 rowsAlreadyShown += rowsVisibleInLastFrame;
1281 height += heightOfLastFrame;
1292 if ( remainingRows <= 0 )
1308 int numberFramesMissing = 0;
1309 while ( remainingRows > 0 )
1311 numberFramesMissing++;
1313 rowsVisibleInLastFrame =
rowsVisible( context, heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1314 if ( rowsVisibleInLastFrame < 1 )
1321 rowsAlreadyShown += rowsVisibleInLastFrame;
1327 height += heightOfLastFrame * numberFramesMissing;
1334 if ( lastRow - firstRow < 1 && !drawHeaderLines )
1343 double currentY = 0;
1344 currentY = halfGridStrokeWidth;
1345 if ( drawHeaderLines )
1347 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1351 for (
int row = firstRow; row < lastRow; ++row )
1353 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1358 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1365 if ( style->enabled && column % 2 == 0 )
1366 color = style->cellBackgroundColor;
1368 if ( style->enabled && column % 2 == 1 )
1369 color = style->cellBackgroundColor;
1371 if ( style->enabled && row % 2 == 0 )
1372 color = style->cellBackgroundColor;
1374 if ( style->enabled && row % 2 == 1 )
1375 color = style->cellBackgroundColor;
1377 if ( style->enabled && column == 0 )
1378 color = style->cellBackgroundColor;
1380 if ( style->enabled && column ==
mColumns.count() - 1 )
1381 color = style->cellBackgroundColor;
1383 if ( style->enabled && row == -1 )
1384 color = style->cellBackgroundColor;
1386 if ( style->enabled && row == 0 )
1387 color = style->cellBackgroundColor;
1390 color = style->cellBackgroundColor;
1405 if ( lastRow - firstRow < 1 && !hasHeader )
1413 double tableHeight = 0;
1419 double headerHeight = tableHeight;
1422 for (
int row = firstRow; row < lastRow; ++row )
1429 double currentX = halfGridStrokeWidth;
1430 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1432 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
1434 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
1436 currentX += ( maxColWidthIt.value() + 2 *
mCellMargin );
1437 if ( col == maxWidthMap.size() || !mergeCells )
1439 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1441 else if ( hasHeader )
1443 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
1462 return (
contents.indexOf( row ) >= 0 );
1477 return mColumns.value( column ).hAlignment();
1482 return mColumns.value( column ).vAlignment();
@ ApplyScalingWorkaroundForTextRendering
Whether a scaling workaround designed to stablise the rendering of small font sizes (or for painters ...
TextHorizontalAlignment
Text horizontal alignment.
@ WrapLines
Automatically wrap long lines of text.
Conditional styling for a rule.
QColor backgroundColor() const
The background color for style.
QColor textColor() const
The text color set for style.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
QRectF extent() const
Returns the visible portion of the multi frame's content which is shown in this frame,...
Item representing the paper in a layout.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
int frameCount() const
Returns the number of frames associated with this multiframe.
QgsLayoutFrame * frame(int index) const
Returns the child frame at a specified index from the multiframe.
@ ExtendToNextPage
Creates new full page frames on the following page(s) until the entire multiframe content is visible.
void refresh() override
Refreshes the multiframe, causing a recalculation of any property overrides.
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of its component frames.
void update()
Forces a redraw of all child frames.
int frameIndex(QgsLayoutFrame *frame) const
Returns the index of a frame within the multiframe.
void recalculateFrameRects()
Forces a recalculation of all the associated frame's scene rectangles.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
double height() const
Returns the height of the size.
Stores properties of a column for a QgsLayoutTable.
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
Styling option for a layout table cell.
bool readXml(const QDomElement &styleElem)
Reads the style's properties from XML.
QColor cellBackgroundColor
Cell background color.
bool enabled
Whether the styling option is enabled.
bool writeXml(QDomElement &styleElem, QDomDocument &doc) const
Writes the style's properties to XML for storage.
bool mHorizontalGrid
True if grid should be shown.
QSizeF fixedFrameSize(int frameIndex=-1) const override
Returns the fixed size for a frame, if desired.
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.
Q_DECL_DEPRECATED void setHeaderFontColor(const QColor &color)
Sets the color used to draw header text in the table.
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.
QColor backgroundColor() const
Returns the color used for the background of the table.
virtual QgsConditionalStyle conditionalCellStyle(int row, int column) const
Returns the conditional style to use for the cell at row, column.
void setHeaderHAlignment(HeaderHAlignment alignment)
Sets the horizontal alignment for table headers.
void setShowEmptyRows(bool showEmpty)
Sets whether empty rows should be drawn.
Q_DECL_DEPRECATED QFont headerFont() const
Returns the font used to draw header text in the table.
QMap< int, double > mMaxColumnWidthMap
Map of maximum width for each column.
void setVerticalGrid(bool verticalGrid)
Sets whether the grid's vertical lines should be drawn in the table.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
void setGridColor(const QColor &color)
Sets the color used for grid lines in the table.
double totalWidth()
Returns total width of table contents.
bool horizontalGrid() const
Returns whether the grid's horizontal lines are drawn in the table.
Q_DECL_DEPRECATED void setContentFontColor(const QColor &color)
Sets the color used to draw text in table body cells.
void setCellMargin(double margin)
Sets the margin distance in mm between cell borders and their contents.
void render(QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex) override
Renders a portion of the multiframe's content into a render context.
Q_DECL_DEPRECATED void setHeaderFont(const QFont &font)
Sets the font used to draw header text in the table.
void drawVerticalGridLines(QgsLayoutItemRenderContext &context, const QMap< int, double > &maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells=false) const
Draws the vertical grid lines for the table.
QgsLayoutTableSortColumns & sortColumns()
Returns a reference to the list of QgsLayoutTableSortColumns shown in the table.
void setBackgroundColor(const QColor &color)
Sets the color used for background of table.
void setContentTextFormat(const QgsTextFormat &format)
Sets the format used to draw content text in the table.
QgsTextFormat contentTextFormat() const
Returns the format used to draw content text in the table.
QString mEmptyTableMessage
String to show in empty tables.
void setWrapBehavior(WrapBehavior behavior)
Sets the wrap behavior for the table, which controls how text within cells is automatically wrapped.
Q_DECL_DEPRECATED QColor headerFontColor() const
Returns the color used to draw header text in the table.
QPair< int, int > rowRange(QgsRenderContext &context, int frameIndex) const
Calculates a range of rows which should be visible in a given frame.
double mGridStrokeWidth
Width of grid lines.
EmptyTableMode mEmptyTableMode
Behavior for empty tables.
void setEmptyTableBehavior(EmptyTableMode mode)
Sets the behavior mode for empty tables with no content rows.
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.
Q_DECL_DEPRECATED void setContentFont(const QFont &font)
Sets the font used to draw text in table body cells.
WrapBehavior mWrapBehavior
bool verticalGrid() const
Returns whether the grid's vertical lines are drawn in the table.
QColor mBackgroundColor
Color for table background.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
void drawHorizontalGridLines(QgsLayoutItemRenderContext &context, int firstRow, int lastRow, bool drawHeaderLines) const
Draws the horizontal grid lines for the table.
virtual QgsExpressionContextScope * scopeForCell(int row, int column) const
Creates a new QgsExpressionContextScope for the cell at row, column.
Q_DECL_DEPRECATED QFont contentFont() const
Returns the font used to draw text in table body cells.
bool contentsContainsRow(const QgsLayoutTableContents &contents, const QgsLayoutTableRow &row) const
Checks whether a table contents contains a given row.
bool mShowGrid
True if grid should be shown.
CellStyleGroup
Row or column groups for cell styling.
@ FirstRow
Style first row only.
@ EvenColumns
Style even numbered columns.
@ EvenRows
Style even numbered rows.
@ HeaderRow
Style header row.
@ OddColumns
Style odd numbered columns.
@ FirstColumn
Style first column only.
@ LastColumn
Style last column only.
@ LastRow
Style last row only.
@ OddRows
Style odd numbered rows.
QgsTextFormat mHeaderTextFormat
void setHorizontalGrid(bool horizontalGrid)
Sets whether the grid's horizontal lines should be drawn in the table.
HeaderMode
Controls where headers are shown in the table.
@ FirstFrame
Header shown on first frame only.
@ AllFrames
Headers shown on all frames.
@ NoHeaders
No headers shown for table.
void setCellStyle(CellStyleGroup group, const QgsLayoutTableStyle &style)
Sets the cell style for a cell group.
QgsLayoutTableColumns mColumns
Columns to show in table.
const QgsLayoutTableStyle * cellStyle(CellStyleGroup group) const
Returns the cell style for a cell group.
void setShowGrid(bool showGrid)
Sets whether grid lines should be drawn in the table.
QgsTextFormat mContentTextFormat
virtual bool getTableContents(QgsLayoutTableContents &contents)=0
Fetches the contents used for the cells in the table.
virtual bool calculateMaxColumnWidths()
Calculates the maximum width of text shown in columns.
~QgsLayoutTable() override
QgsTextFormat headerTextFormat() const
Returns the format used to draw header text in the table.
HeaderMode mHeaderMode
Header display mode.
HeaderHAlignment mHeaderHAlignment
Alignment for table headers.
int rowsVisible(QgsRenderContext &context, double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows) const
Calculates how many content rows would be visible within a frame of the specified height.
void recalculateFrameSizes() override
bool mShowEmptyRows
True if empty rows should be shown in the table.
QColor mGridColor
Color for grid lines.
QSizeF minFrameSize(int frameIndex=-1) const override
Returns the minimum size for a frames, if desired.
double mCellMargin
Margin between cell borders and cell text.
virtual Qt::Alignment verticalAlignmentForCell(int row, int column) const
Returns the vertical alignment to use for the cell at the specified row and column.
Q_DECL_DEPRECATED QColor contentFontColor() const
Returns the color used to draw text in table body cells.
double totalHeight()
Returns total height of table contents.
QgsLayoutTableContents mTableContents
Contents to show in table.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
void setEmptyTableMessage(const QString &message)
Sets the message for empty tables with no content rows.
void setSortColumns(const QgsLayoutTableSortColumns &sortColumns)
Replaces the sorting columns in the table with a specified list of QgsLayoutTableSortColumns.
void setHeaderTextFormat(const QgsTextFormat &format)
Sets the format used to draw header text in the table.
QgsLayoutTableSortColumns mSortColumns
Columns to sort the table.
bool showGrid() const
Returns whether grid lines are drawn in the table.
virtual QMap< int, QString > headerLabels() const
Returns the text used in the column headers for the table.
void setGridStrokeWidth(double width)
Sets the width in mm for grid lines in the table.
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.
QSizeF totalSize() const override
Returns the total size of the multiframe's content, in layout units.
bool mVerticalGrid
True if grid should be shown.
virtual bool calculateMaxRowHeights()
Calculates the maximum height of text shown in rows.
WrapBehavior
Controls how long strings in the table are handled.
@ WrapText
Text which doesn't fit inside the cell is wrapped. Note that this only applies to text in columns wit...
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
@ HeaderRight
Align headers right.
@ HeaderLeft
Align headers left.
@ HeaderCenter
Align headers to center.
@ FollowColumn
Header uses the same alignment as the column.
EmptyTableMode
Controls how empty tables are displayed.
@ HideTable
Hides entire table if empty.
@ ShowMessage
Shows preset message instead of table contents.
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
QMap< CellStyleGroup, QgsLayoutTableStyle * > mCellStyles
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QgsExpressionContext & expressionContext()
Gets the expression context.
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Scoped object for saving and restoring a QPainter object's state.
Scoped object for temporary scaling of a QgsRenderContext for pixel based rendering.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void updateDataDefinedProperties(QgsRenderContext &context)
Updates the format by evaluating current values of data defined properties.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QFont toQFont() const
Returns a QFont matching the relevant settings from this text format.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QColor color() const
Returns the color that text will be rendered in.
static Qgis::TextVerticalAlignment convertQtVAlignment(Qt::Alignment alignment)
Converts a Qt vertical alignment flag to a Qgis::TextVerticalAlignment value.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
static QFontMetricsF fontMetrics(QgsRenderContext &context, const QgsTextFormat &format, double scaleFactor=1.0)
Returns the font metrics for the given text format, when rendered in the specified render context.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags())
Draws text within a rectangle using the specified settings.
static constexpr double FONT_WORKAROUND_SCALE
Scale factor for upscaling font sizes and downscaling destination painter devices.
static Qgis::TextHorizontalAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a Qgis::TextHorizontalAlignment value.
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
QVector< QgsLayoutTableColumn > QgsLayoutTableSortColumns
List of column definitions for sorting 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.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)