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 
26 using namespace KChart;
27 
28 class Q_DECL_HIDDEN DataValueAttributes::Private
29 {
30  friend class DataValueAttributes;
31 public:
32  Private();
33 private:
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 
53 DataValueAttributes::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 );
60  textAttributes.setFontSize( me );
61  me.setValue( 8.0 );
62  me.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
63  textAttributes.setMinimalFontSize( me );
64  textAttributes.setRotation( -45 );
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 
73  showRepetitiveDataLabels = false;
74  showOverlappingDataLabels = false;
75 
76  usePercentage = false;
77  mirrorNegativeValueTextRotation = false;
78 }
79 
80 
81 DataValueAttributes::DataValueAttributes()
82  : _d( new Private() )
83 {
84 }
85 
86 DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
87  : _d( new Private( *r.d ) )
88 {
89 }
90 
91 DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
92 {
93  if ( this == &r )
94  return *this;
95 
96  *d = *r.d;
97 
98  return *this;
99 }
100 
101 DataValueAttributes::~DataValueAttributes()
102 {
103  delete _d; _d = nullptr;
104 }
105 
106 
107 bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
108 {
109  return isVisible() == r.isVisible() &&
110  textAttributes() == r.textAttributes() &&
111  frameAttributes() == r.frameAttributes() &&
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*/
129 const DataValueAttributes& DataValueAttributes::defaultAttributes()
130 {
131  static const DataValueAttributes theDefaultDataValueAttributes;
132  return theDefaultDataValueAttributes;
133 }
134 
135 /*static*/
136 const 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 
223 void DataValueAttributes::setPrefix( const QString prefixString )
224 {
225  d->prefix = prefixString;
226 }
227 
229 {
230  return d->prefix;
231 }
232 
233 void 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 
258 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
259 {
260  d->showRepetitiveDataLabels = showRepetitiveDataLabels;
261 }
262 
264 {
265  return d->showOverlappingDataLabels;
266 }
267 
268 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
269 {
270  d->showOverlappingDataLabels = showOverlappingDataLabels;
271 }
272 
273 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
274 {
275  d->powerOfTenDivisor = powerOfTenDivisor;
276 }
277 
278 int DataValueAttributes::powerOfTenDivisor() const
279 {
280  return d->powerOfTenDivisor;
281 }
282 
283 void DataValueAttributes::setShowInfinite( bool infinite )
284 {
285  d->showInfinite = infinite;
286 }
287 
288 bool 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)
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 */
A set of attributes for frames around items.
void setMarkerAttributes(const MarkerAttributes &a)
Set the marker attributes to use for the data values.
AlignTop
QString prefix() const
Returns the string used as a prefix to the data value text.
void setDataLabel(const QString label)
display a string label instead of the original data value label Supports HTML code.
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
void setMirrorNegativeValueTextRotation(bool enable)
QVariant fromValue(const T &value)
Declaring the class KChart::DataValueAttributes.
void setSuffix(const QString suffix)
Append a suffix string to the data value label.
void setPrefix(const QString prefix)
Prepend a prefix string to the data value label.
void setNegativePosition(const RelativePosition &relPosition)
Defines the relative positioning of the data value labels for negative values.
Diagram attributes dealing with data value labels.
void setDecimalDigits(int digits)
Set how many decimal digits to display when rendering the data value labels.
void setShowRepetitiveDataLabels(bool showRepetitiveDataLabels)
Set whether data value labels not different from their predecessors should be drawn.
const RelativePosition negativePosition() const
Return the relative positioning of the data value labels.
Set of attributes usable for background pixmaps.
void setUsePercentage(bool enable)
Specify whether to use percentages instead of actual data point values when no specific label is set.
void setPositivePosition(const RelativePosition &relPosition)
Defines the relative position of the data value labels for positive values.
void setFrameAttributes(const FrameAttributes &a)
Set the frame attributes to use for the data value labels area.
Measure is used to specify relative and absolute sizes in KChart, e.g. font sizes.
Definition: KChartMeasure.h:37
QString suffix() const
Returns the string used as a suffix to the data value text.
MarkerAttributes markerAttributes() const
void setBackgroundAttributes(const BackgroundAttributes &a)
Set the background attributes to use for the data value labels area.
QString dataLabel() const
Returns the string displayed instead of the data value label.
A set of attributes controlling the appearance of data set markers.
Defines relative position information: reference area, position in this area (reference position),...
const RelativePosition positivePosition() const
Return the relative positioning of the data value labels.
BackgroundAttributes backgroundAttributes() const
void setVisible(bool visible)
Set whether data value labels should be displayed.
void setTextAttributes(const TextAttributes &a)
Set the text attributes to use for the data value labels.
bool mirrorNegativeValueTextRotation() const
If true, rotation of negative value labels is negated, so that negative values are rotated in opposit...
A set of text attributes.
void setShowOverlappingDataLabels(bool showOverlappingDataLabels)
Set whether data value texts overlapping other data value texts of the same diagram should be drawn.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Jul 1 2022 05:09:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.