3
$Id: KDChartData.h,v 1.5.2.2 2001/12/10 22:59:34 faure Exp $
5
KDChart - a multi-platform charting engine
7
Copyright (C) 2001 by Klar�lvdalens Datakonsult AB
2
KDChart - a multi-platform charting engine
5
/****************************************************************************
6
** Copyright (C) 2001-2003 Klar�lvdalens Datakonsult AB. All rights reserved.
8
** This file is part of the KDChart library.
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.
15
** Licensees holding valid commercial KDChart licenses may use this file in
16
** accordance with the KDChart Commercial License Agreement provided with
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
** See http://www.klaralvdalens-datakonsult.se/?page=products for
23
** information about KDChart Commercial License Agreements.
25
** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26
** licensing are not clear to you.
28
**********************************************************************/
10
29
#ifndef __KDCHARTDATA_H__
11
30
#define __KDCHARTDATA_H__
13
32
#include <qstring.h>
14
33
#include <qdatetime.h>
19
#define MINDOUBLE DBL_MIN
36
#include "KDChartGlobal.h"
42
\brief Provides a class to encapsulate one data value in a chart.
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
27
enum ValueType { NoValue, String, Double, DateTime };
28
KDChartData( double value ) :
29
_valueType( Double ), dValue( value )
31
KDChartData( const QString& value ) :
32
_valueType( String ), sValue( value )
38
ValueType valueType() const
44
return _valueType != NoValue;
48
return _valueType == String;
52
return _valueType == Double;
54
bool isDateTime() const
56
return _valueType == DateTime;
59
bool operator==( const KDChartData& it ) const
61
bool bRet = hasValue() == it.hasValue();
62
if ( bRet && hasValue() ) {
63
bRet = valueType() == it.valueType();
65
switch ( valueType() ) {
67
bRet = stringValue() == it.stringValue();
70
bRet = doubleValue() == it.doubleValue();
73
bRet = dateTimeValue()
74
== it.dateTimeValue();
89
QString stringValue() const
91
return isString() ? sValue : QString::null;
93
double doubleValue() const
95
return isDouble() ? dValue : MINDOUBLE;
97
QDateTime dateTimeValue() const
99
return isDateTime() ? dtValue : QDateTime();
103
ValueType _valueType;
106
QString sValue; // dValue and sValue should be a union,
107
// but QString has a non-default constructor
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
58
enum ValueType { NoValue, String, Double, DateTime };
60
// 0. default c'tor: initializing all values as undefined
63
_valueType( NoValue ),
64
_valueType2( NoValue ),
68
// 1. simple c'tors: used for 1-coordinate data
70
KDChartData( double value ) :
71
_valueType( Double ), dValue( value ),
72
_valueType2( NoValue ),
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 ),
81
/* date/time values for /ordinate/ axes are not implemented yet
82
KDChartData( QDateTime value ) :
83
_valueType( DateTime ), dtValue( value ),
84
_valueType2( NoValue ),
88
// 2. complex c'tors: used for 2-coordinate data
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 ),
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 ),
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 ),
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 ),
116
ValueType valueType( int valNo=1 ) const
122
bool hasValue( int valNo=1 ) const
125
? (_valueType != NoValue)
126
: ((_valueType2 == Double) || (_valueType2 == DateTime));
128
/* string values are only supported for legend texts or axis labels */
129
bool isString( int valNo=1 ) const
132
? (_valueType == String)
135
bool isDouble( int valNo=1 ) const
138
? (_valueType == Double)
139
: (_valueType2 == Double);
141
bool isNormalDouble( int valNo=1 ) const
143
if( !isDouble( valNo ) )
145
return doubleValue( valNo ) != POS_INFINITE
146
&& doubleValue( valNo ) != NEG_INFINITE;
148
bool isPosInfiniteDouble( int valNo=1 ) const
150
if( !isDouble( valNo ) )
152
return doubleValue( valNo ) == POS_INFINITE;
154
bool isNegInfiniteDouble( int valNo=1 ) const
156
if( !isDouble( valNo ) )
158
return doubleValue( valNo ) == NEG_INFINITE;
160
bool isDateTime( int valNo=1 ) const
163
? (_valueType == DateTime)
164
: (_valueType2 == DateTime);
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.
174
KDChartData& operator=( const KDChartData& R )
179
_valueType = R._valueType;
180
_valueType2 = R._valueType2;
181
switch ( valueType( 1 ) ) {
194
switch ( valueType( 2 ) ) {
195
// note: the 2nd value can not be a string
196
// - must be a date or a number!
201
dtValue2 = R.dtValue2;
206
// Note: We do *not* copy the _propSetID here since it contains
207
// no values but is used to handle some layout information...
211
KDChartData( const KDChartData& other ) {
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.
222
bool operator==( const KDChartData& it ) const
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 );
229
switch ( valueType( 1 ) ) {
231
bRet = stringValue( 1 ) == it.stringValue( 1 );
234
bRet = doubleValue( 1 ) == it.doubleValue( 1 );
237
bRet = dateTimeValue( 1 ) == it.dateTimeValue( 1 );
243
if ( bRet && hasValue( 2 ) ) {
244
bRet = valueType( 2 ) == it.valueType( 2 );
246
switch ( valueType( 2 ) ) {
247
// note: the 2nd value can not be a string
248
// - must be a date or a number!
250
bRet = doubleValue( 2 ) == it.doubleValue( 2 );
253
bRet = dateTimeValue( 2 ) == it.dateTimeValue( 2 );
260
// Note: We do *not* compare the _propSetID here since it contains
261
// no values but is used to handle some layout information...
268
_valueType = NoValue;
269
_valueType2 = NoValue;
273
/* string values are only supported for legend texts or axis labels */
274
QString stringValue( int valNo=1 ) const
276
// note: the 2nd value can not be a string
277
// - must be a date or a number!
278
if ((1 == valNo) && isString( valNo ))
281
return QString::null;
283
double doubleValue( int valNo=1 ) const
285
return isDouble( valNo )
286
? ((1 == valNo) ? dValue : dValue2)
289
QDateTime dateTimeValue( int valNo=1 ) const
291
return isDateTime( valNo )
292
? ((1 == valNo) ? dtValue : dtValue2)
297
Assign a property set to a data cell.
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.
306
\sa KDChartParams::KDCHART_PROPSET_NORMAL_DATA, KDChartParams::KDCHART_PROPSET_TRANSPARENT_DATA
308
void setPropertySet( int propSetID = 0 )
310
_propSetID = propSetID;
313
Return the ID of the property set that is assigned to this data cell.
315
Use KDChartParams::properties( int ID ) for accessing the respective property set information.
318
\sa KDChartParams::KDCHART_PROPSET_NORMAL_DATA, KDChartParams::KDCHART_PROPSET_TRANSPARENT_DATA
320
int propertySet() const
327
// OBLIGATORY 1st value: usually used for ordinate axis
328
ValueType _valueType;
330
double dValue; // Sorry, d(t)Value and sValue cannot be a union,
331
QString sValue; // since QString has a non-default constructor.
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;
339
// ID number of the property set assigned to this cell