KD Reports API Documentation  2.2
KDReportsReportBuilder_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Reports library.
4 **
5 ** SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #ifndef KDREPORTSREPORTBUILDER_H
12 #define KDREPORTSREPORTBUILDER_H
13 
15 #include "KDReportsVariableType.h"
16 #include <QTextCursor>
17 
18 QT_BEGIN_NAMESPACE
19 class QTextDocument;
20 QT_END_NAMESPACE
21 
22 namespace KDReports {
23 class Element;
24 class Report;
25 class TextDocument;
26 class TextDocumentData;
27 
28 #define REPORTBUILDER_CTOR_ARGDEFS KDReports::TextDocumentData &contentDocument, const QTextCursor &cursor, KDReports::Report *report
29 
30 #define REPORTBUILDER_CTOR_ARGNAMES contentDocument, cursor, report
31 
36 {
37 
38 public:
39  ReportBuilder(KDReports::TextDocumentData &contentDocument, const QTextCursor &cursor, Report *report);
40  virtual ~ReportBuilder()
41  {
42  }
43 
44  QTextCursor &cursor()
45  {
46  m_contentDocument.aboutToModifyContents(TextDocumentData::Append);
47  return m_cursor;
48  }
50  {
51  return m_report;
52  }
53 
54  // Warning, changes to those virtual methods must be propagated to CellReportBuilder.
55  virtual void addPageBreakPublic();
56  virtual void addInlineElementPublic(const Element &element);
57  virtual void addBlockElementPublic(const Element &element, Qt::AlignmentFlag horizontalAlignment, const QColor &backgroundColor = QColor());
59  virtual void addVerticalSpacingPublic(qreal space);
60  virtual void insertFragmentPublic(const QTextDocumentFragment &fragment);
61 
62  // Warning, changes to those virtual methods must be propagated to CellReportBuilder and HeaderReportBuilder.
63  virtual void addInlineElement(const Element &element);
64  virtual void addBlockElement(const Element &element, Qt::AlignmentFlag horizontalAlignment, const QColor &backgroundColor = QColor());
65  virtual void addVariable(KDReports::VariableType variable);
66  virtual void addVerticalSpacing(qreal space);
67 
69  {
70  return m_contentDocument;
71  }
72 
73  QTextDocument &currentDocument()
74  {
75  return currentDocumentData().document();
76  }
77 
78  // Store default font in builder, so that toplevel text elements use the report's default font
79  // but table cells use the table's default font (if any)
80  void setDefaultFont(const QFont &font)
81  {
82  m_defaultFont = font;
83  }
84 
85  QFont defaultFont() const
86  {
87  return m_defaultFont;
88  }
89 
90  // should not be used directly, apart for creating another builder (e.g. cell builder)
92  {
93  return m_contentDocument;
94  }
95  QTextCursor &contentDocumentCursor()
96  {
97  return m_cursor;
98  }
99 
100  void setupBlockFormat(QTextBlockFormat &blockFormat) const;
101 
102  void setTabPositions(const QList<QTextOption::Tab> &tabs); // in mm
103  // const QList<QTextOption::Tab>& tabPositions() const { return m_tabPositions; }
104  void setParagraphMargins(qreal left, qreal top, qreal right, qreal bottom); // in mm
105  void copyStateFrom(const ReportBuilder &parentBuilder);
106  int currentPosition();
107 
108  static QTextCharFormat::VerticalAlignment toVerticalAlignment(Qt::Alignment alignment);
109 
110 private:
111  ReportBuilder(const ReportBuilder &other) = delete;
112  ReportBuilder &operator=(const ReportBuilder &other) = delete;
113 
114  KDReports::TextDocumentData &m_contentDocument;
115  QTextCursor m_cursor;
116  QTextCursor m_layoutDocCursor;
117  QList<QTextOption::Tab> m_tabPositions;
118  qreal m_leftMargin = 0;
119  qreal m_rightMargin = 0;
120  qreal m_topMargin = 0;
121  qreal m_bottomMargin = 0;
122  Report *m_report;
123  QFont m_defaultFont;
124  bool m_first = true;
125 };
126 }
127 
128 QDebug operator<<(QDebug &dbg, const QTextOption::Tab &tab);
129 
130 #endif /* KDREPORTSREPORTBUILDER_H */
#define KDREPORTS_EXPORT
QDebug operator<<(QDebug &dbg, const QTextOption::Tab &tab)
ReportBuilder(KDReports::TextDocumentData &contentDocument, const QTextCursor &cursor, Report *report)
void setDefaultFont(const QFont &font)
virtual void addVerticalSpacingPublic(qreal space)
TextDocumentData & currentDocumentData()
virtual void addBlockElementPublic(const Element &element, Qt::AlignmentFlag horizontalAlignment, const QColor &backgroundColor=QColor())
TextDocumentData & contentDocumentData()
virtual void addVariablePublic(KDReports::VariableType variable)
virtual void addInlineElementPublic(const Element &element)
void setParagraphMargins(qreal left, qreal top, qreal right, qreal bottom)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-reports/
Generated by doxygen 1.9.1