1
/****************************************************************************
2
** Copyright (C) 2007 Klarälvdalens Datakonsult AB. All rights reserved.
4
** This file is part of the KD Chart library.
6
** This file may be used under the terms of the GNU General Public
7
** License versions 2.0 or 3.0 as published by the Free Software
8
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
9
** included in the packaging of this file. Alternatively you may (at
10
** your option) use any later version of the GNU General Public
11
** License if such license has been publicly approved by
12
** Klarälvdalens Datakonsult AB (or its successors, if any).
14
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
15
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
16
** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
17
** not expressly granted herein.
19
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22
**********************************************************************/
24
#include "KDChartDataValueAttributes.h"
28
#include "KDChartRelativePosition.h"
29
#include "KDChartPosition.h"
30
#include <KDChartTextAttributes.h>
31
#include <KDChartFrameAttributes.h>
32
#include <KDChartBackgroundAttributes.h>
33
#include <KDChartMarkerAttributes.h>
35
#include <KDABLibFakes>
38
#define KDCHART_DATA_VALUE_AUTO_DIGITS 4
43
using namespace KDChart;
45
class DataValueAttributes::Private
47
friend class DataValueAttributes;
52
TextAttributes textAttributes;
53
FrameAttributes frameAttributes;
54
BackgroundAttributes backgroundAttributes;
55
MarkerAttributes markerAttributes;
60
int powerOfTenDivisor;
62
RelativePosition negativeRelPos;
63
RelativePosition positiveRelPos;
64
bool showRepetitiveDataLabels;
65
bool showOverlappingDataLabels;
68
DataValueAttributes::Private::Private() :
70
decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ),
71
powerOfTenDivisor( 0 ),
75
KDChartEnums::MeasureCalculationModeAuto,
76
KDChartEnums::MeasureOrientationAuto );
77
textAttributes.setFontSize( me );
79
me.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
80
textAttributes.setMinimalFontSize( me );
81
textAttributes.setRotation( -45 );
83
// we set the Position to unknown: so the diagrams can take their own decisions
84
positiveRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::NorthWest
85
negativeRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::SouthEast
87
positiveRelPos.setAlignment( Qt::AlignLeft | Qt::AlignBottom );
88
negativeRelPos.setAlignment( Qt::AlignRight | Qt::AlignTop );
90
showRepetitiveDataLabels = false;
91
showOverlappingDataLabels = false;
93
// By default use 0.4 (or 0.5, resp.) of the font height as horizontal distance between
94
// the data and their respective data value texts,
95
// and use 0.75 as the vertical distance.
96
const double posHoriPadding = 400.0; const double posVertPadding = -75.0;
97
const double negHoriPadding = -500.0; const double negVertPadding = 75.0;
98
Measure m( posHoriPadding, KDChartEnums::MeasureCalculationModeAuto );
99
positiveRelPos.setHorizontalPadding( m );
100
m.setValue( posVertPadding );
101
positiveRelPos.setVerticalPadding( m );
102
m.setValue( negHoriPadding );
103
negativeRelPos.setHorizontalPadding( m );
104
m.setValue( negVertPadding );
105
negativeRelPos.setVerticalPadding( m );
109
DataValueAttributes::DataValueAttributes()
110
: _d( new Private() )
114
DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
115
: _d( new Private( *r.d ) )
119
DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
129
DataValueAttributes::~DataValueAttributes()
135
bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
138
qDebug() << "DataValueAttributes::operator== finds"
139
<< "b" << (isVisible() == r.isVisible())
140
<< "c" << (textAttributes() == r.textAttributes())
141
<< "d" << (frameAttributes() == r.frameAttributes())
142
<< "e" << (backgroundAttributes() == r.backgroundAttributes())
143
<< "f" << (markerAttributes() == r.markerAttributes())
144
<< "g" << (decimalDigits() == r.decimalDigits())
145
<< "h" << (prefix() == r.prefix())
146
<< "i" << (suffix() == r.suffix())
147
<< "j" << (dataLabel() == r.dataLabel())
148
<< "k" << (powerOfTenDivisor() == r.powerOfTenDivisor())
149
<< "l" << (showInfinite() == r.showInfinite())
150
<< "m" << (negativePosition() == r.negativePosition())
151
<< "n" << (positivePosition() == r.positivePosition())
152
<< "o" << (showRepetitiveDataLabels() == r.showRepetitiveDataLabels())
153
<< "p" << (showOverlappingDataLabels() == r.showOverlappingDataLabels());
155
return ( isVisible() == r.isVisible() &&
156
textAttributes() == r.textAttributes() &&
157
frameAttributes() == r.frameAttributes() &&
158
backgroundAttributes() == r.backgroundAttributes() &&
159
markerAttributes() == r.markerAttributes() &&
160
decimalDigits() == r.decimalDigits() &&
161
prefix() == r.prefix() &&
162
suffix() == r.suffix() &&
163
dataLabel() == r.dataLabel() &&
164
powerOfTenDivisor() == r.powerOfTenDivisor() &&
165
showInfinite() == r.showInfinite() &&
166
negativePosition() == r.negativePosition() &&
167
positivePosition() == r.positivePosition() &&
168
showRepetitiveDataLabels() == r.showRepetitiveDataLabels() &&
169
showOverlappingDataLabels() == r.showOverlappingDataLabels() );
173
const DataValueAttributes& DataValueAttributes::defaultAttributes()
175
static const DataValueAttributes theDefaultDataValueAttributes;
176
return theDefaultDataValueAttributes;
180
const QVariant& DataValueAttributes::defaultAttributesAsVariant()
182
static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes());
183
return theDefaultDataValueAttributesVariant;
187
void DataValueAttributes::setVisible( bool visible )
189
d->visible = visible;
192
bool DataValueAttributes::isVisible() const
197
void DataValueAttributes::setTextAttributes( const TextAttributes &a )
199
d->textAttributes = a;
202
TextAttributes DataValueAttributes::textAttributes() const
204
return d->textAttributes;
207
void DataValueAttributes::setFrameAttributes( const FrameAttributes &a )
209
d->frameAttributes = a;
212
FrameAttributes DataValueAttributes::frameAttributes() const
214
return d->frameAttributes;
217
void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a )
219
d->backgroundAttributes = a;
222
BackgroundAttributes DataValueAttributes::backgroundAttributes() const
224
return d->backgroundAttributes;
227
void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a )
229
d->markerAttributes = a;
232
MarkerAttributes DataValueAttributes::markerAttributes() const
234
return d->markerAttributes;
238
void DataValueAttributes::setDecimalDigits( int digits )
240
d->decimalDigits = digits;
243
int DataValueAttributes::decimalDigits() const
245
return d->decimalDigits;
248
void DataValueAttributes::setPrefix( const QString prefixString )
250
d->prefix = prefixString;
253
QString DataValueAttributes::prefix() const
258
void DataValueAttributes::setSuffix( const QString suffixString )
260
d->suffix = suffixString;
263
QString DataValueAttributes::suffix() const
268
void DataValueAttributes::setDataLabel( const QString label )
270
d->dataLabel = label;
273
QString DataValueAttributes::dataLabel() const
278
bool DataValueAttributes::showRepetitiveDataLabels() const
280
return d->showRepetitiveDataLabels;
283
void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
285
d->showRepetitiveDataLabels = showRepetitiveDataLabels;
288
bool DataValueAttributes::showOverlappingDataLabels() const
290
return d->showOverlappingDataLabels;
293
void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
295
d->showOverlappingDataLabels = showOverlappingDataLabels;
298
void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
300
d->powerOfTenDivisor = powerOfTenDivisor;
303
int DataValueAttributes::powerOfTenDivisor() const
305
return d->powerOfTenDivisor;
308
void DataValueAttributes::setShowInfinite( bool infinite )
310
d->showInfinite = infinite;
313
bool DataValueAttributes::showInfinite() const
315
return d->showInfinite;
318
void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition )
320
d->negativeRelPos = relPosition;
323
const RelativePosition DataValueAttributes::negativePosition() const
325
return d->negativeRelPos;
328
void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition )
330
d->positiveRelPos = relPosition;
333
const RelativePosition DataValueAttributes::positivePosition() const
335
return d->positiveRelPos;
338
#if !defined(QT_NO_DEBUG_STREAM)
339
QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val )
341
dbg << "RelativePosition DataValueAttributes("
342
<< "visible="<<val.isVisible()
343
<< "textattributes="<<val.textAttributes()
344
<< "frameattributes="<<val.frameAttributes()
345
<< "backgroundattributes="<<val.backgroundAttributes()
346
<< "decimaldigits="<<val.decimalDigits()
347
<< "poweroftendivisor="<<val.powerOfTenDivisor()
348
<< "showinfinite="<<val.showInfinite()
349
<< "negativerelativeposition="<<val.negativePosition()
350
<< "positiverelativeposition="<<val.positivePosition()
351
<< "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
352
<< "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
356
#endif /* QT_NO_DEBUG_STREAM */