~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kchart/kdchart/KDChartData.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C++ -*-
2
 
 
3
 
  $Id: KDChartData.h,v 1.5.2.2 2001/12/10 22:59:34 faure Exp $
4
 
 
5
 
  KDChart - a multi-platform charting engine
6
 
 
7
 
  Copyright (C) 2001 by Klar�lvdalens Datakonsult AB
8
 
*/
9
 
 
 
2
   KDChart - a multi-platform charting engine
 
3
   */
 
4
 
 
5
/****************************************************************************
 
6
 ** Copyright (C) 2001-2003 Klar�lvdalens Datakonsult AB.  All rights reserved.
 
7
 **
 
8
 ** This file is part of the KDChart library.
 
9
 **
 
10
 ** This file may be distributed and/or modified under the terms of the
 
11
 ** GNU General Public License version 2 as published by the Free Software
 
12
 ** Foundation and appearing in the file LICENSE.GPL included in the
 
13
 ** packaging of this file.
 
14
 **
 
15
 ** Licensees holding valid commercial KDChart licenses may use this file in
 
16
 ** accordance with the KDChart Commercial License Agreement provided with
 
17
 ** the Software.
 
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
 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
 
23
 **   information about KDChart Commercial License Agreements.
 
24
 **
 
25
 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
 
26
 ** licensing are not clear to you.
 
27
 **
 
28
 **********************************************************************/
10
29
#ifndef __KDCHARTDATA_H__
11
30
#define __KDCHARTDATA_H__
12
31
 
13
32
#include <qstring.h>
14
33
#include <qdatetime.h>
15
 
#ifdef unix
16
 
#include <values.h>
17
 
#else
18
 
#include <float.h>
19
 
#define MINDOUBLE DBL_MIN
20
 
#endif
 
34
 
 
35
 
 
36
#include "KDChartGlobal.h"
 
37
 
 
38
 
 
39
/**
 
40
  \file KDChartData.h
 
41
 
 
42
  \brief Provides a class to encapsulate one data value in a chart.
 
43
  */
 
44
 
21
45
 
22
46
// Please leave all methods in this class inline!
23
47
// It's necessary since it's part of the interface provided by KDChart
24
48
class KDChartData
25
49
{
26
 
public:
27
 
    enum ValueType { NoValue, String, Double, DateTime };
28
 
    KDChartData( double value ) :
29
 
        _valueType( Double ), dValue( value )
30
 
    {}
31
 
    KDChartData( const QString& value ) :
32
 
        _valueType( String ), sValue( value )
33
 
    {}
34
 
    KDChartData() :
35
 
            _valueType( NoValue )
36
 
    {}
37
 
 
38
 
    ValueType valueType() const
39
 
    {
40
 
        return _valueType;
41
 
    }
42
 
    bool hasValue() const
43
 
    {
44
 
        return _valueType != NoValue;
45
 
    }
46
 
    bool isString() const
47
 
    {
48
 
        return _valueType == String;
49
 
    }
50
 
    bool isDouble() const
51
 
    {
52
 
        return _valueType == Double;
53
 
    }
54
 
    bool isDateTime() const
55
 
    {
56
 
        return _valueType == DateTime;
57
 
    }
58
 
 
59
 
    bool operator==( const KDChartData& it ) const
60
 
    {
61
 
        bool bRet = hasValue() == it.hasValue();
62
 
        if ( bRet && hasValue() ) {
63
 
        bRet = valueType() == it.valueType();
64
 
            if ( bRet ) {
65
 
                switch ( valueType() ) {
66
 
                case String:
67
 
                    bRet = stringValue() == it.stringValue();
68
 
                    break;
69
 
                case Double:
70
 
                    bRet = doubleValue() == it.doubleValue();
71
 
                    break;
72
 
                case DateTime:
73
 
                    bRet = dateTimeValue()
74
 
                           == it.dateTimeValue();
75
 
                    break;
76
 
                default:
77
 
                    bRet = false;
78
 
                }
79
 
            }
80
 
        }
81
 
        return bRet;
82
 
    }
83
 
 
84
 
    void clearValue()
85
 
    {
86
 
        _valueType = NoValue;
87
 
    }
88
 
 
89
 
    QString stringValue() const
90
 
    {
91
 
        return isString() ? sValue : QString::null;
92
 
    }
93
 
    double doubleValue() const
94
 
    {
95
 
        return isDouble() ? dValue : MINDOUBLE;
96
 
    }
97
 
    QDateTime dateTimeValue() const
98
 
    {
99
 
        return isDateTime() ? dtValue : QDateTime();
100
 
    }
101
 
 
102
 
private:
103
 
    ValueType _valueType;
104
 
    QDateTime dtValue;
105
 
    double dValue;
106
 
    QString sValue; // dValue and sValue should be a union,
107
 
    // but QString has a non-default constructor
108
 
}
109
 
;
 
50
    public:
 
51
    // OK, so this is bad and should really be a static const
 
52
    // double. But then it is not possible to just use the KChart
 
53
    // interface without linking to KChart itself, because those
 
54
    // symbols would be missing.
 
55
#define POS_INFINITE DBL_MAX
 
56
#define NEG_INFINITE -DBL_MAX
 
57
 
 
58
        enum ValueType { NoValue, String, Double, DateTime };
 
59
 
 
60
        // 0. default c'tor: initializing all values as undefined
 
61
 
 
62
        KDChartData() :
 
63
            _valueType(  NoValue ),
 
64
        _valueType2( NoValue ),
 
65
        _propSetID(  0 )
 
66
        {}
 
67
 
 
68
        // 1. simple c'tors: used for 1-coordinate data
 
69
 
 
70
        KDChartData( double value ) :
 
71
            _valueType(  Double ), dValue( value ),
 
72
        _valueType2( NoValue ),
 
73
        _propSetID(  0 )
 
74
        {}
 
75
        /* string values are only supported for legend texts or axis labels */
 
76
        KDChartData( const QString& value ) :
 
77
            _valueType(  String ), sValue( value ),
 
78
        _valueType2( NoValue ),
 
79
        _propSetID(  0 )
 
80
        {}
 
81
        /* date/time values for /ordinate/ axes are not implemented yet
 
82
           KDChartData( QDateTime value ) :
 
83
           _valueType(  DateTime ), dtValue( value ),
 
84
           _valueType2( NoValue ),
 
85
           _propSetID(  0 )
 
86
           {}*/
 
87
 
 
88
        // 2. complex c'tors: used for 2-coordinate data
 
89
 
 
90
        // 2.a) with additional Date/Time: normally used when Date on x-axis
 
91
        //      e.g. for time related index numbers like water level measurements
 
92
        KDChartData( double yValue, QDateTime xValue ) :
 
93
            _valueType(  Double   ), dValue(   yValue  ),
 
94
        _valueType2( DateTime ), dtValue2( xValue ),
 
95
        _propSetID(  0 )
 
96
        {}
 
97
        /* date/time values for /ordinate/ axes are not implemented yet
 
98
           KDChartData( QDateTime yValue, QDateTime xValue ) :
 
99
           _valueType(  DateTime ), dtValue(  yValue  ),
 
100
           _valueType2( DateTime ), dtValue2( xValue ),
 
101
           _propSetID(  0 )
 
102
           {}*/
 
103
        // 2.b) with additional Double: may be used for mathematical data...
 
104
        KDChartData( double yValue, double xValue ) :
 
105
            _valueType(  Double ), dValue(  yValue  ),
 
106
        _valueType2( Double ), dValue2( xValue ),
 
107
        _propSetID(  0 )
 
108
        {}
 
109
        /* date/time values for /ordinate/ axes are not implemented yet
 
110
           KDChartData( QDateTime yValue, double xValue ) :
 
111
           _valueType(  DateTime ), dtValue( yValue  ),
 
112
           _valueType2( Double   ), dValue2( xValue ),
 
113
           _propSetID(  0 )
 
114
           {}*/
 
115
 
 
116
        ValueType valueType( int valNo=1 ) const
 
117
        {
 
118
            return (1 == valNo)
 
119
                ? _valueType
 
120
                : _valueType2;
 
121
        }
 
122
        bool hasValue( int valNo=1 ) const
 
123
        {
 
124
            return (1 == valNo)
 
125
                ? (_valueType != NoValue)
 
126
                : ((_valueType2 == Double) || (_valueType2 == DateTime));
 
127
        }
 
128
        /* string values are only supported for legend texts or axis labels */
 
129
        bool isString( int valNo=1 ) const
 
130
        {
 
131
            return (1 == valNo)
 
132
                ? (_valueType == String)
 
133
                : false;
 
134
        }
 
135
        bool isDouble( int valNo=1 ) const
 
136
        {
 
137
            return (1 == valNo)
 
138
                ? (_valueType == Double)
 
139
                : (_valueType2 == Double);
 
140
        }
 
141
        bool isNormalDouble( int valNo=1 ) const
 
142
        {
 
143
            if( !isDouble( valNo ) )
 
144
                return false;
 
145
            return doubleValue( valNo ) != POS_INFINITE
 
146
                && doubleValue( valNo ) != NEG_INFINITE;
 
147
        }
 
148
        bool isPosInfiniteDouble( int valNo=1 ) const
 
149
        {
 
150
            if( !isDouble( valNo ) )
 
151
                return false;
 
152
            return doubleValue( valNo ) == POS_INFINITE;
 
153
        }
 
154
        bool isNegInfiniteDouble( int valNo=1 ) const
 
155
        {
 
156
            if( !isDouble( valNo ) )
 
157
                return false;
 
158
            return doubleValue( valNo ) == NEG_INFINITE;
 
159
        }
 
160
        bool isDateTime( int valNo=1 ) const
 
161
        {
 
162
            return (1 == valNo)
 
163
                ? (_valueType == DateTime)
 
164
                : (_valueType2 == DateTime);
 
165
        }
 
166
 
 
167
 
 
168
        /**
 
169
          Assignment operator.
 
170
 
 
171
          \note The property set ID is <b>not</b> changed by the assignment operator.
 
172
          If you want to set it please call \c KDChartData::setPropertySet() explicitely.
 
173
          */
 
174
        KDChartData& operator=( const KDChartData& R )
 
175
        {
 
176
            if ( &R == this )
 
177
                return *this;
 
178
 
 
179
            _valueType  = R._valueType;
 
180
            _valueType2 = R._valueType2;
 
181
            switch ( valueType( 1 ) ) {
 
182
            case String:
 
183
                sValue  = R.sValue;
 
184
                break;
 
185
            case Double:
 
186
                dValue  = R.dValue;
 
187
                break;
 
188
            case DateTime:
 
189
                dtValue = R.dtValue;
 
190
                break;
 
191
            default:
 
192
                /* NOOP */;
 
193
            }
 
194
            switch ( valueType( 2 ) ) {
 
195
            // note: the 2nd value can not be a string
 
196
            //       - must be a date or a number!
 
197
            case Double:
 
198
                dValue2  = R.dValue2;
 
199
                break;
 
200
            case DateTime:
 
201
                dtValue2 = R.dtValue2;
 
202
                break;
 
203
            default:
 
204
                /* NOOP */;
 
205
            }
 
206
            // Note: We do *not* copy the _propSetID here since it contains
 
207
            //       no values but is used to handle some layout information...
 
208
            return *this;
 
209
        }
 
210
 
 
211
        KDChartData( const KDChartData& other ) {
 
212
            *this = other;
 
213
        }
 
214
 
 
215
        /**
 
216
          Compare operator.
 
217
 
 
218
          \note The property set ID is <b>not</b> taken into account while comparing.
 
219
          Two KDChartData are considered equal if their data values are equal - the
 
220
          property set ID is ignored.
 
221
          */
 
222
        bool operator==( const KDChartData& it ) const
 
223
        {
 
224
            bool bRet = (hasValue( 1 ) == it.hasValue( 1 )) &&
 
225
                (hasValue( 2 ) == it.hasValue( 2 ));
 
226
            if ( bRet && hasValue( 1 ) ) {
 
227
                bRet = valueType( 1 ) == it.valueType( 1 );
 
228
                if ( bRet ) {
 
229
                    switch ( valueType( 1 ) ) {
 
230
                        case String:
 
231
                            bRet = stringValue( 1 ) == it.stringValue( 1 );
 
232
                            break;
 
233
                        case Double:
 
234
                            bRet = doubleValue( 1 ) == it.doubleValue( 1 );
 
235
                            break;
 
236
                        case DateTime:
 
237
                            bRet = dateTimeValue( 1 ) == it.dateTimeValue( 1 );
 
238
                            break;
 
239
                        default:
 
240
                            bRet = false;
 
241
                    }
 
242
                }
 
243
                if ( bRet &&  hasValue( 2 ) ) {
 
244
                    bRet = valueType( 2 ) == it.valueType( 2 );
 
245
                    if ( bRet ) {
 
246
                        switch ( valueType( 2 ) ) {
 
247
                            // note: the 2nd value can not be a string
 
248
                            //       - must be a date or a number!
 
249
                            case Double:
 
250
                                bRet = doubleValue( 2 ) == it.doubleValue( 2 );
 
251
                                break;
 
252
                            case DateTime:
 
253
                                bRet = dateTimeValue( 2 ) == it.dateTimeValue( 2 );
 
254
                                break;
 
255
                            default:
 
256
                                bRet = false;
 
257
                        }
 
258
                    }
 
259
                }
 
260
                // Note: We do *not* compare the _propSetID here since it contains
 
261
                //       no values but is used to handle some layout information...
 
262
            }
 
263
            return bRet;
 
264
        }
 
265
 
 
266
        void clearValue()
 
267
        {
 
268
            _valueType  = NoValue;
 
269
            _valueType2 = NoValue;
 
270
            _propSetID  = 0;
 
271
        }
 
272
 
 
273
        /* string values are only supported for legend texts or axis labels */
 
274
        QString stringValue( int valNo=1 ) const
 
275
        {
 
276
            // note: the 2nd value can not be a string
 
277
            //       - must be a date or a number!
 
278
            if ((1 == valNo) && isString( valNo ))
 
279
                return sValue;
 
280
            else
 
281
                return QString::null;
 
282
        }
 
283
        double doubleValue( int valNo=1 ) const
 
284
        {
 
285
            return isDouble( valNo )
 
286
                ? ((1 == valNo) ? dValue : dValue2)
 
287
                : DBL_MIN;
 
288
        }
 
289
        QDateTime dateTimeValue( int valNo=1 ) const
 
290
        {
 
291
            return isDateTime( valNo )
 
292
                ? ((1 == valNo) ? dtValue : dtValue2)
 
293
                : QDateTime();
 
294
        }
 
295
 
 
296
        /**
 
297
          Assign a property set to a data cell.
 
298
 
 
299
          \param propSetID The ID of the property set to be assigned to this data cell.
 
300
          This ID can either be one of the built-in IDs documented
 
301
          at KDChartPropertySet::BuiltinDataPropertySetIDs or
 
302
          a special ID that was given back by a
 
303
          KDChartParams::registerProperties function call.
 
304
 
 
305
          \sa propertySet
 
306
          \sa KDChartParams::KDCHART_PROPSET_NORMAL_DATA, KDChartParams::KDCHART_PROPSET_TRANSPARENT_DATA
 
307
          */
 
308
        void setPropertySet( int propSetID = 0 )
 
309
        {
 
310
            _propSetID = propSetID;
 
311
        }
 
312
        /**
 
313
          Return the ID of the property set that is assigned to this data cell.
 
314
 
 
315
          Use KDChartParams::properties( int ID ) for accessing the respective property set information.
 
316
 
 
317
          \sa setPropertySet
 
318
          \sa KDChartParams::KDCHART_PROPSET_NORMAL_DATA, KDChartParams::KDCHART_PROPSET_TRANSPARENT_DATA
 
319
          */
 
320
        int propertySet() const
 
321
        {
 
322
            return _propSetID;
 
323
        }
 
324
 
 
325
 
 
326
    private:
 
327
        // OBLIGATORY 1st value: usually used for ordinate axis
 
328
        ValueType _valueType;
 
329
        QDateTime dtValue;
 
330
        double dValue;  // Sorry, d(t)Value and sValue cannot be a union,
 
331
        QString sValue; // since QString has a non-default constructor.
 
332
 
 
333
        // OPTIONAL 2nd value: if valid, normally used for abscissa axis
 
334
        // note: this 2nd value can not be a string - must be a date or a number!
 
335
        ValueType _valueType2;
 
336
        QDateTime dtValue2;
 
337
        double dValue2;
 
338
 
 
339
        // ID number of the property set assigned to this cell
 
340
        int _propSetID;
 
341
};
110
342
 
111
343
#endif