KD Chart 2  [rev.2.7]
KDChartDataValueAttributes.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
24 
25 #include <QVariant>
26 #include <QDebug>
28 #include "KDChartPosition.h"
29 #include <KDChartTextAttributes.h>
30 #include <KDChartFrameAttributes.h>
33 
34 #include <KDABLibFakes>
35 
36 // FIXME till
37 #define KDCHART_DATA_VALUE_AUTO_DIGITS 4
38 
39 
40 #define d d_func()
41 
42 using namespace KDChart;
43 
44 class DataValueAttributes::Private
45 {
46  friend class DataValueAttributes;
47 public:
48  Private();
49 private:
54  QString prefix;
55  QString suffix;
56  QString dataLabel;
57  RelativePosition negativeRelPos;
58  RelativePosition positiveRelPos;
59  qint16 decimalDigits;
60  qint16 powerOfTenDivisor;
61  bool visible : 1;
62  bool showInfinite : 1;
63  bool showRepetitiveDataLabels : 1;
65  bool usePercentage : 1;
67 };
68 
69 DataValueAttributes::Private::Private() :
71  powerOfTenDivisor( 0 ),
72  visible( false ),
73  showInfinite( true )
74 {
77  me.setValue( 8.0 );
81 
82  // we set the Position to unknown: so the diagrams can take their own decisions
83  positiveRelPos.setReferencePosition( Position::Unknown );
84  negativeRelPos.setReferencePosition( Position::Unknown );
85 
86  positiveRelPos.setAlignment( Qt::AlignTop | Qt::AlignRight );
87  negativeRelPos.setAlignment( Qt::AlignBottom | Qt::AlignRight );
88 
91 
92  usePercentage = false;
94 }
95 
96 
98  : _d( new Private() )
99 {
100 }
101 
103  : _d( new Private( *r.d ) )
104 {
105 }
106 
108 {
109  if ( this == &r )
110  return *this;
111 
112  *d = *r.d;
113 
114  return *this;
115 }
116 
118 {
119  delete _d; _d = 0;
120 }
121 
122 
124 {
125  return isVisible() == r.isVisible() &&
126  textAttributes() == r.textAttributes() &&
127  frameAttributes() == r.frameAttributes() &&
130  decimalDigits() == r.decimalDigits() &&
131  prefix() == r.prefix() &&
132  suffix() == r.suffix() &&
133  dataLabel() == r.dataLabel() &&
134  powerOfTenDivisor() == r.powerOfTenDivisor() &&
135  showInfinite() == r.showInfinite() &&
140  usePercentage() == r.usePercentage() &&
142 }
143 
144 /*static*/
146 {
147  static const DataValueAttributes theDefaultDataValueAttributes;
148  return theDefaultDataValueAttributes;
149 }
150 
151 /*static*/
153 {
154  static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes());
155  return theDefaultDataValueAttributesVariant;
156 }
157 
158 
160 {
161  d->visible = visible;
162 }
163 
165 {
166  return d->visible;
167 }
168 
170 {
171  d->textAttributes = a;
172 }
173 
175 {
176  return d->textAttributes;
177 }
178 
180 {
181  d->frameAttributes = a;
182 }
183 
185 {
186  return d->frameAttributes;
187 }
188 
190 {
191  d->backgroundAttributes = a;
192 }
193 
195 {
196  return d->backgroundAttributes;
197 }
198 
200 {
201  d->markerAttributes = a;
202 }
203 
205 {
206  return d->markerAttributes;
207 }
208 
210 {
211  d->mirrorNegativeValueTextRotation = enable;
212 }
213 
215 {
216  return d->mirrorNegativeValueTextRotation;
217 }
218 
220 {
221  d->usePercentage = enable;
222 }
223 
225 {
226  return d->usePercentage;
227 }
228 
230 {
231  d->decimalDigits = digits;
232 }
233 
235 {
236  return d->decimalDigits;
237 }
238 
239 void DataValueAttributes::setPrefix( const QString prefixString )
240 {
241  d->prefix = prefixString;
242 }
243 
245 {
246  return d->prefix;
247 }
248 
249 void DataValueAttributes::setSuffix( const QString suffixString )
250 {
251  d->suffix = suffixString;
252 }
253 
255 {
256  return d->suffix;
257 }
258 
259 void DataValueAttributes::setDataLabel( const QString label )
260 {
261  d->dataLabel = label;
262 }
263 
265 {
266  return d->dataLabel;
267 }
268 
270 {
271  return d->showRepetitiveDataLabels;
272 }
273 
275 {
276  d->showRepetitiveDataLabels = showRepetitiveDataLabels;
277 }
278 
280 {
281  return d->showOverlappingDataLabels;
282 }
283 
285 {
286  d->showOverlappingDataLabels = showOverlappingDataLabels;
287 }
288 
289 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
290 {
291  d->powerOfTenDivisor = powerOfTenDivisor;
292 }
293 
294 int DataValueAttributes::powerOfTenDivisor() const
295 {
296  return d->powerOfTenDivisor;
297 }
298 
299 void DataValueAttributes::setShowInfinite( bool infinite )
300 {
301  d->showInfinite = infinite;
302 }
303 
304 bool DataValueAttributes::showInfinite() const
305 {
306  return d->showInfinite;
307 }
308 
310 {
311  d->negativeRelPos = relPosition;
312 }
313 
315 {
316  return d->negativeRelPos;
317 }
318 
320 {
321  d->positiveRelPos = relPosition;
322 }
323 
325 {
326  return d->positiveRelPos;
327 }
328 
329 #if !defined(QT_NO_DEBUG_STREAM)
330 QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val )
331 {
332  dbg << "RelativePosition DataValueAttributes("
333  << "visible="<<val.isVisible()
334  << "textattributes="<<val.textAttributes()
335  << "frameattributes="<<val.frameAttributes()
336  << "backgroundattributes="<<val.backgroundAttributes()
337  << "decimaldigits="<<val.decimalDigits()
338  << "poweroftendivisor="<<val.powerOfTenDivisor()
339  << "showinfinite="<<val.showInfinite()
340  << "negativerelativeposition="<<val.negativePosition()
341  << "positiverelativeposition="<<val.positivePosition()
342  << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
343  << "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
344  <<")";
345  return dbg;
346 }
347 #endif /* QT_NO_DEBUG_STREAM */
QString prefix() const
Returns the string used as a prefix to the data value text.
void setDecimalDigits(int digits)
Set how many decimal digits to display when rendering the data value labels.
bool mirrorNegativeValueTextRotation() const
If true, rotation of negative value labels is negated, so that negative values are rotated in opposit...
MarkerAttributes markerAttributes() const
void setVisible(bool visible)
Set whether data value labels should be displayed.
Diagram attributes dealing with data value labels.
void setFrameAttributes(const FrameAttributes &a)
Set the frame attributes to use for the data value labels area.
QString dataLabel() const
Returns the string displayed instead of the data value label.
BackgroundAttributes backgroundAttributes() const
static const DataValueAttributes & defaultAttributes()
Declaring the class KDChart::DataValueAttributes.
A set of attributes for frames around items.
void setMarkerAttributes(const MarkerAttributes &a)
Set the marker attributes to use for the data values.
void setDataLabel(const QString label)
display a string label instead of the original data value label Supports HTML code.
static const Position & Unknown
void setValue(qreal val)
static const QVariant & defaultAttributesAsVariant()
void setRotation(int rotation)
Set the rotation angle to use for the text.
void setPositivePosition(const RelativePosition &relPosition)
Defines the relative position of the data value labels for positive values.
void setPrefix(const QString prefix)
Prepend a prefix string to the data value label.
#define KDCHART_DATA_VALUE_AUTO_DIGITS
void setFontSize(const Measure &measure)
Set the size of the font used for rendering text.
void setTextAttributes(const TextAttributes &a)
Set the text attributes to use for the data value labels.
void setUsePercentage(bool enable)
Specify whether to use percentages instead of actual data point values when no specific label is set...
const RelativePosition positivePosition() const
Return the relative positioning of the data value labels.
void setShowRepetitiveDataLabels(bool showRepetitiveDataLabels)
Set whether data value labels not different from their predecessors should be drawn.
DataValueAttributes & operator=(const DataValueAttributes &)
void setBackgroundAttributes(const BackgroundAttributes &a)
Set the background attributes to use for the data value labels area.
bool operator==(const DataValueAttributes &) const
A set of attributes controlling the appearance of data set markers.
void setShowOverlappingDataLabels(bool showOverlappingDataLabels)
Set whether data value texts overlapping other data value texts of the same diagram should be drawn...
void setSuffix(const QString suffix)
Append a suffix string to the data value label.
Measure is used to specify relative and absolute sizes in KDChart, e.g.
QString suffix() const
Returns the string used as a suffix to the data value text.
Defines relative position information: reference area, position in this area (reference position)...
void setMinimalFontSize(const Measure &measure)
Set the minimal size of the font used for rendering text.
QDebug operator<<(QDebug stream, const DataDimension &r)
void setCalculationMode(KDChartEnums::MeasureCalculationMode mode)
void setNegativePosition(const RelativePosition &relPosition)
Defines the relative positioning of the data value labels for negative values.
const RelativePosition negativePosition() const
Return the relative positioning of the data value labels.
A set of text attributes.
Set of attributes usable for background pixmaps.

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/