39 styleElem.setAttribute( QStringLiteral(
"enabled" ),
enabled );
46 enabled = ( styleElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
72 elem.setAttribute( QStringLiteral(
"cellMargin" ), QString::number(
mCellMargin ) );
73 elem.setAttribute( QStringLiteral(
"emptyTableMode" ), QString::number(
static_cast< int >(
mEmptyTableMode ) ) );
75 elem.setAttribute( QStringLiteral(
"showEmptyRows" ),
mShowEmptyRows );
77 QDomElement headerElem = doc.createElement( QStringLiteral(
"headerTextFormat" ) );
79 headerElem.appendChild( headerTextElem );
80 elem.appendChild( headerElem );
81 elem.setAttribute( QStringLiteral(
"headerHAlignment" ), QString::number(
static_cast< int >(
mHeaderHAlignment ) ) );
82 elem.setAttribute( QStringLiteral(
"headerMode" ), QString::number(
static_cast< int >(
mHeaderMode ) ) );
84 QDomElement contentElem = doc.createElement( QStringLiteral(
"contentTextFormat" ) );
86 contentElem.appendChild( contentTextElem );
87 elem.appendChild( contentElem );
88 elem.setAttribute( QStringLiteral(
"gridStrokeWidth" ), QString::number(
mGridStrokeWidth ) );
90 elem.setAttribute( QStringLiteral(
"horizontalGrid" ),
mHorizontalGrid );
91 elem.setAttribute( QStringLiteral(
"verticalGrid" ),
mVerticalGrid );
92 elem.setAttribute( QStringLiteral(
"showGrid" ),
mShowGrid );
94 elem.setAttribute( QStringLiteral(
"wrapBehavior" ), QString::number(
static_cast< int >(
mWrapBehavior ) ) );
97 QDomElement displayColumnsElem = doc.createElement( QStringLiteral(
"displayColumns" ) );
100 QDomElement columnElem = doc.createElement( QStringLiteral(
"column" ) );
101 column.writeXml( columnElem, doc );
102 displayColumnsElem.appendChild( columnElem );
104 elem.appendChild( displayColumnsElem );
106 QDomElement sortColumnsElem = doc.createElement( QStringLiteral(
"sortColumns" ) );
109 QDomElement columnElem = doc.createElement( QStringLiteral(
"column" ) );
110 column.writeXml( columnElem, doc );
111 sortColumnsElem.appendChild( columnElem );
113 elem.appendChild( sortColumnsElem );
117 QDomElement stylesElem = doc.createElement( QStringLiteral(
"cellStyles" ) );
118 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
119 for ( ; it != mCellStyleNames.constEnd(); ++it )
121 QString styleName = it.value();
122 QDomElement styleElem = doc.createElement( styleName );
127 stylesElem.appendChild( styleElem );
130 elem.appendChild( stylesElem );
137 mEmptyTableMessage = itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), tr(
"No matching records" ) );
138 mShowEmptyRows = itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt();
140 const QDomElement
headerTextFormat = itemElem.firstChildElement( QStringLiteral(
"headerTextFormat" ) );
143 QDomNodeList textFormatNodeList =
headerTextFormat.elementsByTagName( QStringLiteral(
"text-style" ) );
144 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
152 headerFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
172 const QDomElement
contentTextFormat = itemElem.firstChildElement( QStringLiteral(
"contentTextFormat" ) );
175 QDomNodeList textFormatNodeList =
contentTextFormat.elementsByTagName( QStringLiteral(
"text-style" ) );
176 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
184 contentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
201 mCellMargin = itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble();
202 mGridStrokeWidth = itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble();
203 mHorizontalGrid = itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt();
204 mVerticalGrid = itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt();
205 mShowGrid = itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt();
212 QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
213 if ( !columnsList.isEmpty() )
215 QDomElement columnsElem = columnsList.at( 0 ).toElement();
216 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
217 for (
int i = 0; i < columnEntryList.size(); ++i )
219 QDomElement columnElem = columnEntryList.at( i ).toElement();
227 QDomNodeList sortColumnsList = itemElem.elementsByTagName( QStringLiteral(
"sortColumns" ) );
228 if ( !sortColumnsList.isEmpty() )
230 QDomElement columnsElem = sortColumnsList.at( 0 ).toElement();
231 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
232 for (
int i = 0; i < columnEntryList.size(); ++i )
234 QDomElement columnElem = columnEntryList.at( i ).toElement();
251 QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
252 if ( !stylesList.isEmpty() )
254 QDomElement stylesElem = stylesList.at( 0 ).toElement();
256 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
257 for ( ; it != mCellStyleNames.constEnd(); ++it )
259 QString styleName = it.value();
260 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
261 if ( !styleList.isEmpty() )
263 QDomElement styleElem = styleList.at( 0 ).toElement();
289 double headerHeight = 0;
292 for (
int col = 0; col <
mColumns.count(); ++ col )
306 double contentHeight = frameHeight - headerHeight;
310 int currentRow = firstRow;
311 while ( contentHeight > 0 && currentRow <=
mTableContents.count() )
314 contentHeight -= currentRowHeight;
318 if ( includeEmptyRows && contentHeight > 0 )
322 currentRow += std::max( std::floor( contentHeight / rowHeight ), 0.0 );
325 return currentRow - firstRow - 1;
337 bool includeHeader =
false;
341 includeHeader =
true;
343 return rowsVisible( context, frameExtent.height(), firstRow, includeHeader, includeEmptyRows );
352 return qMakePair( 0, 0 );
357 int rowsAlreadyShown = 0;
360 rowsAlreadyShown +=
rowsVisible( context, idx, rowsAlreadyShown,
false );
364 int firstVisible = std::min( rowsAlreadyShown,
static_cast<int>(
mTableContents.length() ) );
366 int lastVisible = std::min( firstVisible + possibleRowsVisible,
static_cast<int>(
mTableContents.length() ) );
368 return qMakePair( firstVisible, lastVisible );
380 if ( !
mLayout->renderContext().isPreviewRender() )
405 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
406 int numberEmptyRows = 0;
410 numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
412 bool mergeCells =
false;
427 p->setPen( Qt::SolidLine );
429 double currentX = gridSizeX;
430 double currentY = gridSizeY;
437 std::unique_ptr< QgsExpressionContextScope > headerCellScope = std::make_unique< QgsExpressionContextScope >();
438 headerCellScope->setVariable( QStringLiteral(
"column_number" ), col + 1,
true );
444 p->setPen( Qt::NoPen );
475 QStringList
str = column.heading().split(
'\n' );
478 str = wrappedText( context.
renderContext(), column.heading(), column.width(), headerFormat );
493 currentX += gridSizeX;
497 currentY += cellHeaderHeight;
498 currentY += gridSizeY;
506 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
509 currentX = gridSizeX;
520 p->setPen( Qt::NoPen );
522 p->drawRect( fullCell );
529 const QString localizedString { QgsExpressionUtils::toLocalizedString( cellContents ) };
530 QStringList
str = localizedString.split(
'\n' );
540 str = wrappedText( context.
renderContext(), localizedString, column.width(), cellFormat );
544 p->setClipRect( fullCell );
548 QColor foreColor = cellFormat.
color();
568 currentX += gridSizeX;
571 currentY += rowHeight;
572 currentY += gridSizeY;
576 if ( numberRowsToDraw > rowsDrawn )
579 p->setPen( Qt::NoPen );
582 for (
int row = rowsDrawn; row < numberRowsToDraw; ++row )
584 currentX = gridSizeX;
590 p->drawRect( QRectF( gridSizeX, currentY,
mTableSize.width() - 2 * gridSizeX, cellBodyHeightForEmptyRows ) );
606 currentX += gridSizeX;
610 currentY += cellBodyHeightForEmptyRows + gridSizeY;
621 gridPen.setJoinStyle( Qt::MiterJoin );
622 p->setPen( gridPen );
637 double messageY = gridSizeY + ( drawHeader ? cellHeaderHeight + gridSizeY : 0 );
638 cell = QRectF( messageX, messageY,
mTableSize.width() - messageX, cellBodyHeightForEmptyRows );
714 if ( font.pointSizeF() > 0 )
719 else if ( font.pixelSize() > 0 )
798 if ( font.pointSizeF() > 0 )
803 else if ( font.pixelSize() > 0 )
958 if ( !newSortColumns.isEmpty() )
989 QMap<int, QString> headers;
994 headers.insert( i, col.heading() );
1002 std::unique_ptr< QgsExpressionContextScope > cellScope = std::make_unique< QgsExpressionContextScope >();
1003 cellScope->setVariable( QStringLiteral(
"row_number" ), row + 1,
true );
1004 cellScope->setVariable( QStringLiteral(
"column_number" ), column + 1,
true );
1005 return cellScope.release();
1029 for (
int col = 0; col <
mColumns.size(); ++ col )
1034 return QSizeF( 0, height );
1056 void QgsLayoutTable::initStyles()
1068 mCellStyleNames.insert(
OddColumns, QStringLiteral(
"oddColumns" ) );
1069 mCellStyleNames.insert(
EvenColumns, QStringLiteral(
"evenColumns" ) );
1070 mCellStyleNames.insert(
OddRows, QStringLiteral(
"oddRows" ) );
1071 mCellStyleNames.insert(
EvenRows, QStringLiteral(
"evenRows" ) );
1072 mCellStyleNames.insert(
FirstColumn, QStringLiteral(
"firstColumn" ) );
1073 mCellStyleNames.insert(
LastColumn, QStringLiteral(
"lastColumn" ) );
1074 mCellStyleNames.insert(
HeaderRow, QStringLiteral(
"headerRow" ) );
1075 mCellStyleNames.insert(
FirstRow, QStringLiteral(
"firstRow" ) );
1076 mCellStyleNames.insert(
LastRow, QStringLiteral(
"lastRow" ) );
1086 QVector< double > widths( cells );
1088 double currentCellTextWidth;
1097 if ( col.width() > 0 )
1100 widths[i] = col.width();
1104 std::unique_ptr< QgsExpressionContextScope > headerCellScope = std::make_unique< QgsExpressionContextScope >();
1105 headerCellScope->setVariable( QStringLiteral(
"column_number" ), i + 1,
true );
1109 const QStringList multiLineSplit = col.heading().split(
'\n' );
1111 widths[i] = currentCellTextWidth;
1121 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
1125 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
1127 for ( ; colIt != rowIt->constEnd(); ++colIt )
1129 if (
mColumns.at( col ).width() <= 0 )
1132 const QStringList multiLineSplit = QgsExpressionUtils::toLocalizedString( *colIt ).split(
'\n' );
1139 widths[ row * cols + col ] = currentCellTextWidth;
1143 widths[ row * cols + col ] = 0;
1152 for (
int col = 0; col < cols; ++col )
1154 double maxColWidth = 0;
1157 maxColWidth = std::max( widths[ row * cols + col ], maxColWidth );
1172 QVector< double > heights( cells );
1181 std::unique_ptr< QgsExpressionContextScope > headerCellScope = std::make_unique< QgsExpressionContextScope >();
1182 headerCellScope->setVariable( QStringLiteral(
"column_number" ), i + 1,
true );
1192 else if ( textRequiresWrapping( context, col.heading(),
mColumns.at( i ).width(), cellFormat ) )
1208 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
1212 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
1214 for ( ; colIt != rowIt->constEnd(); ++colIt )
1220 const QString localizedString { QgsExpressionUtils::toLocalizedString( *colIt ) };
1222 if ( textRequiresWrapping( context, localizedString,
mColumns.at( i ).width(), cellFormat ) )
1240 double maxRowHeight = 0;
1241 for (
int col = 0; col < cols; ++col )
1243 maxRowHeight = std::max( heights[ row * cols + col ], maxRowHeight );
1287 int rowsAlreadyShown = 0;
1289 int rowsVisibleInLastFrame = 0;
1290 double heightOfLastFrame = 0;
1291 for (
int idx = 0; idx < numberExistingFrames; ++idx )
1295 heightOfLastFrame =
frame( idx )->rect().height();
1296 rowsVisibleInLastFrame =
rowsVisible( context, heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1297 rowsAlreadyShown += rowsVisibleInLastFrame;
1298 height += heightOfLastFrame;
1309 if ( remainingRows <= 0 )
1325 int numberFramesMissing = 0;
1326 while ( remainingRows > 0 )
1328 numberFramesMissing++;
1330 rowsVisibleInLastFrame =
rowsVisible( context, heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1331 if ( rowsVisibleInLastFrame < 1 )
1338 rowsAlreadyShown += rowsVisibleInLastFrame;
1344 height += heightOfLastFrame * numberFramesMissing;
1351 if ( lastRow - firstRow < 1 && !drawHeaderLines )
1360 double currentY = 0;
1361 currentY = halfGridStrokeWidth;
1362 if ( drawHeaderLines )
1364 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1368 for (
int row = firstRow; row < lastRow; ++row )
1370 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1375 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1378 bool QgsLayoutTable::textRequiresWrapping(
QgsRenderContext &context,
const QString &text,
double columnWidth,
const QgsTextFormat &format )
const
1383 const QStringList multiLineSplit = text.split(
'\n' );
1385 return currentTextWidth > columnWidth;
1388 QStringList QgsLayoutTable::wrappedText(
QgsRenderContext &context,
const QString &value,
double columnWidth,
const QgsTextFormat &format )
const
1390 QStringList lines = value.split(
'\n' );
1391 QStringList outLines;
1392 const auto constLines = lines;
1393 for (
const QString &line : constLines )
1395 if ( textRequiresWrapping( context, line, columnWidth, format ) )
1398 QStringList words = line.split(
' ' );
1399 QStringList linesToProcess;
1400 QString wordsInCurrentLine;
1401 const auto constWords = words;
1402 for (
const QString &word : constWords )
1404 if ( textRequiresWrapping( context, word, columnWidth, format ) )
1407 if ( !wordsInCurrentLine.isEmpty() )
1408 linesToProcess << wordsInCurrentLine;
1409 wordsInCurrentLine.clear();
1410 linesToProcess << word;
1414 if ( !wordsInCurrentLine.isEmpty() )
1415 wordsInCurrentLine.append(
' ' );
1416 wordsInCurrentLine.append( word );
1419 if ( !wordsInCurrentLine.isEmpty() )
1420 linesToProcess << wordsInCurrentLine;
1422 const auto constLinesToProcess = linesToProcess;
1423 for (
const QString &line : constLinesToProcess )
1425 QString remainingText = line;
1426 int lastPos = remainingText.lastIndexOf(
' ' );
1427 while ( lastPos > -1 )
1430 if ( !textRequiresWrapping( context, remainingText, columnWidth, format ) )
1435 if ( !textRequiresWrapping( context, remainingText.left( lastPos ), columnWidth, format ) )
1437 outLines << remainingText.left( lastPos );
1438 remainingText = remainingText.mid( lastPos + 1 );
1441 lastPos = remainingText.lastIndexOf(
' ', lastPos - 1 );
1443 outLines << remainingText;
1459 if ( style->enabled && column % 2 == 0 )
1460 color = style->cellBackgroundColor;
1462 if ( style->enabled && column % 2 == 1 )
1463 color = style->cellBackgroundColor;
1465 if ( style->enabled && row % 2 == 0 )
1466 color = style->cellBackgroundColor;
1468 if ( style->enabled && row % 2 == 1 )
1469 color = style->cellBackgroundColor;
1471 if ( style->enabled && column == 0 )
1472 color = style->cellBackgroundColor;
1474 if ( style->enabled && column ==
mColumns.count() - 1 )
1475 color = style->cellBackgroundColor;
1477 if ( style->enabled && row == -1 )
1478 color = style->cellBackgroundColor;
1480 if ( style->enabled && row == 0 )
1481 color = style->cellBackgroundColor;
1484 color = style->cellBackgroundColor;
1499 if ( lastRow - firstRow < 1 && !hasHeader )
1507 double tableHeight = 0;
1513 double headerHeight = tableHeight;
1516 for (
int row = firstRow; row < lastRow; ++row )
1523 double currentX = halfGridStrokeWidth;
1524 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1526 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
1528 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
1530 currentX += ( maxColWidthIt.value() + 2 *
mCellMargin );
1531 if ( col == maxWidthMap.size() || !mergeCells )
1533 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1535 else if ( hasHeader )
1537 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
1556 return (
contents.indexOf( row ) >= 0 );
1571 return mColumns.value( column ).hAlignment();
1576 return mColumns.value( column ).vAlignment();
@ ApplyScalingWorkaroundForTextRendering
Whether a scaling workaround designed to stablise the rendering of small font sizes (or for painters ...
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.
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.
QgsLayoutTableColumns & columns()
Returns a reference to the list of QgsLayoutTableColumns shown in the table.
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.
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.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
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.
QgsLayoutTableSortColumns & sortColumns()
Returns a reference to the list of QgsLayoutTableSortColumns shown 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.
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...
@ TruncateText
Text which doesn't fit inside the cell is truncated.
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
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).
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 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.
@ AlignVCenter
Center align.
HAlignment
Horizontal alignment.
@ AlignCenter
Center align.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr)
Returns the height 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 HAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
static VAlignment convertQtVAlignment(Qt::Alignment alignment)
Converts a Qt vertical alignment flag to a QgsTextRenderer::VAlignment value.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop)
Draws text within a rectangle using the specified settings.
@ Rect
Text within rectangle draw mode.
static constexpr double FONT_WORKAROUND_SCALE
Scale factor for upscaling font sizes and downscaling destination painter devices.
@ 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)