36 styleElem.setAttribute( QStringLiteral(
"enabled" ),
enabled );
43 enabled = ( styleElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
57 QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
58 if ( !defaultFontString.isEmpty() )
78 elem.setAttribute( QStringLiteral(
"cellMargin" ), QString::number(
mCellMargin ) );
79 elem.setAttribute( QStringLiteral(
"emptyTableMode" ), QString::number( static_cast< int >(
mEmptyTableMode ) ) );
81 elem.setAttribute( QStringLiteral(
"showEmptyRows" ),
mShowEmptyRows );
84 elem.setAttribute( QStringLiteral(
"headerHAlignment" ), QString::number( static_cast< int >(
mHeaderHAlignment ) ) );
85 elem.setAttribute( QStringLiteral(
"headerMode" ), QString::number( static_cast< int >(
mHeaderMode ) ) );
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 );
107 QDomElement stylesElem = doc.createElement( QStringLiteral(
"cellStyles" ) );
108 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
109 for ( ; it != mCellStyleNames.constEnd(); ++it )
111 QString styleName = it.value();
112 QDomElement styleElem = doc.createElement( styleName );
117 stylesElem.appendChild( styleElem );
120 elem.appendChild( stylesElem );
127 mEmptyTableMessage = itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), tr(
"No matching records" ) );
128 mShowEmptyRows = itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt();
131 mHeaderFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
138 mContentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
141 mCellMargin = itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble();
142 mGridStrokeWidth = itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble();
143 mHorizontalGrid = itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt();
144 mVerticalGrid = itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt();
145 mShowGrid = itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt();
153 QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
154 if ( !columnsList.isEmpty() )
156 QDomElement columnsElem = columnsList.at( 0 ).toElement();
157 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
158 for (
int i = 0; i < columnEntryList.size(); ++i )
160 QDomElement columnElem = columnEntryList.at( i ).toElement();
168 QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
169 if ( !stylesList.isEmpty() )
171 QDomElement stylesElem = stylesList.at( 0 ).toElement();
173 QMap< CellStyleGroup, QString >::const_iterator it = mCellStyleNames.constBegin();
174 for ( ; it != mCellStyleNames.constEnd(); ++it )
176 QString styleName = it.value();
177 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
178 if ( !styleList.isEmpty() )
180 QDomElement styleElem = styleList.at( 0 ).toElement();
206 double headerHeight = 0;
219 double contentHeight = frameHeight - headerHeight;
223 int currentRow = firstRow;
224 while ( contentHeight > 0 && currentRow <=
mTableContents.count() )
227 contentHeight -= currentRowHeight;
231 if ( includeEmptyRows && contentHeight > 0 )
234 currentRow += std::max( std::floor( contentHeight / rowHeight ), 0.0 );
237 return currentRow - firstRow - 1;
247 QRectF frameExtent =
frame( frameIndex )->
extent();
249 bool includeHeader =
false;
253 includeHeader =
true;
255 return rowsVisible( frameExtent.height(), firstRow, includeHeader, includeEmptyRows );
264 return qMakePair( 0, 0 );
269 int rowsAlreadyShown = 0;
272 rowsAlreadyShown +=
rowsVisible( idx, rowsAlreadyShown,
false );
276 int firstVisible = std::min( rowsAlreadyShown,
mTableContents.length() );
277 int possibleRowsVisible =
rowsVisible( frameIndex, rowsAlreadyShown,
false );
278 int lastVisible = std::min( firstVisible + possibleRowsVisible,
mTableContents.length() );
280 return qMakePair( firstVisible, lastVisible );
292 if ( !
mLayout->renderContext().isPreviewRender() )
300 QPair< int, int > rowsToShow =
rowRange( frameIndex );
314 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
315 int numberEmptyRows = 0;
318 numberRowsToDraw =
rowsVisible( frameIndex, rowsToShow.first,
true );
319 numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
321 bool mergeCells =
false;
336 p->setPen( Qt::SolidLine );
338 double currentX = gridSizeX;
339 double currentY = gridSizeY;
348 p->setPen( Qt::NoPen );
355 Qt::TextFlag textFlag =
static_cast< Qt::TextFlag
>( 0 );
356 if ( column->width() <= 0 )
361 textFlag = Qt::TextDontClip;
367 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
371 headerAlign = column->hAlignment();
374 headerAlign = Qt::AlignLeft;
377 headerAlign = Qt::AlignHCenter;
380 headerAlign = Qt::AlignRight;
388 currentX += gridSizeX;
392 currentY += cellHeaderHeight;
393 currentY += gridSizeY;
401 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
404 currentX = gridSizeX;
413 const QRectF fullCell( currentX, currentY,
mMaxColumnWidthMap[col] + 2 * mCellMargin, rowHeight );
416 p->setPen( Qt::NoPen );
418 p->drawRect( fullCell );
425 QString str = cellContents.toString();
429 Qt::TextFlag textFlag =
static_cast< Qt::TextFlag
>( Qt::TextDontClip );
432 str = wrappedText( str, column->width(),
mContentFont );
436 p->setClipRect( fullCell );
437 const QRectF textCell = QRectF( currentX, currentY + mCellMargin,
mMaxColumnWidthMap[col], rowHeight - 2 * mCellMargin );
449 currentX += gridSizeX;
452 currentY += rowHeight;
453 currentY += gridSizeY;
457 if ( numberRowsToDraw > rowsDrawn )
460 p->setPen( Qt::NoPen );
463 for (
int row = rowsDrawn; row < numberRowsToDraw; ++row )
465 currentX = gridSizeX;
471 p->drawRect( QRectF( gridSizeX, currentY,
mTableSize.width() - 2 * gridSizeX, cellBodyHeight ) );
487 currentX += gridSizeX;
491 currentY += cellBodyHeight + gridSizeY;
502 gridPen.setJoinStyle( Qt::MiterJoin );
503 p->setPen( gridPen );
518 double messageY = gridSizeY + ( drawHeader ? cellHeaderHeight + gridSizeY : 0 );
519 cell = QRectF( messageX, messageY,
mTableSize.width() - messageX, cellBodyHeight );
786 QMap<int, QString> headers;
788 QgsLayoutTableColumns::const_iterator columnIt =
mColumns.constBegin();
790 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
792 headers.insert( col, ( *columnIt )->heading() );
805 Q_UNUSED( frameIndex )
818 return QSizeF( 0, height );
840 void QgsLayoutTable::initStyles()
852 mCellStyleNames.insert(
OddColumns, QStringLiteral(
"oddColumns" ) );
853 mCellStyleNames.insert(
EvenColumns, QStringLiteral(
"evenColumns" ) );
854 mCellStyleNames.insert(
OddRows, QStringLiteral(
"oddRows" ) );
855 mCellStyleNames.insert(
EvenRows, QStringLiteral(
"evenRows" ) );
856 mCellStyleNames.insert(
FirstColumn, QStringLiteral(
"firstColumn" ) );
857 mCellStyleNames.insert(
LastColumn, QStringLiteral(
"lastColumn" ) );
858 mCellStyleNames.insert(
HeaderRow, QStringLiteral(
"headerRow" ) );
859 mCellStyleNames.insert(
FirstRow, QStringLiteral(
"firstRow" ) );
860 mCellStyleNames.insert(
LastRow, QStringLiteral(
"lastRow" ) );
870 QVector< double > widths( cells );
873 QgsLayoutTableColumns::const_iterator columnIt =
mColumns.constBegin();
875 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
877 if ( ( *columnIt )->width() > 0 )
880 widths[col] = ( *columnIt )->width();
894 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
895 double currentCellTextWidth;
899 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
901 for ( ; colIt != rowIt->constEnd(); ++colIt )
903 if (
mColumns.at( col )->width() <= 0 )
906 QStringList multiLineSplit = ( *colIt ).toString().split(
'\n' );
907 currentCellTextWidth = 0;
908 const auto constMultiLineSplit = multiLineSplit;
909 for (
const QString &line : constMultiLineSplit )
913 widths[ row * cols + col ] = currentCellTextWidth;
917 widths[ row * cols + col ] = 0;
926 for (
int col = 0; col < cols; ++col )
928 double maxColWidth = 0;
931 maxColWidth = std::max( widths[ row * cols + col ], maxColWidth );
946 QVector< double > heights( cells );
949 QgsLayoutTableColumns::const_iterator columnIt =
mColumns.constBegin();
951 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
959 QgsLayoutTableContents::const_iterator rowIt =
mTableContents.constBegin();
963 QgsLayoutTableRow::const_iterator colIt = rowIt->constBegin();
965 for ( ; colIt != rowIt->constEnd(); ++colIt )
985 double maxRowHeight = 0;
986 for (
int col = 0; col < cols; ++col )
988 maxRowHeight = std::max( heights[ row * cols + col ], maxRowHeight );
1009 totalWidth += maxColWidthIt.value();
1029 int rowsAlreadyShown = 0;
1031 int rowsVisibleInLastFrame = 0;
1032 double heightOfLastFrame = 0;
1033 for (
int idx = 0; idx < numberExistingFrames; ++idx )
1037 heightOfLastFrame =
frame( idx )->rect().height();
1038 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1039 rowsAlreadyShown += rowsVisibleInLastFrame;
1040 height += heightOfLastFrame;
1051 if ( remainingRows <= 0 )
1067 int numberFramesMissing = 0;
1068 while ( remainingRows > 0 )
1070 numberFramesMissing++;
1072 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1073 if ( rowsVisibleInLastFrame < 1 )
1080 rowsAlreadyShown += rowsVisibleInLastFrame;
1086 height += heightOfLastFrame * numberFramesMissing;
1093 if ( lastRow - firstRow < 1 && !drawHeaderLines )
1100 double currentY = 0;
1101 currentY = halfGridStrokeWidth;
1102 if ( drawHeaderLines )
1104 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1108 for (
int row = firstRow; row < lastRow; ++row )
1110 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1115 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
1118 bool QgsLayoutTable::textRequiresWrapping(
const QString &text,
double columnWidth,
const QFont &font )
const 1123 QStringList multiLineSplit = text.split(
'\n' );
1124 double currentTextWidth = 0;
1125 const auto constMultiLineSplit = multiLineSplit;
1126 for (
const QString &line : constMultiLineSplit )
1131 return ( currentTextWidth > columnWidth );
1134 QString QgsLayoutTable::wrappedText(
const QString &value,
double columnWidth,
const QFont &font )
const 1136 QStringList lines = value.split(
'\n' );
1137 QStringList outLines;
1138 const auto constLines = lines;
1139 for (
const QString &line : constLines )
1141 if ( textRequiresWrapping( line, columnWidth, font ) )
1144 QStringList words = line.split(
' ' );
1145 QStringList linesToProcess;
1146 QString wordsInCurrentLine;
1147 const auto constWords = words;
1148 for (
const QString &word : constWords )
1150 if ( textRequiresWrapping( word, columnWidth, font ) )
1153 if ( !wordsInCurrentLine.isEmpty() )
1154 linesToProcess << wordsInCurrentLine;
1155 wordsInCurrentLine.clear();
1156 linesToProcess << word;
1160 if ( !wordsInCurrentLine.isEmpty() )
1161 wordsInCurrentLine.append(
' ' );
1162 wordsInCurrentLine.append( word );
1165 if ( !wordsInCurrentLine.isEmpty() )
1166 linesToProcess << wordsInCurrentLine;
1168 const auto constLinesToProcess = linesToProcess;
1169 for (
const QString &line : constLinesToProcess )
1171 QString remainingText = line;
1172 int lastPos = remainingText.lastIndexOf(
' ' );
1173 while ( lastPos > -1 )
1176 if ( !textRequiresWrapping( remainingText, columnWidth, font ) )
1181 if ( !textRequiresWrapping( remainingText.left( lastPos ), columnWidth, font ) )
1183 outLines << remainingText.left( lastPos );
1184 remainingText = remainingText.mid( lastPos + 1 );
1187 lastPos = remainingText.lastIndexOf(
' ', lastPos - 1 );
1189 outLines << remainingText;
1198 return outLines.join( QStringLiteral(
"\n" ) );
1205 if ( style->enabled && column % 2 == 0 )
1206 color = style->cellBackgroundColor;
1208 if ( style->enabled && column % 2 == 1 )
1209 color = style->cellBackgroundColor;
1211 if ( style->enabled && row % 2 == 0 )
1212 color = style->cellBackgroundColor;
1214 if ( style->enabled && row % 2 == 1 )
1215 color = style->cellBackgroundColor;
1217 if ( style->enabled && column == 0 )
1218 color = style->cellBackgroundColor;
1220 if ( style->enabled && column ==
mColumns.count() - 1 )
1221 color = style->cellBackgroundColor;
1223 if ( style->enabled && row == -1 )
1224 color = style->cellBackgroundColor;
1226 if ( style->enabled && row == 0 )
1227 color = style->cellBackgroundColor;
1230 color = style->cellBackgroundColor;
1245 if ( lastRow - firstRow < 1 && !hasHeader )
1251 double tableHeight = 0;
1257 double headerHeight = tableHeight;
1260 for (
int row = firstRow; row < lastRow; ++row )
1267 double currentX = halfGridStrokeWidth;
1268 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1270 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
1272 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
1274 currentX += ( maxColWidthIt.value() + 2 *
mCellMargin );
1275 if ( col == maxWidthMap.size() || !mergeCells )
1277 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1279 else if ( hasHeader )
1281 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
1300 return ( contents.indexOf( row ) >= 0 );
EmptyTableMode
Controls how empty tables are displayed.
The class is used as a container of context for various read/write operations on other objects...
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
void refresh() override
Refreshes the multiframe, causing a recalculation of any property overrides.
void setWrapBehavior(WrapBehavior behavior)
Sets the wrap behavior for the table, which controls how text within cells is automatically wrapped...
virtual bool calculateMaxRowHeights()
Calculates the maximum height of text shown in rows.
QMap< CellStyleGroup, QgsLayoutTableStyle *> mCellStyles
Style odd numbered columns.
~QgsLayoutTable() override
WrapBehavior
Controls how long strings in the table are handled.
static double textWidthMM(const QFont &font, const QString &text)
Calculate a font width in millimeters for a text string, including workarounds for QT font rendering ...
bool horizontalGrid() const
Returns whether the grid's horizontal lines are drawn in the table.
This class is a composition of two QSettings instances:
void setCellMargin(double margin)
Sets the margin distance in mm between cell borders and their contents.
Header uses the same alignment as the column.
QgsLayoutTable(QgsLayout *layout)
Constructor for QgsLayoutTable, belonging to the specified layout.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
int frameIndex(QgsLayoutFrame *frame) const
Returns the index of a frame within the multiframe.
QRectF extent() const
Returns the visible portion of the multi frame's content which is shown in this frame, in layout units.
virtual QMap< int, QString > headerLabels() const
Returns the text used in the column headers for the table.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
void setHeaderFontColor(const QColor &color)
Sets the color used to draw header text in the table.
double mCellMargin
Margin between cell borders and cell text.
Styling option for a layout table cell.
bool writeXml(QDomElement &styleElem, QDomDocument &doc) const
Writes the style's properties to XML for storage.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
QVector< QgsLayoutTableColumn *> QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
void setEmptyTableMessage(const QString &message)
Sets the message for empty tables with no content rows.
WrapBehavior mWrapBehavior
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
QSizeF minFrameSize(int frameIndex=-1) const override
Returns the minimum size for a frames, if desired.
void setVerticalGrid(bool verticalGrid)
Sets whether the grid's vertical lines should be drawn in the table.
Text which doesn't fit inside the cell is truncated.
void setCellStyle(CellStyleGroup group, const QgsLayoutTableStyle &style)
Sets the cell style for a cell group.
Style even numbered columns.
void render(QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex) override
Renders a portion of the multiframe's content into a render context.
QString mEmptyTableMessage
String to show in empty tables.
Shows preset message instead of table contents.
int frameCount() const
Returns the number of frames associated with this multiframe.
Text which doesn't fit inside the cell is wrapped. Note that this only applies to text in columns wit...
void recalculateFrameRects()
Forces a recalculation of all the associated frame's scene rectangles.
const QgsLayoutTableStyle * cellStyle(CellStyleGroup group) const
Returns the cell style for a cell group.
double totalHeight()
Returns total height of table contents.
Creates new full page frames on the following page(s) until the entire multiframe content is visible...
Stores properties of a column for a QgsLayoutTable.
QSizeF fixedFrameSize(int frameIndex=-1) const override
Returns the fixed size for a frame, if desired.
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
QColor mGridColor
Color for grid lines.
static QString encodeColor(const QColor &color)
QSizeF totalSize() const override
Returns the total size of the multiframe's content, in layout units.
bool mShowGrid
True if grid should be shown.
No headers shown for table.
void setHeaderMode(HeaderMode mode)
Sets the display mode for headers in the table.
QColor mContentFontColor
Table contents font color.
Conditional styling for a rule.
bool mVerticalGrid
True if grid should be shown.
QColor mHeaderFontColor
Header font color.
void setHorizontalGrid(bool horizontalGrid)
Sets whether the grid's horizontal lines should be drawn in the table.
void recalculateFrameSizes() override
virtual bool calculateMaxColumnWidths()
Calculates the maximum width of text shown in columns.
void setHeaderHAlignment(HeaderHAlignment alignment)
Sets the horizontal alignment for table headers.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QColor cellBackgroundColor
Cell background color.
void drawVerticalGridLines(QPainter *painter, const QMap< int, double > &maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells=false) const
Draws the vertical grid lines for the table.
QPointer< QgsLayout > mLayout
QColor backgroundColor() const
The background color for style.
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.
QColor mBackgroundColor
Color for table background.
void setContentFontColor(const QColor &color)
Sets the color used to draw text in table body cells.
Header shown on first frame only.
bool mHorizontalGrid
True if grid should be shown.
QFont mHeaderFont
Header font.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setGridStrokeWidth(double width)
Sets the width in mm for grid lines in the table.
virtual bool getTableContents(QgsLayoutTableContents &contents)=0
Fetches the contents used for the cells in the table.
bool mShowEmptyRows
True if empty rows should be shown in the table.
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of its component frames...
static void drawText(QPainter *painter, QPointF position, const QString &text, const QFont &font, const QColor &color=QColor())
Draws text on a painter at a specific position, taking care of layout specific issues (calculation to...
QFont mContentFont
Table contents font.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsLayoutFrame * frame(int index) const
Returns the child frame at a specified index from the multiframe.
virtual QgsConditionalStyle conditionalCellStyle(int row, int column) const
Returns the conditional style to use for the cell at row, column.
double mGridStrokeWidth
Width of grid lines.
bool verticalGrid() const
Returns whether the grid's vertical lines are drawn in the table.
bool showGrid() const
Returns whether grid lines are drawn in the table.
QColor textColor() const
The text color set for style.
QgsLayoutTableColumns mColumns
Columns to show in table.
void setContentFont(const QFont &font)
Sets the font used to draw text in table body cells.
bool readXml(const QDomElement &styleElem)
Reads the style's properties from XML.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
void drawHorizontalGridLines(QPainter *painter, int firstRow, int lastRow, bool drawHeaderLines) const
Draws the horizontal grid lines for the table.
static double fontAscentMM(const QFont &font)
Calculates a font ascent in millimeters, including workarounds for QT font rendering issues...
void update()
Forces a redraw of all child frames.
Headers shown on all frames.
QgsLayoutTableContents mTableContents
Contents to show in table.
void setBackgroundColor(const QColor &color)
Sets the color used for background of table.
QPair< int, int > rowRange(int frameIndex) const
Calculates a range of rows which should be visible in a given frame.
static double textHeightMM(const QFont &font, const QString &text, double multiLineHeight=1.0)
Calculate a font height in millimeters for a text string, including workarounds for QT font rendering...
EmptyTableMode mEmptyTableMode
Behavior for empty tables.
QColor backgroundColor() const
Returns the color used for the background of the table.
double totalWidth()
Returns total width of table contents.
QMap< int, double > mMaxColumnWidthMap
Map of maximum width for each column.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
void setHeaderFont(const QFont &font)
Sets the font used to draw header text in the table.
bool enabled
Whether the styling option is enabled.
HeaderMode
Controls where headers are shown in the table.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
Style even numbered rows.
void setEmptyTableBehavior(EmptyTableMode mode)
Sets the behavior mode for empty tables with no content rows.
QgsLayoutTableColumns & columns()
Returns a reference to the list of QgsLayoutTableColumns shown in the table.
void setShowGrid(bool showGrid)
Sets whether grid lines should be drawn in the table.
void setColumns(const QgsLayoutTableColumns &columns)
Replaces the columns in the table with a specified list of QgsLayoutTableColumns. ...
void changed()
Emitted when the object's properties change.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
double height() const
Returns the height of the size.
CellStyleGroup
Row or column groups for cell styling.
HeaderMode mHeaderMode
Header display mode.
void setGridColor(const QColor &color)
Sets the color used for grid lines in the table.
bool contentsContainsRow(const QgsLayoutTableContents &contents, const QgsLayoutTableRow &row) const
Checks whether a table contents contains a given row.
HeaderHAlignment mHeaderHAlignment
Alignment for table headers.
int rowsVisible(double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows) const
Calculates how many content rows would be visible within a frame of the specified height...
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
void setShowEmptyRows(bool showEmpty)
Sets whether empty rows should be drawn.
static QColor decodeColor(const QString &str)
Hides entire table if empty.
Item representing the paper in a layout.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
QVector< QVariant > QgsLayoutTableRow
List of QVariants, representing a the contents of a single row in a QgsLayoutTable.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.