KD Reports API Documentation 2.2
Loading...
Searching...
No Matches
KDReportsFrame.cpp
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#include "KDReportsFrame.h"
12#include "KDReportsElement.h"
16
17#include <QDebug>
18#include <QTextFrame>
19
20class KDReports::FramePrivate
21{
22public:
23 FramePrivate()
24 : m_width(0)
25 , m_height(0)
26 , m_padding(0.5)
27 , m_border(1.0)
28 , m_widthUnit(KDReports::Millimeters)
29 , m_heightUnit(KDReports::Millimeters)
30 {
31 }
32 ~FramePrivate()
33 {
34 }
36 qreal m_width;
37 qreal m_height;
38 qreal m_padding;
39 qreal m_border;
40 KDReports::Unit m_widthUnit;
41 KDReports::Unit m_heightUnit;
43};
44
46 : d(new FramePrivate)
47{
48}
49
51 : Element(other)
52 , d(new FramePrivate(*other.d))
53{
54}
55
57{
58 if (&other == this)
59 return *this;
60 Element::operator=(other);
61 *d = *other.d;
62 return *this;
63}
64
66{
67 d->m_width = width;
68 d->m_widthUnit = unit;
69}
70
72{
73 d->m_height = height;
74 d->m_heightUnit = unit;
75}
76
78{
79 d->m_padding = padding;
80}
81
83{
84 return d->m_padding;
85}
86
88{
89 d->m_border = border;
90}
91
93{
94 return d->m_border;
95}
96
98{
99 d->m_position = pos;
100}
101
103{
104 return d->m_position;
105}
106
110
112{
113 d->m_elements.append(KDReports::ElementData(element.clone()));
114}
115
116void KDReports::Frame::addElement(const Element &element, Qt::AlignmentFlag horizontalAlignment)
117{
118 d->m_elements.append(KDReports::ElementData(element.clone(), horizontalAlignment));
119}
120
122{
123 d->m_elements.append(KDReports::ElementData(variable));
124}
125
127{
128 // prepare the frame
129 QTextFrameFormat format;
130 if (d->m_width) {
131 if (d->m_widthUnit == Millimeters) {
133 } else {
135 }
136 }
137 if (d->m_height) {
138 if (d->m_heightUnit == Millimeters) {
140 } else {
142 }
143 }
144
145 format.setPadding(mmToPixels(padding()));
146 format.setBorder(d->m_border);
147 // TODO borderBrush like in AbstractTableElement
148 format.setPosition(static_cast<QTextFrameFormat::Position>(d->m_position)); // those enums have the same value
149
150 QTextCursor &textDocCursor = builder.cursor();
151
152 QTextFrame *frame = textDocCursor.insertFrame(format);
153
154 QTextCursor contentsCursor = frame->firstCursorPosition();
155
156 ReportBuilder contentsBuilder(builder.currentDocumentData(), contentsCursor, builder.report());
157 contentsBuilder.copyStateFrom(builder);
158
159 foreach (const KDReports::ElementData &ed, d->m_elements) {
160 switch (ed.m_type) {
162 contentsBuilder.addInlineElement(*ed.m_element);
163 break;
165 contentsBuilder.addBlockElement(*ed.m_element, ed.m_align);
166 break;
168 contentsBuilder.addVariable(ed.m_variableType);
169 break;
171 contentsBuilder.addVerticalSpacing(ed.m_value);
172 break;
173 }
174 }
175
176 textDocCursor.movePosition(QTextCursor::End);
177}
178
180{
181 return new Frame(*this);
182}
Element & operator=(const Element &other)
virtual Element * clone() const =0
void addVariable(VariableType variable)
void setBorder(qreal border)
@ InFlow
The frame is part of the flow of the paragraph (default)
qreal padding() const
Frame & operator=(const Frame &other)
void setWidth(qreal width, Unit unit=Millimeters)
Element * clone() const override
void setPosition(Position pos)
qreal border() const
void addInlineElement(const Element &element)
void setHeight(qreal height, Unit unit=Millimeters)
void addElement(const Element &element, Qt::AlignmentFlag horizontalAlignment=Qt::AlignLeft)
void setPadding(qreal padding)
void build(ReportBuilder &builder) const override
Position position() const
TextDocumentData & currentDocumentData()
virtual void addVerticalSpacing(qreal space)
virtual void addBlockElement(const Element &element, Qt::AlignmentFlag horizontalAlignment, const QColor &backgroundColor=QColor())
virtual void addVariable(KDReports::VariableType variable)
virtual void addInlineElement(const Element &element)
void copyStateFrom(const ReportBuilder &parentBuilder)
@ Millimeters
Millimeters (the default)
KDREPORTS_EXPORT qreal mmToPixels(qreal mm)
AlignmentFlag
QTextFrame * insertFrame(const QTextFrameFormat &format)
bool movePosition(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode, int n)
QTextCursor firstCursorPosition() const const
void setBorder(qreal width)
void setHeight(qreal height)
void setPadding(qreal width)
void setPosition(QTextFrameFormat::Position policy)
void setWidth(qreal width)
KDReports::VariableType m_variableType

© 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 on Wed Apr 24 2024 04:08:14 for KD Reports API Documentation by doxygen 1.9.8