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

KDE's Doxygen guidelines are available online.