21 : m_contentDocument(contentDocument)
31 cursor.beginEditBlock();
36 const QTextCharFormat origCharFormat =
cursor.charFormat();
38 cursor.setCharFormat(origCharFormat);
44 QTextCursor &cursor = this->cursor();
45 cursor.beginEditBlock();
54 QTextCharFormat charFormat = cursor.charFormat();
55 charFormat.setFont(m_defaultFont);
56 cursor.setCharFormat(charFormat);
58 QTextBlockFormat blockFormat;
59 blockFormat.setAlignment(horizontalAlignment);
60 setupBlockFormat(blockFormat);
62 if (backgroundColor.isValid())
63 blockFormat.setBackground(backgroundColor);
65 cursor.setBlockFormat(blockFormat);
69 cursor.setCharFormat(charFormat);
70 cursor.endEditBlock();
73 if (!m_tabPositions.isEmpty()) {
74 QTextBlock block = cursor.document()->firstBlock();
76 qDebug() <<
"addBlock: Looking at block" << block.blockNumber() <<
"tabs:" << block.blockFormat().tabPositions().count();
78 }
while ( block.isValid() );
85 QTextCursor &cursor = this->cursor();
86 const int charPosition = cursor.position();
92 const QTextCharFormat origCharFormat = cursor.charFormat();
95 QTextCursor docCursor(¤tDocument());
96 docCursor.setPosition(charPosition);
97 cursor.setCharFormat(docCursor.charFormat());
99 cursor.beginEditBlock();
100 element.
build(*
this);
101 cursor.endEditBlock();
105 cursor.setCharFormat(origCharFormat);
110 QTextCursor &cursor = this->cursor();
111 cursor.beginEditBlock();
114 cursor.insertBlock();
119 QTextBlockFormat blockFormat;
122 cursor.setBlockFormat(blockFormat);
123 QTextCharFormat charFormat;
124 charFormat.setFontPointSize(1);
125 cursor.setCharFormat(charFormat);
126 cursor.insertText(QStringLiteral(
" "));
127 cursor.endEditBlock();
133 addInlineElement(element);
138 addBlockElement(element, horizontalAlignment, backgroundColor);
143 addVariable(variable);
148 addVerticalSpacing(space);
154 QTextBlockFormat blockFormat = m_cursor.blockFormat();
155 blockFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
156 m_cursor.setBlockFormat(blockFormat);
161 m_cursor.insertFragment(fragment);
166 m_tabPositions = tabs;
167 for (QTextOption::Tab &tab : m_tabPositions) {
170 m_contentDocument.setUsesTabPositions(
true);
175 m_tabPositions = parentBuilder.m_tabPositions;
176 m_leftMargin = parentBuilder.m_leftMargin;
177 m_rightMargin = parentBuilder.m_rightMargin;
178 m_topMargin = parentBuilder.m_topMargin;
179 m_bottomMargin = parentBuilder.m_bottomMargin;
180 m_defaultFont = parentBuilder.m_defaultFont;
185 static const char *types[] = {
"LeftTab",
"RightTab",
"CenterTab",
"DelimiterTab"};
186 dbg.space() <<
'(' << types[tab.type] << tab.position <<
"px" <<
')';
202 blockFormat.setTabPositions(m_tabPositions);
203 blockFormat.setLeftMargin(m_leftMargin);
204 blockFormat.setRightMargin(m_rightMargin);
205 blockFormat.setTopMargin(m_topMargin);
206 blockFormat.setBottomMargin(m_bottomMargin);
211 return m_cursor.position();
216 switch (alignment & Qt::AlignVertical_Mask) {
218 return QTextCharFormat::AlignTop;
219 case Qt::AlignBottom:
220 return QTextCharFormat::AlignBottom;
221 case Qt::AlignVCenter:
222 return QTextCharFormat::AlignMiddle;
223 case Qt::AlignBaseline:
224 return QTextCharFormat::AlignBaseline;
226 return QTextCharFormat::AlignNormal;
QDebug operator<<(QDebug &dbg, QTextOption::Tab tab)
virtual void build(ReportBuilder &) const =0
ReportBuilder(KDReports::TextDocumentData &contentDocument, const QTextCursor &cursor, Report *report)
void setTabPositions(const QList< QTextOption::Tab > &tabs)
virtual void insertFragmentPublic(const QTextDocumentFragment &fragment)
virtual void addVerticalSpacingPublic(qreal space)
virtual void addPageBreakPublic()
virtual void addBlockElementPublic(const Element &element, Qt::AlignmentFlag horizontalAlignment, const QColor &backgroundColor=QColor())
virtual void addVariablePublic(KDReports::VariableType variable)
virtual void addVerticalSpacing(qreal space)
static QTextCharFormat::VerticalAlignment toVerticalAlignment(Qt::Alignment alignment)
virtual void addInlineElementPublic(const Element &element)
void setupBlockFormat(QTextBlockFormat &blockFormat) const
virtual void addBlockElement(const Element &element, Qt::AlignmentFlag horizontalAlignment, const QColor &backgroundColor=QColor())
void setParagraphMargins(qreal left, qreal top, qreal right, qreal bottom)
virtual void addVariable(KDReports::VariableType variable)
virtual void addInlineElement(const Element &element)
void copyStateFrom(const ReportBuilder &parentBuilder)
void build(ReportBuilder &builder) const override
QString variableValue(int pageNumber, KDReports::Report *report, VariableType type)
KDREPORTS_EXPORT qreal mmToPixels(qreal mm)
void setVariableMarker(QTextDocument &textDoc, int pos, KDReports::VariableType variableType, int valueLength)