KD Reports API Documentation  2.0
KDReportsTextElement.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-2022 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDAB-KDReports OR LicenseRef-KDAB-KDReports-US
8 **
9 ** Licensees holding valid commercial KD Reports licenses may use this file in
10 ** accordance with the KD Reports Commercial License Agreement provided with
11 ** the Software.
12 **
13 ** Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 **
15 ****************************************************************************/
16 
17 #include "KDReportsTextElement.h"
18 #include "KDReportsHeader_p.h" // for cleanupVariableProperties
20 #include <QDebug>
21 
22 class KDReports::TextElementPrivate
23 {
24 public:
25  TextElementPrivate()
26  : m_bold(false)
27  , m_boldIsSet(false)
28  , m_italic(false)
29  , m_italicIsSet(false)
30  , m_underline(false)
31  , m_underlineIsSet(false)
32  , m_strikeout(false)
33  , m_strikeoutIsSet(false)
34  , m_fontSet(false)
35  , m_pointSize(0)
36  {
37  }
38 
39  QString m_string;
40  QString m_id;
41 
42  QString m_fontFamily;
43  bool m_bold;
44  bool m_boldIsSet;
45  bool m_italic;
46  bool m_italicIsSet;
47  bool m_underline;
48  bool m_underlineIsSet;
49  bool m_strikeout;
50  bool m_strikeoutIsSet;
51  bool m_fontSet;
52  qreal m_pointSize;
53  QColor m_foreground;
54  QFont m_font;
55 };
56 
58  : Element()
59  , d(new TextElementPrivate)
60 {
61  d->m_string = string;
62 }
63 
65  : Element(other)
66  , d(new TextElementPrivate(*other.d))
67 {
68 }
69 
71 {
72  if (&other == this)
73  return *this;
74  Element::operator=(other);
75  *d = *other.d;
76  return *this;
77 }
78 
80 {
81  delete d;
82 }
83 
85 {
86  QTextCursor &cursor = builder.cursor();
87  const int charPosition = cursor.position();
88  QTextCharFormat charFormat = cursor.charFormat();
90  if (d->m_fontSet) {
91 #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
92  charFormat.setFont(d->m_font, QTextCharFormat::FontPropertiesSpecifiedOnly);
93 #else
94  charFormat.setFont(d->m_font);
95 #endif
96  }
97  if (d->m_boldIsSet)
98  charFormat.setFontWeight(d->m_bold ? QFont::Bold : QFont::Normal);
99  if (d->m_italicIsSet)
100  charFormat.setFontItalic(d->m_italic);
101  if (d->m_underlineIsSet)
102  charFormat.setFontUnderline(d->m_underline);
103  if (d->m_strikeoutIsSet)
104  charFormat.setFontStrikeOut(d->m_strikeout);
105  if (d->m_pointSize > 0)
106  charFormat.setFontPointSize(d->m_pointSize);
107  if (!d->m_fontFamily.isEmpty())
108  charFormat.setFontFamily(d->m_fontFamily);
109  if (d->m_foreground.isValid())
110  charFormat.setForeground(d->m_foreground);
111  charFormat.setBackground(background());
112  cursor.setCharFormat(charFormat);
113  cursor.insertText(d->m_string);
114  if (!d->m_id.isEmpty())
115  builder.currentDocumentData().setTextValueMarker(charPosition, d->m_id, d->m_string.length(), false);
116 }
117 
119 {
120  d->m_string.append(str);
121  return *this;
122 }
123 
124 void KDReports::TextElement::setText(const QString &text)
125 {
126  d->m_string = text;
127 }
128 
129 void KDReports::TextElement::setFontFamily(const QString &family)
130 {
131  d->m_fontFamily = family;
132 }
133 
135 {
136  d->m_bold = bold;
137  d->m_boldIsSet = true;
138 }
139 
141 {
142  d->m_italic = italic;
143  d->m_italicIsSet = true;
144 }
145 
147 {
148  d->m_underline = underline;
149  d->m_underlineIsSet = true;
150 }
151 
153 {
154  d->m_strikeout = strikeout;
155  d->m_strikeoutIsSet = true;
156 }
157 
159 {
160  d->m_pointSize = size;
161 }
162 
163 void KDReports::TextElement::setFont(const QFont &font)
164 {
165  d->m_font = font;
166  d->m_fontSet = true;
167 }
168 
169 void KDReports::TextElement::setTextColor(const QColor &color)
170 {
171  d->m_foreground = color;
172 }
173 
175 {
176  return d->m_foreground;
177 }
178 
180 {
181  return new TextElement(*this);
182 }
183 
184 void KDReports::TextElement::setId(const QString &id)
185 {
186  d->m_id = id;
187 }
188 
190 {
191  return d->m_id;
192 }
193 
195 {
196  return d->m_string;
197 }
198 
200 {
201  return d->m_font;
202 }
KDReports::TextElement::font
QFont font() const
Definition: KDReportsTextElement.cpp:199
KDReports::ReportBuilder
Definition: KDReportsReportBuilder_p.h:41
KDReports::ReportBuilder::currentDocumentData
TextDocumentData & currentDocumentData()
Definition: KDReportsReportBuilder_p.h:69
KDReports::cleanupVariableProperties
void cleanupVariableProperties(QTextCharFormat &charFormat)
Definition: KDReportsHeader.cpp:108
KDReports::TextElement::id
QString id() const
Definition: KDReportsTextElement.cpp:189
KDReports::TextElement::operator=
TextElement & operator=(const TextElement &other)
Definition: KDReportsTextElement.cpp:70
KDReports::TextElement::TextElement
TextElement(const QString &string=QString())
Definition: KDReportsTextElement.cpp:57
KDReports::TextDocumentData::setTextValueMarker
void setTextValueMarker(int pos, const QString &id, int valueLength, bool html)
Definition: KDReportsTextDocumentData.cpp:90
KDReports::TextElement::build
void build(ReportBuilder &builder) const override
Definition: KDReportsTextElement.cpp:84
KDReports::TextElement
Definition: KDReportsTextElement.h:36
KDReports::TextElement::setBold
void setBold(bool bold)
Set font attribute: bold.
Definition: KDReportsTextElement.cpp:134
KDReportsTextElement.h
KDReports::Element
Definition: KDReportsElement.h:39
KDReports::TextElement::setFont
void setFont(const QFont &)
Definition: KDReportsTextElement.cpp:163
KDReports::TextElement::setItalic
void setItalic(bool italic)
Set font attribute: italic.
Definition: KDReportsTextElement.cpp:140
KDReports::TextElement::operator<<
TextElement & operator<<(const QString &)
Definition: KDReportsTextElement.cpp:118
KDReports::TextElement::setTextColor
void setTextColor(const QColor &color)
Definition: KDReportsTextElement.cpp:169
KDReports::TextElement::~TextElement
~TextElement() override
Definition: KDReportsTextElement.cpp:79
KDReports::TextElement::clone
Element * clone() const override
Definition: KDReportsTextElement.cpp:179
KDReports::Element::operator=
Element & operator=(const Element &other)
Definition: KDReportsElement.cpp:36
KDReportsHeader_p.h
KDReports::TextElement::setFontFamily
void setFontFamily(const QString &family)
Set font attribute: family.
Definition: KDReportsTextElement.cpp:129
KDReports::TextElement::setId
void setId(const QString &id)
Definition: KDReportsTextElement.cpp:184
KDReportsReportBuilder_p.h
KDReports::TextElement::setStrikeOut
void setStrikeOut(bool strikeout)
Set font attribute: strike out.
Definition: KDReportsTextElement.cpp:152
KDReports::ReportBuilder::cursor
QTextCursor & cursor()
Definition: KDReportsReportBuilder_p.h:48
KDReports::TextElement::text
QString text() const
Definition: KDReportsTextElement.cpp:194
KDReports::TextElement::setPointSize
void setPointSize(qreal size)
Set font attribute: size in points. Can be integer or decimal.
Definition: KDReportsTextElement.cpp:158
KDReports::TextElement::textColor
QColor textColor() const
Definition: KDReportsTextElement.cpp:174
KDReports::TextElement::setUnderline
void setUnderline(bool underline)
Set font attribute: underline.
Definition: KDReportsTextElement.cpp:146
KDReports::TextElement::setText
void setText(const QString &text)
Definition: KDReportsTextElement.cpp:124

© 2007-2021 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 Sat Jan 8 2022 02:38:32 for KD Reports API Documentation by doxygen 1.8.17