KChart

KChartDataValueAttributes.cpp
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
21 
22 #include <QVariant>
23 #include <QDebug>
24 #include "KChartRelativePosition.h"
25 #include "KChartPosition.h"
26 #include "KChartMath_p.h"
27 #include <KChartTextAttributes.h>
28 #include <KChartFrameAttributes.h>
29 #include <KChartBackgroundAttributes.h>
30 #include <KChartMarkerAttributes.h>
31 
32 // FIXME till
33 #define KCHART_DATA_VALUE_AUTO_DIGITS 4
34 
35 
36 #define d d_func()
37 
38 using namespace KChart;
39 
40 class Q_DECL_HIDDEN DataValueAttributes::Private
41 {
42  friend class DataValueAttributes;
43 public:
44  Private();
45 private:
46  TextAttributes textAttributes;
47  FrameAttributes frameAttributes;
48  BackgroundAttributes backgroundAttributes;
49  MarkerAttributes markerAttributes;
50  QString prefix;
51  QString suffix;
52  QString dataLabel;
53  RelativePosition negativeRelPos;
54  RelativePosition positiveRelPos;
55  qint16 decimalDigits;
56  qint16 powerOfTenDivisor;
57  bool visible : 1;
58  bool showInfinite : 1;
59  bool showRepetitiveDataLabels : 1;
60  bool showOverlappingDataLabels : 1;
61  bool usePercentage : 1;
62  bool mirrorNegativeValueTextRotation : 1;
63 };
64 
65 DataValueAttributes::Private::Private() :
66  decimalDigits( KCHART_DATA_VALUE_AUTO_DIGITS ),
67  powerOfTenDivisor( 0 ),
68  visible( false ),
69  showInfinite( true )
70 {
71  Measure me( 20.0, KChartEnums::MeasureCalculationModeAuto, KChartEnums::MeasureOrientationAuto );
72  textAttributes.setFontSize( me );
73  me.setValue( 8.0 );
74  me.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
75  textAttributes.setMinimalFontSize( me );
76  textAttributes.setRotation( -45 );
77 
78  // we set the Position to unknown: so the diagrams can take their own decisions
79  positiveRelPos.setReferencePosition( Position::Unknown );
80  negativeRelPos.setReferencePosition( Position::Unknown );
81 
82  positiveRelPos.setAlignment( Qt::AlignTop | Qt::AlignRight );
83  negativeRelPos.setAlignment( Qt::AlignBottom | Qt::AlignRight );
84 
85  showRepetitiveDataLabels = false;
86  showOverlappingDataLabels = false;
87 
88  usePercentage = false;
89  mirrorNegativeValueTextRotation = false;
90 }
91 
92 
93 DataValueAttributes::DataValueAttributes()
94  : _d( new Private() )
95 {
96 }
97 
98 DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
99  : _d( new Private( *r.d ) )
100 {
101 }
102 
103 DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
104 {
105  if ( this == &r )
106  return *this;
107 
108  *d = *r.d;
109 
110  return *this;
111 }
112 
113 DataValueAttributes::~DataValueAttributes()
114 {
115  delete _d; _d = nullptr;
116 }
117 
118 
119 bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
120 {
121  return isVisible() == r.isVisible() &&
122  textAttributes() == r.textAttributes() &&
123  frameAttributes() == r.frameAttributes() &&
124  backgroundAttributes() == r.backgroundAttributes() &&
125  markerAttributes() == r.markerAttributes() &&
126  decimalDigits() == r.decimalDigits() &&
127  prefix() == r.prefix() &&
128  suffix() == r.suffix() &&
129  dataLabel() == r.dataLabel() &&
130  powerOfTenDivisor() == r.powerOfTenDivisor() &&
131  showInfinite() == r.showInfinite() &&
132  negativePosition() == r.negativePosition() &&
133  positivePosition() == r.positivePosition() &&
134  showRepetitiveDataLabels() == r.showRepetitiveDataLabels() &&
135  showOverlappingDataLabels() == r.showOverlappingDataLabels() &&
136  usePercentage() == r.usePercentage() &&
137  mirrorNegativeValueTextRotation() == r.mirrorNegativeValueTextRotation();
138 }
139 
140 /*static*/
141 const DataValueAttributes& DataValueAttributes::defaultAttributes()
142 {
143  static const DataValueAttributes theDefaultDataValueAttributes;
144  return theDefaultDataValueAttributes;
145 }
146 
147 /*static*/
148 const QVariant& DataValueAttributes::defaultAttributesAsVariant()
149 {
150  static const QVariant theDefaultDataValueAttributesVariant = QVariant::fromValue(defaultAttributes());
151  return theDefaultDataValueAttributesVariant;
152 }
153 
154 
156 {
157  d->visible = visible;
158 }
159 
161 {
162  return d->visible;
163 }
164 
166 {
167  d->textAttributes = a;
168 }
169 
171 {
172  return d->textAttributes;
173 }
174 
176 {
177  d->frameAttributes = a;
178 }
179 
181 {
182  return d->frameAttributes;
183 }
184 
186 {
187  d->backgroundAttributes = a;
188 }
189 
191 {
192  return d->backgroundAttributes;
193 }
194 
196 {
197  d->markerAttributes = a;
198 }
199 
201 {
202  return d->markerAttributes;
203 }
204 
206 {
207  d->mirrorNegativeValueTextRotation = enable;
208 }
209 
211 {
212  return d->mirrorNegativeValueTextRotation;
213 }
214 
216 {
217  d->usePercentage = enable;
218 }
219 
221 {
222  return d->usePercentage;
223 }
224 
226 {
227  d->decimalDigits = digits;
228 }
229 
231 {
232  return d->decimalDigits;
233 }
234 
235 void DataValueAttributes::setPrefix( const QString prefixString )
236 {
237  d->prefix = prefixString;
238 }
239 
241 {
242  return d->prefix;
243 }
244 
245 void DataValueAttributes::setSuffix( const QString suffixString )
246 {
247  d->suffix = suffixString;
248 }
249 
251 {
252  return d->suffix;
253 }
254 
256 {
257  d->dataLabel = label;
258 }
259 
261 {
262  return d->dataLabel;
263 }
264 
266 {
267  return d->showRepetitiveDataLabels;
268 }
269 
270 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
271 {
272  d->showRepetitiveDataLabels = showRepetitiveDataLabels;
273 }
274 
276 {
277  return d->showOverlappingDataLabels;
278 }
279 
280 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
281 {
282  d->showOverlappingDataLabels = showOverlappingDataLabels;
283 }
284 
285 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
286 {
287  d->powerOfTenDivisor = powerOfTenDivisor;
288 }
289 
290 int DataValueAttributes::powerOfTenDivisor() const
291 {
292  return d->powerOfTenDivisor;
293 }
294 
295 void DataValueAttributes::setShowInfinite( bool infinite )
296 {
297  d->showInfinite = infinite;
298 }
299 
300 bool DataValueAttributes::showInfinite() const
301 {
302  return d->showInfinite;
303 }
304 
306 {
307  d->negativeRelPos = relPosition;
308 }
309 
311 {
312  return d->negativeRelPos;
313 }
314 
316 {
317  d->positiveRelPos = relPosition;
318 }
319 
321 {
322  return d->positiveRelPos;
323 }
324 
325 #if !defined(QT_NO_DEBUG_STREAM)
327 {
328  dbg << "RelativePosition DataValueAttributes("
329  << "visible="<<val.isVisible()
330  << "textattributes="<<val.textAttributes()
331  << "frameattributes="<<val.frameAttributes()
332  << "backgroundattributes="<<val.backgroundAttributes()
333  << "decimaldigits="<<val.decimalDigits()
334  << "poweroftendivisor="<<val.powerOfTenDivisor()
335  << "showinfinite="<<val.showInfinite()
336  << "negativerelativeposition="<<val.negativePosition()
337  << "positiverelativeposition="<<val.positivePosition()
338  << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
339  << "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
340  <<")";
341  return dbg;
342 }
343 #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:48
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-2020 The KDE developers.
Generated on Tue Sep 29 2020 22:42:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.