14 #include <QTextCursor>
15 #include <QTextTableFormat>
17 class KDReports::AbstractTableElementPrivate
20 void fillConstraints(QTextTableFormat *tableFormat)
const;
23 QBrush m_borderBrush = QBrush(Qt::darkGray );
24 qreal m_padding = 0.5;
28 bool m_fontSpecified =
false;
29 QVector<KDReports::AbstractTableElement::ColumnConstraint> m_constraints;
34 , d(new AbstractTableElementPrivate)
40 , d(new AbstractTableElementPrivate(*other.d))
55 d->m_constraints = constraints;
74 d->m_borderBrush = brush;
79 return d->m_borderBrush;
84 d->m_padding = padding;
110 d->m_defaultFont = font;
111 d->m_fontSpecified =
true;
116 *isSet = d->m_fontSpecified;
117 return d->m_defaultFont;
120 void KDReports::AbstractTableElementPrivate::fillConstraints(QTextTableFormat *tableFormat)
const
122 if (!m_constraints.isEmpty()) {
123 QVector<QTextLength> constraints;
124 constraints.reserve(m_constraints.size());
125 for (
const auto &c : m_constraints) {
129 length = QTextLength(QTextLength::FixedLength,
mmToPixels(c.width));
132 length = QTextLength(QTextLength::PercentageLength, c.width);
135 constraints.append(length);
137 tableFormat->setColumnWidthConstraints(constraints);
145 tableFormat.setWidth(QTextLength(QTextLength::FixedLength,
mmToPixels(d->m_width)));
147 tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, d->m_width));
151 d->fillConstraints(&tableFormat);
153 tableFormat.setBorder(border());
154 tableFormat.setBorderBrush(borderBrush());
155 tableFormat.setCellPadding(
mmToPixels(padding()));
156 tableFormat.setCellSpacing(0);
157 if (d->m_fontSpecified) {
158 QTextCharFormat charFormat = textDocCursor.charFormat();
159 charFormat.setFont(d->m_defaultFont);
160 textDocCursor.setCharFormat(charFormat);
~AbstractTableElement() override
void setPadding(qreal padding)
void setBorderBrush(const QBrush &brush)
void setDefaultFont(const QFont &font)
void setColumnConstraints(const QVector< ColumnConstraint > &constraints)
QFont defaultFont(bool *isSet) const
void setBorder(qreal border)
AbstractTableElement & operator=(const AbstractTableElement &other)
void fillTableFormat(QTextTableFormat &tableFormat, QTextCursor &textDocCursor) const
QBrush borderBrush() const
void setWidth(qreal width, Unit unit=Millimeters)
Element & operator=(const Element &other)
@ Percent
Percentage of the text width, i.e. the page width minus margins.
@ Millimeters
Millimeters (the default)
KDREPORTS_EXPORT qreal mmToPixels(qreal mm)