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() :
70  decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ),
71  powerOfTenDivisor( 0 ),
72  visible( false ),
73  showInfinite( true )
74 {
76  textAttributes.setFontSize( me );
77  me.setValue( 8.0 );
78  me.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
79  textAttributes.setMinimalFontSize( me );
80  textAttributes.setRotation( -45 );
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 
89  showRepetitiveDataLabels = false;
90  showOverlappingDataLabels = false;
91 
92  usePercentage = false;
93  mirrorNegativeValueTextRotation = false;
94 }
95 
96 
97 DataValueAttributes::DataValueAttributes()
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 
274 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
275 {
276  d->showRepetitiveDataLabels = showRepetitiveDataLabels;
277 }
278 
280 {
281  return d->showOverlappingDataLabels;
282 }
283 
284 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
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 */
KDChart::DataValueAttributes::negativePosition
const RelativePosition negativePosition() const
Return the relative positioning of the data value labels.
Definition: KDChartDataValueAttributes.cpp:314
KDChart::MarkerAttributes
A set of attributes controlling the appearance of data set markers.
Definition: KDChartMarkerAttributes.h:44
KDChart::DataValueAttributes::setShowRepetitiveDataLabels
void setShowRepetitiveDataLabels(bool showRepetitiveDataLabels)
Set whether data value labels not different from their predecessors should be drawn.
Definition: KDChartDataValueAttributes.cpp:274
KDChart::DataValueAttributes::showRepetitiveDataLabels
bool showRepetitiveDataLabels() const
Definition: KDChartDataValueAttributes.cpp:269
KDChart::DataValueAttributes::decimalDigits
int decimalDigits() const
Definition: KDChartDataValueAttributes.cpp:234
KDChartEnums::MeasureOrientationAuto
@ MeasureOrientationAuto
Definition: KDChartEnums.h:290
KDChartEnums::MeasureCalculationModeAuto
@ MeasureCalculationModeAuto
Definition: KDChartEnums.h:224
KDChart::DataValueAttributes::defaultAttributesAsVariant
static const QVariant & defaultAttributesAsVariant()
Definition: KDChartDataValueAttributes.cpp:152
KDChart::DataValueAttributes::~DataValueAttributes
~DataValueAttributes()
Definition: KDChartDataValueAttributes.cpp:117
KDChart::DataValueAttributes::frameAttributes
FrameAttributes frameAttributes() const
Definition: KDChartDataValueAttributes.cpp:184
KDChart::DataValueAttributes::markerAttributes
MarkerAttributes markerAttributes() const
Definition: KDChartDataValueAttributes.cpp:204
KDChart::DataValueAttributes::backgroundAttributes
BackgroundAttributes backgroundAttributes() const
Definition: KDChartDataValueAttributes.cpp:194
KDChart::DataValueAttributes::operator==
bool operator==(const DataValueAttributes &) const
Definition: KDChartDataValueAttributes.cpp:123
KDChart::DataValueAttributes::prefix
QString prefix() const
Returns the string used as a prefix to the data value text.
Definition: KDChartDataValueAttributes.cpp:244
KDChart
Definition: KDChartAbstractCartesianDiagram.h:30
KDChart::DataValueAttributes::setSuffix
void setSuffix(const QString suffix)
Append a suffix string to the data value label.
Definition: KDChartDataValueAttributes.cpp:249
KDChart::DataValueAttributes::suffix
QString suffix() const
Returns the string used as a suffix to the data value text.
Definition: KDChartDataValueAttributes.cpp:254
KDChart::DataValueAttributes::setBackgroundAttributes
void setBackgroundAttributes(const BackgroundAttributes &a)
Set the background attributes to use for the data value labels area.
Definition: KDChartDataValueAttributes.cpp:189
KDChart::DataValueAttributes::setShowOverlappingDataLabels
void setShowOverlappingDataLabels(bool showOverlappingDataLabels)
Set whether data value texts overlapping other data value texts of the same diagram should be drawn.
Definition: KDChartDataValueAttributes.cpp:284
KDChart::DataValueAttributes::usePercentage
bool usePercentage() const
Definition: KDChartDataValueAttributes.cpp:224
KDChart::DataValueAttributes::setFrameAttributes
void setFrameAttributes(const FrameAttributes &a)
Set the frame attributes to use for the data value labels area.
Definition: KDChartDataValueAttributes.cpp:179
KDChart::operator<<
QDebug operator<<(QDebug stream, const DataDimension &r)
Definition: KDChartAbstractCoordinatePlane.cpp:440
KDChart::TextAttributes
A set of text attributes.
Definition: KDChartTextAttributes.h:47
KDChart::Measure
Measure is used to specify relative and absolute sizes in KDChart, e.g.
Definition: KDChartMeasure.h:52
KDChart::DataValueAttributes::setMirrorNegativeValueTextRotation
void setMirrorNegativeValueTextRotation(bool enable)
Definition: KDChartDataValueAttributes.cpp:209
KDChart::DataValueAttributes::positivePosition
const RelativePosition positivePosition() const
Return the relative positioning of the data value labels.
Definition: KDChartDataValueAttributes.cpp:324
KDChart::DataValueAttributes::setNegativePosition
void setNegativePosition(const RelativePosition &relPosition)
Defines the relative positioning of the data value labels for negative values.
Definition: KDChartDataValueAttributes.cpp:309
KDChartMarkerAttributes.h
KDChart::DataValueAttributes::DataValueAttributes
DataValueAttributes()
Definition: KDChartDataValueAttributes.cpp:97
KDChart::RelativePosition
Defines relative position information: reference area, position in this area (reference position),...
Definition: KDChartRelativePosition.h:58
KDChartEnums::MeasureCalculationModeAbsolute
@ MeasureCalculationModeAbsolute
Definition: KDChartEnums.h:222
KDChart::BackgroundAttributes
Set of attributes usable for background pixmaps.
Definition: KDChartBackgroundAttributes.h:37
KDChart::DataValueAttributes::setDecimalDigits
void setDecimalDigits(int digits)
Set how many decimal digits to display when rendering the data value labels.
Definition: KDChartDataValueAttributes.cpp:229
KDChart::DataValueAttributes::showOverlappingDataLabels
bool showOverlappingDataLabels() const
Definition: KDChartDataValueAttributes.cpp:279
KDChart::DataValueAttributes::setDataLabel
void setDataLabel(const QString label)
display a string label instead of the original data value label Supports HTML code.
Definition: KDChartDataValueAttributes.cpp:259
KDChart::DataValueAttributes::operator=
DataValueAttributes & operator=(const DataValueAttributes &)
Definition: KDChartDataValueAttributes.cpp:107
KDChart::FrameAttributes
A set of attributes for frames around items.
Definition: KDChartFrameAttributes.h:37
KDChartBackgroundAttributes.h
KDChartFrameAttributes.h
KDChart::DataValueAttributes::setMarkerAttributes
void setMarkerAttributes(const MarkerAttributes &a)
Set the marker attributes to use for the data values.
Definition: KDChartDataValueAttributes.cpp:199
KDCHART_DATA_VALUE_AUTO_DIGITS
#define KDCHART_DATA_VALUE_AUTO_DIGITS
Definition: KDChartDataValueAttributes.cpp:37
KDChartDataValueAttributes.h
Declaring the class KDChart::DataValueAttributes.
KDChartTextAttributes.h
KDChart::DataValueAttributes::textAttributes
TextAttributes textAttributes() const
Definition: KDChartDataValueAttributes.cpp:174
KDChart::DataValueAttributes::setUsePercentage
void setUsePercentage(bool enable)
Specify whether to use percentages instead of actual data point values when no specific label is set.
Definition: KDChartDataValueAttributes.cpp:219
KDChart::DataValueAttributes::isVisible
bool isVisible() const
Definition: KDChartDataValueAttributes.cpp:164
KDChart::DataValueAttributes::dataLabel
QString dataLabel() const
Returns the string displayed instead of the data value label.
Definition: KDChartDataValueAttributes.cpp:264
KDChart::DataValueAttributes::setPrefix
void setPrefix(const QString prefix)
Prepend a prefix string to the data value label.
Definition: KDChartDataValueAttributes.cpp:239
KDChart::DataValueAttributes::setVisible
void setVisible(bool visible)
Set whether data value labels should be displayed.
Definition: KDChartDataValueAttributes.cpp:159
KDChart::DataValueAttributes::defaultAttributes
static const DataValueAttributes & defaultAttributes()
Definition: KDChartDataValueAttributes.cpp:145
KDChart::DataValueAttributes
Diagram attributes dealing with data value labels.
Definition: KDChartDataValueAttributes.h:56
KDChartPosition.h
KDChartRelativePosition.h
KDChart::DataValueAttributes::setPositivePosition
void setPositivePosition(const RelativePosition &relPosition)
Defines the relative position of the data value labels for positive values.
Definition: KDChartDataValueAttributes.cpp:319
KDChart::DataValueAttributes::setTextAttributes
void setTextAttributes(const TextAttributes &a)
Set the text attributes to use for the data value labels.
Definition: KDChartDataValueAttributes.cpp:169
Unknown
@ Unknown
Definition: KDChartChart.cpp:307
d
#define d
Definition: KDChartDataValueAttributes.cpp:40
KDChart::DataValueAttributes::mirrorNegativeValueTextRotation
bool mirrorNegativeValueTextRotation() const
If true, rotation of negative value labels is negated, so that negative values are rotated in opposit...
Definition: KDChartDataValueAttributes.cpp:214

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/