KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
KDChartTextAttributes.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
12
14#include <KDChartCartesianCoordinatePlane_p.h>
15
16#include <KDABLibFakes>
17#include <QApplication>
18#include <QFont>
19#include <QPen>
20#include <QSharedPointer>
21#include <QTextDocument>
22#include <qglobal.h>
23
24#define d d_func()
25
26using namespace KDChart;
27
28class TextAttributes::Private
29{
30 friend class TextAttributes;
31
32public:
33 Private();
34
35private:
36 bool visible = true;
37 QFont font;
38 mutable QFont cachedFont;
39 mutable qreal cachedFontSize = -1.0;
40 Measure fontSize;
41 Measure minimalFontSize;
42 bool autoRotate = false;
43 bool autoShrink = false;
44 bool hasRotation = false;
45 int rotation = 0;
46 QPen pen;
48};
49
50TextAttributes::Private::Private()
52 , pen(Qt::black)
53{
54}
55
57 : _d(new Private())
58{
59}
60
62 : _d(new Private(*r.d))
63{
64}
65
67{
68 if (this == &r)
69 return *this;
70
71 *d = *r.d;
72
73 return *this;
74}
75
77{
78 delete _d;
79 _d = nullptr;
80}
81
83{
84 // the following works around a bug in gcc 4.3.2
85 // causing StyleHint to be set to Zero when copying a QFont
86 const QFont myFont(font());
87 QFont r_font(r.font());
88 r_font.setStyleHint(myFont.styleHint(), myFont.styleStrategy());
89 return (isVisible() == r.isVisible() && myFont == r_font && fontSize() == r.fontSize() && minimalFontSize() == r.minimalFontSize() && autoRotate() == r.autoRotate() && autoShrink() == r.autoShrink() && rotation() == r.rotation() && pen() == r.pen() && textDocument() == r.textDocument());
90}
91
93{
94 d->visible = visible;
95}
96
98{
99 return d->visible;
100}
101
103{
104 d->font = font;
105 d->cachedFont = font; // note: we do not set the font's size here, but in calculatedFont()
106 d->cachedFontSize = -1.0;
107}
108
110{
111 return d->font;
112}
113
115{
116 d->fontSize = measure;
117}
118
120{
121 return d->fontSize;
122}
123
125{
126 d->minimalFontSize = measure;
127}
128
130{
131 return d->minimalFontSize;
132}
133
135{
137 && d->minimalFontSize.calculationMode() == KDChartEnums::MeasureCalculationModeAbsolute;
138}
139
141 KDChartEnums::MeasureOrientation autoReferenceOrientation) const
142{
143 const qreal normalSize = fontSize().calculatedValue(referenceSize, autoReferenceOrientation);
144 const qreal minimalSize = minimalFontSize().calculatedValue(referenceSize, autoReferenceOrientation);
145 return qMax(normalSize, minimalSize);
146}
147
148#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && defined(Q_COMPILER_MANGLES_RETURN_TYPE)
149const
150#endif
151 qreal
153 KDChartEnums::MeasureOrientation autoReferenceOrientation) const
154{
155 const qreal normalSize = fontSize().calculatedValue(autoReferenceArea, autoReferenceOrientation);
156 const qreal minimalSize = minimalFontSize().calculatedValue(autoReferenceArea, autoReferenceOrientation);
157 return qMax(normalSize, minimalSize);
158}
159
160const QFont TextAttributes::calculatedFont(const QObject *autoReferenceArea,
161 KDChartEnums::MeasureOrientation autoReferenceOrientation) const
162{
163 qreal size = NaN;
164
165 const auto *plane = qobject_cast<const CartesianCoordinatePlane *>(autoReferenceArea);
166 if (plane && plane->hasFixedDataCoordinateSpaceRelation()) {
167 // HACK
168 // if hasFixedDataCoordinateSpaceRelation, we use a zoom trick to keep the diagram at a constant size
169 // even when the plane size changes. calculatedFontSize() usually uses the plane size, not the diagram
170 // size, to determine the font size. here we need to give it the diagram size in order to make the font
171 // size constant, too. see KDCHDEV-219.
172 CartesianCoordinatePlane::Private *priv = CartesianCoordinatePlane::Private::get(const_cast<CartesianCoordinatePlane *>(plane));
173 size = calculatedFontSize(priv->fixedDataCoordinateSpaceRelationPinnedSize,
174 autoReferenceOrientation);
175 } else {
176 size = calculatedFontSize(autoReferenceArea, autoReferenceOrientation);
177 }
178
179 if (size > 0.0 && d->cachedFontSize != size) {
180 d->cachedFontSize = size;
181 d->cachedFont.setPointSizeF(d->cachedFontSize);
182 }
183
184 return d->cachedFont;
185}
186
187void TextAttributes::setAutoRotate(bool autoRotate)
188{
189 d->autoRotate = autoRotate;
190}
191
193{
194 return d->autoRotate;
195}
196
197void TextAttributes::setAutoShrink(bool autoShrink)
198{
199 d->autoShrink = autoShrink;
200}
201
203{
204 return d->autoShrink;
205}
206
208{
209 d->hasRotation = true;
210 d->rotation = rotation;
211}
212
214{
215 return d->rotation;
216}
217
219{
220 d->hasRotation = false;
221 d->rotation = 0;
222}
223
225{
226 return d->hasRotation;
227}
228
230{
231 d->pen = pen;
232}
233
235{
236 return d->pen;
237}
238
240{
241 return d->document.data();
242}
243
245{
246 d->document = QSharedPointer<QTextDocument>(document);
247}
248
249#if !defined(QT_NO_DEBUG_STREAM)
251{
252 dbg << "KDChart::TextAttributes("
253 << "visible=" << ta.isVisible()
254 << "font=" << ta.font().toString() /* What? No QDebug for QFont? */
255 << "fontsize=" << ta.fontSize()
256 << "minimalfontsize=" << ta.minimalFontSize()
257 << "autorotate=" << ta.autoRotate()
258 << "autoshrink=" << ta.autoShrink()
259 << "rotation=" << ta.rotation()
260 << "pen=" << ta.pen()
261 << ")";
262 return dbg;
263}
264#endif /* QT_NO_DEBUG_STREAM */
@ MeasureCalculationModeAbsolute
Measure is used to specify relative and absolute sizes in KDChart, e.g. font sizes.
qreal calculatedValue(const QObject *autoArea, KDChartEnums::MeasureOrientation autoOrientation) const
KDChartEnums::MeasureCalculationMode calculationMode() const
A set of text attributes.
void setFontSize(const Measure &measure)
void setAutoRotate(bool autoRotate)
const QFont calculatedFont(const QObject *autoReferenceArea, KDChartEnums::MeasureOrientation autoReferenceOrientation) const
Returns the font in the size that is used at drawing time.
bool operator==(const TextAttributes &) const
void setMinimalFontSize(const Measure &measure)
void setTextDocument(QTextDocument *layout)
TextAttributes & operator=(const TextAttributes &)
void setFont(const QFont &font)
QTextDocument * textDocument() const
void setAutoShrink(bool autoShrink)
qreal calculatedFontSize(const QSizeF &referenceSize, KDChartEnums::MeasureOrientation autoReferenceOrientation) const
Returns the font size that is used at drawing time.
QDebug operator<<(QDebug stream, const DataDimension &r)
void setStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy)
QFont::StyleHint styleHint() const const
QFont::StyleStrategy styleStrategy() const const
QString toString() const const

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Wed May 1 2024 00:01:10 for KD Chart API Documentation by doxygen 1.9.8