~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kchart/kdchart/src/KDChartDataValueAttributes.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 ** Copyright (C) 2007 Klarälvdalens Datakonsult AB.  All rights reserved.
3
 
 **
4
 
 ** This file is part of the KD Chart library.
5
 
 **
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).
13
 
 ** 
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.
18
 
 ** 
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.
21
 
 **
22
 
 **********************************************************************/
23
 
 
24
 
#include "KDChartDataValueAttributes.h"
25
 
 
26
 
#include <QVariant>
27
 
#include <QDebug>
28
 
#include "KDChartRelativePosition.h"
29
 
#include "KDChartPosition.h"
30
 
#include <KDChartTextAttributes.h>
31
 
#include <KDChartFrameAttributes.h>
32
 
#include <KDChartBackgroundAttributes.h>
33
 
#include <KDChartMarkerAttributes.h>
34
 
 
35
 
#include <KDABLibFakes>
36
 
 
37
 
// FIXME till
38
 
#define KDCHART_DATA_VALUE_AUTO_DIGITS 4
39
 
 
40
 
 
41
 
#define d d_func()
42
 
 
43
 
using namespace KDChart;
44
 
 
45
 
class DataValueAttributes::Private
46
 
{
47
 
    friend class DataValueAttributes;
48
 
public:
49
 
    Private();
50
 
private:
51
 
    bool visible;
52
 
    TextAttributes textAttributes;
53
 
    FrameAttributes frameAttributes;
54
 
    BackgroundAttributes backgroundAttributes;
55
 
    MarkerAttributes markerAttributes;
56
 
    int decimalDigits;
57
 
    QString prefix;
58
 
    QString suffix;
59
 
    QString dataLabel;
60
 
    int powerOfTenDivisor;
61
 
    bool showInfinite;
62
 
    RelativePosition negativeRelPos;
63
 
    RelativePosition positiveRelPos;
64
 
    bool showRepetitiveDataLabels;
65
 
    bool showOverlappingDataLabels;
66
 
};
67
 
 
68
 
DataValueAttributes::Private::Private() :
69
 
    visible( false ),
70
 
    decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ),
71
 
    powerOfTenDivisor( 0 ),
72
 
    showInfinite( true )
73
 
{
74
 
    Measure me( 25.0,
75
 
                KDChartEnums::MeasureCalculationModeAuto,
76
 
                KDChartEnums::MeasureOrientationAuto );
77
 
    textAttributes.setFontSize( me );
78
 
    me.setValue( 8.0 );
79
 
    me.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
80
 
    textAttributes.setMinimalFontSize( me );
81
 
    textAttributes.setRotation( -45 );
82
 
 
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
86
 
 
87
 
    positiveRelPos.setAlignment( Qt::AlignLeft  | Qt::AlignBottom );
88
 
    negativeRelPos.setAlignment( Qt::AlignRight | Qt::AlignTop );
89
 
 
90
 
    showRepetitiveDataLabels = false;
91
 
    showOverlappingDataLabels = false;
92
 
 
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 );
106
 
}
107
 
 
108
 
 
109
 
DataValueAttributes::DataValueAttributes()
110
 
    : _d( new Private() )
111
 
{
112
 
}
113
 
 
114
 
DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
115
 
    : _d( new Private( *r.d ) )
116
 
{
117
 
}
118
 
 
119
 
DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
120
 
{
121
 
    if( this == &r )
122
 
        return *this;
123
 
 
124
 
    *d = *r.d;
125
 
 
126
 
    return *this;
127
 
}
128
 
 
129
 
DataValueAttributes::~DataValueAttributes()
130
 
{
131
 
    delete _d; _d = 0;
132
 
}
133
 
 
134
 
 
135
 
bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
136
 
{
137
 
    /*
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());
154
 
    */
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() );
170
 
}
171
 
 
172
 
/*static*/
173
 
const DataValueAttributes& DataValueAttributes::defaultAttributes()
174
 
{
175
 
    static const DataValueAttributes theDefaultDataValueAttributes;
176
 
    return theDefaultDataValueAttributes;
177
 
}
178
 
 
179
 
/*static*/
180
 
const QVariant& DataValueAttributes::defaultAttributesAsVariant()
181
 
{
182
 
    static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes());
183
 
    return theDefaultDataValueAttributesVariant;
184
 
}
185
 
 
186
 
 
187
 
void DataValueAttributes::setVisible( bool visible )
188
 
{
189
 
    d->visible = visible;
190
 
}
191
 
 
192
 
bool DataValueAttributes::isVisible() const
193
 
{
194
 
    return d->visible;
195
 
}
196
 
 
197
 
void DataValueAttributes::setTextAttributes( const TextAttributes &a )
198
 
{
199
 
    d->textAttributes = a;
200
 
}
201
 
 
202
 
TextAttributes DataValueAttributes::textAttributes() const
203
 
{
204
 
    return d->textAttributes;
205
 
}
206
 
 
207
 
void DataValueAttributes::setFrameAttributes( const FrameAttributes &a )
208
 
{
209
 
    d->frameAttributes = a;
210
 
}
211
 
 
212
 
FrameAttributes DataValueAttributes::frameAttributes() const
213
 
{
214
 
    return d->frameAttributes;
215
 
}
216
 
 
217
 
void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a )
218
 
{
219
 
    d->backgroundAttributes = a;
220
 
}
221
 
 
222
 
BackgroundAttributes DataValueAttributes::backgroundAttributes() const
223
 
{
224
 
    return d->backgroundAttributes;
225
 
}
226
 
 
227
 
void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a )
228
 
{
229
 
    d->markerAttributes = a;
230
 
}
231
 
 
232
 
MarkerAttributes DataValueAttributes::markerAttributes() const
233
 
{
234
 
    return d->markerAttributes;
235
 
}
236
 
 
237
 
 
238
 
void DataValueAttributes::setDecimalDigits( int digits )
239
 
{
240
 
    d->decimalDigits = digits;
241
 
}
242
 
 
243
 
int DataValueAttributes::decimalDigits() const
244
 
{
245
 
    return d->decimalDigits;
246
 
}
247
 
 
248
 
void DataValueAttributes::setPrefix( const QString prefixString )
249
 
{
250
 
    d->prefix = prefixString;
251
 
}
252
 
 
253
 
QString DataValueAttributes::prefix() const
254
 
{
255
 
    return d->prefix;
256
 
}
257
 
 
258
 
void DataValueAttributes::setSuffix( const QString suffixString )
259
 
{
260
 
    d->suffix  = suffixString;
261
 
}
262
 
 
263
 
QString DataValueAttributes::suffix() const
264
 
{
265
 
    return d->suffix;
266
 
}
267
 
 
268
 
void DataValueAttributes::setDataLabel( const QString label )
269
 
{
270
 
    d->dataLabel =  label;
271
 
}
272
 
 
273
 
QString DataValueAttributes::dataLabel() const
274
 
{
275
 
    return d->dataLabel;
276
 
}
277
 
 
278
 
bool DataValueAttributes::showRepetitiveDataLabels() const
279
 
{
280
 
    return d->showRepetitiveDataLabels;
281
 
}
282
 
 
283
 
void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
284
 
{
285
 
    d->showRepetitiveDataLabels = showRepetitiveDataLabels;
286
 
}
287
 
 
288
 
bool DataValueAttributes::showOverlappingDataLabels() const
289
 
{
290
 
    return d->showOverlappingDataLabels;
291
 
}
292
 
 
293
 
void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
294
 
{
295
 
    d->showOverlappingDataLabels = showOverlappingDataLabels;
296
 
}
297
 
 
298
 
void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
299
 
{
300
 
    d->powerOfTenDivisor = powerOfTenDivisor;
301
 
}
302
 
 
303
 
int DataValueAttributes::powerOfTenDivisor() const
304
 
{
305
 
    return d->powerOfTenDivisor;
306
 
}
307
 
 
308
 
void DataValueAttributes::setShowInfinite( bool infinite )
309
 
{
310
 
    d->showInfinite = infinite;
311
 
}
312
 
 
313
 
bool DataValueAttributes::showInfinite() const
314
 
{
315
 
    return d->showInfinite;
316
 
}
317
 
 
318
 
void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition )
319
 
{
320
 
    d->negativeRelPos = relPosition;
321
 
}
322
 
 
323
 
const RelativePosition DataValueAttributes::negativePosition() const
324
 
{
325
 
    return d->negativeRelPos;
326
 
}
327
 
 
328
 
void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition )
329
 
{
330
 
    d->positiveRelPos = relPosition;
331
 
}
332
 
 
333
 
const RelativePosition DataValueAttributes::positivePosition() const
334
 
{
335
 
    return d->positiveRelPos;
336
 
}
337
 
 
338
 
#if !defined(QT_NO_DEBUG_STREAM)
339
 
QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val )
340
 
{
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()
353
 
    <<")";
354
 
    return dbg;
355
 
}
356
 
#endif /* QT_NO_DEBUG_STREAM */