KChart

KChartDataValueAttributes.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
10
11#include <QVariant>
12#include <QDebug>
13#include "KChartPosition.h"
14#include "KChartMath_p.h"
15#include <KChartTextAttributes.h>
16#include <KChartFrameAttributes.h>
17#include <KChartBackgroundAttributes.h>
18#include <KChartMarkerAttributes.h>
19
20// FIXME till
21#define KCHART_DATA_VALUE_AUTO_DIGITS 4
22
23
24#define d d_func()
25
26using namespace KChart;
27
28class Q_DECL_HIDDEN DataValueAttributes::Private
29{
30 friend class DataValueAttributes;
31public:
32 Private();
33private:
34 TextAttributes textAttributes;
35 FrameAttributes frameAttributes;
36 BackgroundAttributes backgroundAttributes;
37 MarkerAttributes markerAttributes;
38 QString prefix;
39 QString suffix;
40 QString dataLabel;
41 RelativePosition negativeRelPos;
42 RelativePosition positiveRelPos;
43 qint16 decimalDigits;
44 qint16 powerOfTenDivisor;
45 bool visible : 1;
46 bool showInfinite : 1;
47 bool showRepetitiveDataLabels : 1;
48 bool showOverlappingDataLabels : 1;
49 bool usePercentage : 1;
50 bool mirrorNegativeValueTextRotation : 1;
51};
52
53DataValueAttributes::Private::Private() :
54 decimalDigits( KCHART_DATA_VALUE_AUTO_DIGITS ),
55 powerOfTenDivisor( 0 ),
56 visible( false ),
57 showInfinite( true )
58{
59 Measure me( 20.0, KChartEnums::MeasureCalculationModeAuto, KChartEnums::MeasureOrientationAuto );
61 me.setValue( 8.0 );
62 me.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
65
66 // we set the Position to unknown: so the diagrams can take their own decisions
67 positiveRelPos.setReferencePosition( Position::Unknown );
68 negativeRelPos.setReferencePosition( Position::Unknown );
69
70 positiveRelPos.setAlignment( Qt::AlignTop | Qt::AlignRight );
71 negativeRelPos.setAlignment( Qt::AlignBottom | Qt::AlignRight );
72
75
76 usePercentage = false;
78}
79
80
81DataValueAttributes::DataValueAttributes()
82 : _d( new Private() )
83{
84}
85
86DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
87 : _d( new Private( *r.d ) )
88{
89}
90
91DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
92{
93 if ( this == &r )
94 return *this;
95
96 *d = *r.d;
97
98 return *this;
99}
100
101DataValueAttributes::~DataValueAttributes()
102{
103 delete _d; _d = nullptr;
104}
105
106
107bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
108{
109 return isVisible() == r.isVisible() &&
114 decimalDigits() == r.decimalDigits() &&
115 prefix() == r.prefix() &&
116 suffix() == r.suffix() &&
117 dataLabel() == r.dataLabel() &&
118 powerOfTenDivisor() == r.powerOfTenDivisor() &&
119 showInfinite() == r.showInfinite() &&
124 usePercentage() == r.usePercentage() &&
126}
127
128/*static*/
129const DataValueAttributes& DataValueAttributes::defaultAttributes()
130{
131 static const DataValueAttributes theDefaultDataValueAttributes;
132 return theDefaultDataValueAttributes;
133}
134
135/*static*/
136const QVariant& DataValueAttributes::defaultAttributesAsVariant()
137{
138 static const QVariant theDefaultDataValueAttributesVariant = QVariant::fromValue(defaultAttributes());
139 return theDefaultDataValueAttributesVariant;
140}
141
142
144{
145 d->visible = visible;
146}
147
149{
150 return d->visible;
151}
152
154{
155 d->textAttributes = a;
156}
157
159{
160 return d->textAttributes;
161}
162
164{
165 d->frameAttributes = a;
166}
167
169{
170 return d->frameAttributes;
171}
172
174{
175 d->backgroundAttributes = a;
176}
177
179{
180 return d->backgroundAttributes;
181}
182
184{
185 d->markerAttributes = a;
186}
187
189{
190 return d->markerAttributes;
191}
192
194{
195 d->mirrorNegativeValueTextRotation = enable;
196}
197
199{
200 return d->mirrorNegativeValueTextRotation;
201}
202
204{
205 d->usePercentage = enable;
206}
207
209{
210 return d->usePercentage;
211}
212
214{
215 d->decimalDigits = digits;
216}
217
219{
220 return d->decimalDigits;
221}
222
223void DataValueAttributes::setPrefix( const QString prefixString )
224{
225 d->prefix = prefixString;
226}
227
229{
230 return d->prefix;
231}
232
233void DataValueAttributes::setSuffix( const QString suffixString )
234{
235 d->suffix = suffixString;
236}
237
239{
240 return d->suffix;
241}
242
244{
245 d->dataLabel = label;
246}
247
249{
250 return d->dataLabel;
251}
252
254{
255 return d->showRepetitiveDataLabels;
256}
257
258void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
259{
260 d->showRepetitiveDataLabels = showRepetitiveDataLabels;
261}
262
264{
265 return d->showOverlappingDataLabels;
266}
267
268void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
269{
270 d->showOverlappingDataLabels = showOverlappingDataLabels;
271}
272
273void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
274{
275 d->powerOfTenDivisor = powerOfTenDivisor;
276}
277
278int DataValueAttributes::powerOfTenDivisor() const
279{
280 return d->powerOfTenDivisor;
281}
282
283void DataValueAttributes::setShowInfinite( bool infinite )
284{
285 d->showInfinite = infinite;
286}
287
288bool DataValueAttributes::showInfinite() const
289{
290 return d->showInfinite;
291}
292
294{
295 d->negativeRelPos = relPosition;
296}
297
299{
300 return d->negativeRelPos;
301}
302
304{
305 d->positiveRelPos = relPosition;
306}
307
309{
310 return d->positiveRelPos;
311}
312
313#if !defined(QT_NO_DEBUG_STREAM)
314QDebug operator<<(QDebug dbg, const KChart::DataValueAttributes& val )
315{
316 dbg << "RelativePosition DataValueAttributes("
317 << "visible="<<val.isVisible()
318 << "textattributes="<<val.textAttributes()
319 << "frameattributes="<<val.frameAttributes()
320 << "backgroundattributes="<<val.backgroundAttributes()
321 << "decimaldigits="<<val.decimalDigits()
322 << "poweroftendivisor="<<val.powerOfTenDivisor()
323 << "showinfinite="<<val.showInfinite()
324 << "negativerelativeposition="<<val.negativePosition()
325 << "positiverelativeposition="<<val.positivePosition()
326 << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
327 << "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
328 <<")";
329 return dbg;
330}
331#endif /* QT_NO_DEBUG_STREAM */
Declaring the class KChart::DataValueAttributes.
Set of attributes usable for background pixmaps.
Diagram attributes dealing with data value labels.
void setFrameAttributes(const FrameAttributes &a)
Set the frame attributes to use for the data value labels area.
void setDataLabel(const QString label)
display a string label instead of the original data value label Supports HTML code.
const RelativePosition positivePosition() const
Return the relative positioning of the data value labels.
void setDecimalDigits(int digits)
Set how many decimal digits to display when rendering the data value labels.
void setMarkerAttributes(const MarkerAttributes &a)
Set the marker attributes to use for the data values.
void setPositivePosition(const RelativePosition &relPosition)
Defines the relative position of the data value labels for positive values.
void setUsePercentage(bool enable)
Specify whether to use percentages instead of actual data point values when no specific label is set.
MarkerAttributes markerAttributes() const
const RelativePosition negativePosition() const
Return the relative positioning of the data value labels.
BackgroundAttributes backgroundAttributes() const
void setBackgroundAttributes(const BackgroundAttributes &a)
Set the background attributes to use for the data value labels area.
bool mirrorNegativeValueTextRotation() const
If true, rotation of negative value labels is negated, so that negative values are rotated in opposit...
QString prefix() const
Returns the string used as a prefix to the data value text.
void setShowOverlappingDataLabels(bool showOverlappingDataLabels)
Set whether data value texts overlapping other data value texts of the same diagram should be drawn.
void setTextAttributes(const TextAttributes &a)
Set the text attributes to use for the data value labels.
void setNegativePosition(const RelativePosition &relPosition)
Defines the relative positioning of the data value labels for negative values.
void setVisible(bool visible)
Set whether data value labels should be displayed.
QString suffix() const
Returns the string used as a suffix to the data value text.
QString dataLabel() const
Returns the string displayed instead of the data value label.
void setPrefix(const QString prefix)
Prepend a prefix string to the data value label.
void setShowRepetitiveDataLabels(bool showRepetitiveDataLabels)
Set whether data value labels not different from their predecessors should be drawn.
void setSuffix(const QString suffix)
Append a suffix string to the data value label.
A set of attributes for frames around items.
A set of attributes controlling the appearance of data set markers.
Measure is used to specify relative and absolute sizes in KChart, e.g.
Defines relative position information: reference area, position in this area (reference position),...
A set of text attributes.
void setFontSize(const Measure &measure)
Set the size of the font used for rendering text.
void setMinimalFontSize(const Measure &measure)
Set the minimal size of the font used for rendering text.
void setRotation(int rotation)
Set the rotation angle to use for the text.
AlignTop
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.