35#include "moc_qgslayouttable.cpp"
37using namespace Qt::StringLiterals;
47 styleElem.setAttribute( u
"enabled"_s,
enabled );
54 enabled = ( styleElem.attribute( u
"enabled"_s, u
"0"_s ) !=
"0"_L1 );
80 elem.setAttribute( u
"cellMargin"_s, QString::number(
mCellMargin ) );
81 elem.setAttribute( u
"emptyTableMode"_s, QString::number(
static_cast< int >(
mEmptyTableMode ) ) );
85 QDomElement headerElem = doc.createElement( u
"headerTextFormat"_s );
87 headerElem.appendChild( headerTextElem );
88 elem.appendChild( headerElem );
89 elem.setAttribute( u
"headerHAlignment"_s, QString::number(
static_cast< int >(
mHeaderHAlignment ) ) );
90 elem.setAttribute( u
"headerMode"_s, QString::number(
static_cast< int >(
mHeaderMode ) ) );
92 QDomElement contentElem = doc.createElement( u
"contentTextFormat"_s );
94 contentElem.appendChild( contentTextElem );
95 elem.appendChild( contentElem );
96 elem.setAttribute( u
"gridStrokeWidth"_s, QString::number(
mGridStrokeWidth ) );
100 elem.setAttribute( u
"showGrid"_s,
mShowGrid );
102 elem.setAttribute( u
"wrapBehavior"_s, QString::number(
static_cast< int >(
mWrapBehavior ) ) );
105 QDomElement displayColumnsElem = doc.createElement( u
"displayColumns"_s );
108 QDomElement columnElem = doc.createElement( u
"column"_s );
109 column.writeXml( columnElem, doc );
110 displayColumnsElem.appendChild( columnElem );
112 elem.appendChild( displayColumnsElem );
114 QDomElement sortColumnsElem = doc.createElement( u
"sortColumns"_s );
117 QDomElement columnElem = doc.createElement( u
"column"_s );
118 column.writeXml( columnElem, doc );
119 sortColumnsElem.appendChild( columnElem );
121 elem.appendChild( sortColumnsElem );
125 QDomElement stylesElem = doc.createElement( u
"cellStyles"_s );
126 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
127 for ( ; it != mCellStyleNames.constEnd(); ++it )
129 QString styleName = it.value();
130 QDomElement styleElem = doc.createElement( styleName );
135 stylesElem.appendChild( styleElem );
138 elem.appendChild( stylesElem );
145 mEmptyTableMessage = itemElem.attribute( u
"emptyTableMessage"_s, tr(
"No matching records" ) );
146 mShowEmptyRows = itemElem.attribute( u
"showEmptyRows"_s, u
"0"_s ).toInt();
148 const QDomElement
headerTextFormat = itemElem.firstChildElement( u
"headerTextFormat"_s );
151 QDomNodeList textFormatNodeList =
headerTextFormat.elementsByTagName( u
"text-style"_s );
152 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
160 headerFont.fromString( itemElem.attribute( u
"headerFont"_s, QString() ) );
180 const QDomElement
contentTextFormat = itemElem.firstChildElement( u
"contentTextFormat"_s );
183 QDomNodeList textFormatNodeList =
contentTextFormat.elementsByTagName( u
"text-style"_s );
184 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
192 contentFont.fromString( itemElem.attribute( u
"contentFont"_s, QString() ) );
209 mCellMargin = itemElem.attribute( u
"cellMargin"_s, u
"1.0"_s ).toDouble();
210 mGridStrokeWidth = itemElem.attribute( u
"gridStrokeWidth"_s, u
"0.5"_s ).toDouble();
211 mHorizontalGrid = itemElem.attribute( u
"horizontalGrid"_s, u
"1"_s ).toInt();
212 mVerticalGrid = itemElem.attribute( u
"verticalGrid"_s, u
"1"_s ).toInt();
213 mShowGrid = itemElem.attribute( u
"showGrid"_s, u
"1"_s ).toInt();
220 QDomNodeList columnsList = itemElem.elementsByTagName( u
"displayColumns"_s );
221 if ( !columnsList.isEmpty() )
223 QDomElement columnsElem = columnsList.at( 0 ).toElement();
224 QDomNodeList columnEntryList = columnsElem.elementsByTagName( u
"column"_s );
225 for (
int i = 0; i < columnEntryList.size(); ++i )
227 QDomElement columnElem = columnEntryList.at( i ).toElement();
235 QDomNodeList sortColumnsList = itemElem.elementsByTagName( u
"sortColumns"_s );
236 if ( !sortColumnsList.isEmpty() )
238 QDomElement columnsElem = sortColumnsList.at( 0 ).toElement();
239 QDomNodeList columnEntryList = columnsElem.elementsByTagName( u
"column"_s );
240 for (
int i = 0; i < columnEntryList.size(); ++i )
242 QDomElement columnElem = columnEntryList.at( i ).toElement();
259 QDomNodeList stylesList = itemElem.elementsByTagName( u
"cellStyles"_s );
260 if ( !stylesList.isEmpty() )
262 QDomElement stylesElem = stylesList.at( 0 ).toElement();
264 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
265 for ( ; it != mCellStyleNames.constEnd(); ++it )
267 QString styleName = it.value();
268 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
269 if ( !styleList.isEmpty() )
271 QDomElement styleElem = styleList.at( 0 ).toElement();
297 double headerHeight = 0;
309 double contentHeight = frameHeight - headerHeight;
313 int currentRow = firstRow;
314 while ( contentHeight > 0 && currentRow <=
mTableContents.count() )
317 contentHeight -= currentRowHeight;
321 if ( includeEmptyRows && contentHeight > 0 )
325 currentRow += std::max( std::floor( contentHeight / rowHeight ), 0.0 );
328 return currentRow - firstRow - 1;
340 bool includeHeader =
false;
344 includeHeader =
true;
346 return rowsVisible( context, frameExtent.height(), firstRow, includeHeader, includeEmptyRows );
355 return qMakePair( 0, 0 );
360 int rowsAlreadyShown = 0;
363 rowsAlreadyShown +=
rowsVisible( context, idx, rowsAlreadyShown,
false );
367 int firstVisible = std::min( rowsAlreadyShown,
static_cast<int>(
mTableContents.length() ) );
369 int lastVisible = std::min( firstVisible + possibleRowsVisible,
static_cast<int>(
mTableContents.length() ) );
371 return qMakePair( firstVisible, lastVisible );
383 if ( !
mLayout->renderContext().isPreviewRender() )
408 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
409 int numberEmptyRows = 0;
413 numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
415 bool mergeCells =
false;
430 p->setPen( Qt::SolidLine );
432 double currentX = gridSizeX;
433 double currentY = gridSizeY;
440 auto headerCellScope = std::make_unique< QgsExpressionContextScope >();
441 headerCellScope->setVariable( u
"column_number"_s, col + 1,
true );
447 p->setPen( Qt::NoPen );
476 const QStringList str = column.heading().split(
'\n' );
492 currentX += gridSizeX;
496 currentY += cellHeaderHeight;
497 currentY += gridSizeY;
502 std::set< std::pair< int, int > > spannedCells;
506 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
509 currentX = gridSizeX;
516 bool isSpanned =
false;
519 double cellHeight = 0;
520 double cellWidth = 0;
521 const int rowsSpan =
rowSpan( row, col );
523 if ( spannedCells.find( std::make_pair( row, col ) ) != spannedCells.end() )
529 for (
int spannedRow = row; spannedRow < row + rowsSpan; ++spannedRow )
532 + ( spannedRow > row ? gridSizeY : 0 );
533 for (
int spannedCol = col; spannedCol < col + colsSpan; ++spannedCol )
535 spannedCells.insert( std::make_pair( spannedRow, spannedCol ) );
538 for (
int spannedCol = col; spannedCol < col + colsSpan; ++spannedCol )
541 + ( spannedCol > col ? gridSizeX : 0 );
545 fullCell = QRectF( currentX, currentY, cellWidth, cellHeight );
551 p->setPen( Qt::NoPen );
553 p->drawRect( fullCell );
563 const QString localizedString { QgsExpressionUtils::toLocalizedString( cellContents ) };
564 const QStringList str = localizedString.split(
'\n' );
571 p->setClipRect( fullCell );
575 QColor foreColor = cellFormat.
color();
597 currentX += gridSizeX;
601 currentY += gridSizeY;
605 if ( numberRowsToDraw > rowsDrawn )
608 p->setPen( Qt::NoPen );
611 for (
int row = rowsDrawn; row < numberRowsToDraw; ++row )
613 currentX = gridSizeX;
619 p->drawRect( QRectF( gridSizeX, currentY,
mTableSize.width() - 2 * gridSizeX, cellBodyHeightForEmptyRows ) );
635 currentX += gridSizeX;
639 currentY += cellBodyHeightForEmptyRows + gridSizeY;
650 gridPen.setJoinStyle( Qt::MiterJoin );
651 gridPen.setCapStyle( Qt::FlatCap );
652 p->setPen( gridPen );
667 double messageY = gridSizeY + ( drawHeader ? cellHeaderHeight + gridSizeY : 0 );
668 cell = QRectF( messageX, messageY,
mTableSize.width() - messageX, cellBodyHeightForEmptyRows );
744 if ( font.pointSizeF() > 0 )
749 else if ( font.pixelSize() > 0 )
828 if ( font.pointSizeF() > 0 )
833 else if ( font.pixelSize() > 0 )
988 if ( !newSortColumns.isEmpty() )
1019 QMap<int, QString> headers;
1024 headers.insert( i, col.heading() );
1032 auto cellScope = std::make_unique< QgsExpressionContextScope >();
1033 cellScope->setVariable( u
"row_number"_s, row + 1,
true );
1034 cellScope->setVariable( u
"column_number"_s, column + 1,
true );
1035 return cellScope.release();
1069 for (
int col = 0; col <
mColumns.size(); ++ col )
1074 return QSizeF( 0, height );
1096void QgsLayoutTable::initStyles()
1108 mCellStyleNames.insert(
OddColumns, u
"oddColumns"_s );
1109 mCellStyleNames.insert(
EvenColumns, u
"evenColumns"_s );
1110 mCellStyleNames.insert(
OddRows, u
"oddRows"_s );
1111 mCellStyleNames.insert(
EvenRows, u
"evenRows"_s );
1112 mCellStyleNames.insert(
FirstColumn, u
"firstColumn"_s );
1113 mCellStyleNames.insert(
LastColumn, u
"lastColumn"_s );
1114 mCellStyleNames.insert(
HeaderRow, u
"headerRow"_s );
1115 mCellStyleNames.insert(
FirstRow, u
"firstRow"_s );
1116 mCellStyleNames.insert(
LastRow, u
"lastRow"_s );
1126 QVector< double > widths( cells );
1128 double currentCellTextWidth;
1137 if ( col.width() > 0 )
1140 widths[i] = col.width();
1144 auto headerCellScope = std::make_unique< QgsExpressionContextScope >();
1145 headerCellScope->setVariable( u
"column_number"_s, i + 1,
true );
1149 const QStringList multiLineSplit = col.heading().split(
'\n' );
1151 widths[i] = currentCellTextWidth;
1161 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
1165 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
1167 for ( ; colIt != rowIt->constEnd(); ++colIt )
1169 if (
mColumns.at( col ).width() <= 0 )
1172 const QStringList multiLineSplit = QgsExpressionUtils::toLocalizedString( *colIt ).split(
'\n' );
1179 widths[ row * cols + col ] = currentCellTextWidth;
1183 widths[ row * cols + col ] = 0;
1192 for (
int col = 0; col < cols; ++col )
1194 double maxColWidth = 0;
1197 maxColWidth = std::max( widths[ row * cols + col ], maxColWidth );
1212 QVector< double > heights( cells );
1221 auto headerCellScope = std::make_unique< QgsExpressionContextScope >();
1222 headerCellScope->setVariable( u
"column_number"_s, i + 1,
true );
1248 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
1252 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
1254 for ( ; colIt != rowIt->constEnd(); ++colIt )
1260 const QString localizedString { QgsExpressionUtils::toLocalizedString( *colIt ) };
1264 QStringList() << localizedString.split(
'\n' ),
1279 double maxRowHeight = 0;
1280 for (
int col = 0; col < cols; ++col )
1282 maxRowHeight = std::max( heights[ row * cols + col ], maxRowHeight );
1326 int rowsAlreadyShown = 0;
1328 int rowsVisibleInLastFrame = 0;
1329 double heightOfLastFrame = 0;
1330 for (
int idx = 0; idx < numberExistingFrames; ++idx )
1334 heightOfLastFrame =
frame( idx )->rect().height();
1335 rowsVisibleInLastFrame =
rowsVisible( context, heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1336 rowsAlreadyShown += rowsVisibleInLastFrame;
1337 height += heightOfLastFrame;
1348 if ( remainingRows <= 0 )
1364 int numberFramesMissing = 0;
1365 while ( remainingRows > 0 )
1367 numberFramesMissing++;
1369 rowsVisibleInLastFrame =
rowsVisible( context, heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1370 if ( rowsVisibleInLastFrame < 1 )
1377 rowsAlreadyShown += rowsVisibleInLastFrame;
1383 height += heightOfLastFrame * numberFramesMissing;
1390 if ( lastRow - firstRow < 1 && !drawHeaderLines )
1399 double currentY = halfGridStrokeWidth;
1400 if ( drawHeaderLines )
1402 painter->drawLine( QPointF( 0, currentY ), QPointF(
mTableSize.width(), currentY ) );
1407 QHash< QPair< int, int >,
bool > skippedCellBottomBorders;
1408 for (
int row = 0; row < lastRow; ++row )
1410 for (
int col = 0; col <
mColumns.size(); ++col )
1412 if ( skippedCellBottomBorders.constFind( qMakePair( row, col ) ) != skippedCellBottomBorders.constEnd() )
1415 const int rowsSpan =
rowSpan( row, col );
1417 skippedCellBottomBorders.insert( qMakePair( row, col ), rowsSpan > 1 );
1418 for (
int rowDelta = 0; rowDelta < rowsSpan - 1; ++rowDelta )
1420 for (
int colDelta = 0; colDelta < colsSpan; ++colDelta )
1422 if ( rowDelta != 0 || colDelta != 0 )
1423 skippedCellBottomBorders.insert( qMakePair( row + rowDelta, col + colDelta ),
true );
1429 for (
int row = firstRow; row < lastRow; ++row )
1432 double endX = startX;
1434 for (
int col = 0; col <
mColumns.size(); ++col )
1438 if ( skippedCellBottomBorders.value( qMakePair( row - 1, col ) ) )
1443 painter->drawLine( QPointF( startX, currentY ), QPointF( endX, currentY ) );
1459 painter->drawLine( QPointF( startX, currentY ), QPointF( endX, currentY ) );
1466 painter->drawLine( QPointF( 0, currentY ), QPointF(
mTableSize.width(), currentY ) );
1473 if ( style->enabled && column % 2 == 0 )
1474 color = style->cellBackgroundColor;
1476 if ( style->enabled && column % 2 == 1 )
1477 color = style->cellBackgroundColor;
1479 if ( style->enabled && row % 2 == 0 )
1480 color = style->cellBackgroundColor;
1482 if ( style->enabled && row % 2 == 1 )
1483 color = style->cellBackgroundColor;
1485 if ( style->enabled && column == 0 )
1486 color = style->cellBackgroundColor;
1489 color = style->cellBackgroundColor;
1491 if ( style->enabled && row == -1 )
1492 color = style->cellBackgroundColor;
1494 if ( style->enabled && row == 0 )
1495 color = style->cellBackgroundColor;
1498 color = style->cellBackgroundColor;
1513 if ( lastRow - firstRow < 1 && !hasHeader )
1518 QHash< QPair< int, int >,
bool > skippedCellRightBorders;
1519 for (
int row = 0; row < lastRow; ++row )
1521 for (
int col = 0; col <
mColumns.size(); ++col )
1523 if ( skippedCellRightBorders.constFind( qMakePair( row, col ) ) != skippedCellRightBorders.constEnd() )
1526 const int rowsSpan =
rowSpan( row, col );
1528 skippedCellRightBorders.insert( qMakePair( row, col ), colsSpan > 1 );
1530 for (
int colDelta = 0; colDelta < colsSpan - 1; ++colDelta )
1532 for (
int rowDelta = 0; rowDelta < rowsSpan; ++rowDelta )
1534 if ( rowDelta != 0 || colDelta != 0 )
1535 skippedCellRightBorders.insert( qMakePair( row + rowDelta, col + colDelta ),
true );
1544 double tableHeight = 0;
1545 QList< double > rowHeights;
1556 double headerHeight = tableHeight;
1559 for (
int row = firstRow; row < lastRow; ++row )
1568 painter->drawLine( QPointF( currentX, 0 ), QPointF( currentX, tableHeight ) );
1570 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
1572 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
1574 currentX += ( maxColWidthIt.value() + 2 *
mCellMargin );
1575 if ( col == maxWidthMap.size() )
1578 painter->drawLine( QPointF( currentX, 0 ), QPointF( currentX, tableHeight ) );
1586 for (
int row = firstRow; row < lastRow; ++row )
1588 const double rowHeight = rowHeights.value( row - firstRow + 1 );
1589 if ( skippedCellRightBorders.value( qMakePair( row, col - 1 ) ) )
1594 painter->drawLine( QPointF( currentX, startY ), QPointF( currentX, endY ) );
1610 painter->drawLine( QPointF( currentX, startY ), QPointF( currentX, endY ) );
1613 else if ( hasHeader )
1615 painter->drawLine( QPointF( currentX, 0 ), QPointF( currentX, headerHeight ) );
1635 return (
contents.indexOf( row ) >= 0 );
1650 return mColumns.value( column ).hAlignment();
1655 return mColumns.value( column ).vAlignment();
@ Rectangle
Text within rectangle layout mode.
QFlags< TextRendererFlag > TextRendererFlags
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ ApplyScalingWorkaroundForTextRendering
Whether a scaling workaround designed to stablise the rendering of small font sizes (or for painters ...
@ VerticalCenter
Center align.
TextHorizontalAlignment
Text horizontal alignment.
@ WrapLines
Automatically wrap long lines of text.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
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.
int frameCount() const
Returns the number of frames associated with this multiframe.
QgsLayoutMultiFrame(QgsLayout *layout)
Construct a new multiframe item, attached to the specified layout.
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.
const QgsLayout * layout() const
Returns the layout the object is attached to.
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.
virtual int rowSpan(int row, int column) const
Returns the row span for the cell a row, column.
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.
virtual int columnSpan(int row, int column) const
Returns the column span for the cell a row, column.
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.
A container for the context for various read/write operations on 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.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
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.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void updateDataDefinedProperties(QgsRenderContext &context)
Updates the format by evaluating current values of data defined properties.
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 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(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
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 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.
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).