1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/* -*- Mode: C++ -*-
KDChart - a multi-platform charting engine
*/
/****************************************************************************
** Copyright (C) 2001-2003 Klar�vdalens Datakonsult AB. All rights reserved.
**
** This file is part of the KDChart library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KDChart licenses may use this file in
** accordance with the KDChart Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.klaralvdalens-datakonsult.se/?page=products for
** information about KDChart Commercial License Agreements.
**
** Contact [email protected] if any conditions of this
** licensing are not clear to you.
**
**********************************************************************/
#ifndef __KDCHARTDATAINTERN_H__
#define __KDCHARTDATAINTERN_H__
#include <tqvariant.h>
#include <tqstring.h>
#include <tqdatetime.h>
#include "KDChartGlobal.h"
/**
\file KDChartData.h
\brief Provides a class to encapsulate one data value in a chart.
*/
// Please leave all methods in this class inline!
// It's necessary since it's part of the interface provided by KDChart
class KDCHART_EXPORT KDChartData
{
public:
// 0. default c'tor: initializing all values as undefined
KDChartData() :
_valueType( TQVariant::Invalid ),
_valueType2( TQVariant::Invalid ),
_propSetID( 0 )
{}
// 1. simple c'tors: used for 1-coordinate data
KDChartData( double value ) :
_valueType( TQVariant::Double ), dValue( value ),
_valueType2( TQVariant::Invalid ),
_propSetID( 0 )
{}
/* string values are only supported for legend texts or axis labels */
KDChartData( const TQString& value ) :
_valueType( TQVariant::String ), sValue( value ),
_valueType2( TQVariant::Invalid ),
_propSetID( 0 )
{}
/* date/time values for /ordinate/ axes are not implemented yet
KDChartData( TQDateTime value ) :
_valueType( TQVariant::DateTime ), dtValue( value ),
_valueType2( TQVariant::Invalid ),
_propSetID( 0 )
{}*/
// 2. complex c'tors: used for 2-coordinate data
// 2.a) with additional Date/Time: normally used when Date on x-axis
// e.g. for time related index numbers like water level measurements
KDChartData( double yValue, TQDateTime xValue ) :
_valueType( TQVariant::Double ), dValue( yValue ),
_valueType2( TQVariant::DateTime ), dtValue2( xValue ),
_propSetID( 0 )
{}
KDChartData( const TQVariant& _value1,
const TQVariant& _value2 )
{
switch( _value1.type() ){
case TQVariant::Int:
case TQVariant::UInt:
case TQVariant::Double:
_valueType = TQVariant::Double;
dValue = _value1.toDouble();
break;
case TQVariant::DateTime:
_valueType = TQVariant::DateTime;
dtValue = _value1.toDateTime();
break;
case TQVariant::String:
_valueType = TQVariant::String;
sValue = _value1.toString();
break;
default:
_valueType = TQVariant::Invalid;
}
switch( _value2.type() ){
case TQVariant::Int:
case TQVariant::UInt:
case TQVariant::Double:
_valueType2 = TQVariant::Double;
dValue2 = _value2.toDouble();
break;
case TQVariant::DateTime:
_valueType2 = TQVariant::DateTime;
dtValue2 = _value2.toDateTime();
break;
default:
_valueType2 = TQVariant::Invalid;
}
_propSetID = 0;
}
/* date/time values for /ordinate/ axes are not implemented yet
KDChartData( TQDateTime yValue, TQDateTime xValue ) :
_valueType( DateTime ), dtValue( yValue ),
_valueType2( DateTime ), dtValue2( xValue ),
_propSetID( 0 )
{}*/
// 2.b) with additional Double: may be used for mathematical data...
KDChartData( double yValue, double xValue ) :
_valueType( TQVariant::Double ), dValue( yValue ),
_valueType2( TQVariant::Double ), dValue2( xValue ),
_propSetID( 0 )
{}
/* date/time values for /ordinate/ axes are not implemented yet
KDChartData( TQDateTime yValue, double xValue ) :
_valueType( DateTime ), dtValue( yValue ),
_valueType2( Double ), dValue2( xValue ),
_propSetID( 0 )
{}*/
/*
/-**
Copy constructor.
\sa setData
* /
KDChartData( const KDChartData& other ) :
{
setData( other );
}
/-**
Assignment operator.
\sa setData
* /
KDChartData& operator=( const KDChartData& R )
{
setData( R );
return *this;
}
*/
/**
Compare operator.
\sa isEqual
*/
bool operator==( const KDChartData& it ) const
{
return isEqual(*this, it);
}
/**
Compare operator.
\sa isEqual
*/
bool operator!=( const KDChartData& it ) const
{
return !isEqual(*this, it);
}
/**
Compare method.
\note The property set ID is <b>not</b> taken into account while comparing.
Two KDChartData are considered equal if their data values are equal - the
property set ID is ignored.
*/
bool isEqual( const KDChartData& a, const KDChartData& b ) const
{
bool bRet = (a.hasValue( 1 ) == b.hasValue( 1 )) &&
(a.hasValue( 2 ) == b.hasValue( 2 ));
if ( bRet && a.hasValue( 1 ) ) {
bRet = a.valueType( 1 ) == b.valueType( 1 );
if ( bRet ) {
switch ( a.valueType( 1 ) ) {
case TQVariant::String:
bRet = a.stringValue( 1 ) == b.stringValue( 1 );
break;
case TQVariant::Double:
bRet = a.doubleValue( 1 ) == b.doubleValue( 1 );
break;
case TQVariant::DateTime:
bRet = a.dateTimeValue( 1 ) == b.dateTimeValue( 1 );
break;
default:
bRet = false;
}
}
if ( bRet && a.hasValue( 2 ) ) {
bRet = a.valueType( 2 ) == b.valueType( 2 );
if ( bRet ) {
switch ( a.valueType( 2 ) ) {
// note: the 2nd value can not be a string
// - must be a date or a number!
case TQVariant::Double:
bRet = a.doubleValue( 2 ) == b.doubleValue( 2 );
break;
case TQVariant::DateTime:
bRet = a.dateTimeValue( 2 ) == b.dateTimeValue( 2 );
break;
default:
bRet = false;
}
}
}
// Note: We do *not* compare the _propSetID here since it contains
// no values but is used to handle some tqlayout information...
}
return bRet;
}
/**
Method setAll.
\note The property set ID is <b>also</b> changed by the setAll method.
\sa setData
*/
void setAll( const KDChartData& R )
{
setData( R );
setPropertySet( R.propertySet() );
}
/**
Method setData.
\note The property set ID is <b>not</b> changed by the setData method.
If you want to set it please call \c KDChartData::setPropertySet() explicitely.
\sa setAll
*/
void setData( const KDChartData& R )
{
if( &R != this ){
_valueType = R._valueType;
_valueType2 = R._valueType2;
switch ( valueType( 1 ) ) {
case TQVariant::String:
sValue = R.sValue;
break;
case TQVariant::Double:
dValue = R.dValue;
break;
case TQVariant::DateTime:
dtValue = R.dtValue;
break;
default:
/* NOOP */;
}
switch ( valueType( 2 ) ) {
// note: the 2nd value can not be a string
// - must be a date or a number!
case TQVariant::Double:
dValue2 = R.dValue2;
break;
case TQVariant::DateTime:
dtValue2 = R.dtValue2;
break;
default:
/* NOOP */;
}
// Note: We do *not* copy the _propSetID here since it contains
// no values but is used to handle some tqlayout information...
}
}
TQVariant::Type valueType( int valNo=1 ) const
{
return (1 == valNo)
? _valueType
: _valueType2;
}
bool hasValue( int valNo=1 ) const
{
return (1 == valNo)
? (_valueType != TQVariant::Invalid)
: ((_valueType2 == TQVariant::Double) || (_valueType2 == TQVariant::DateTime));
}
/* string values are only supported for legend texts or axis labels */
bool isString( int valNo=1 ) const
{
return (1 == valNo)
? (_valueType == TQVariant::String)
: false;
}
bool isDouble( int valNo=1 ) const
{
return (1 == valNo)
? (_valueType == TQVariant::Double)
: (_valueType2 == TQVariant::Double);
}
bool isDateTime( int valNo=1 ) const
{
return (1 == valNo)
? (_valueType == TQVariant::DateTime)
: (_valueType2 == TQVariant::DateTime);
}
void clearValue()
{
_valueType = TQVariant::Invalid;
_valueType2 = TQVariant::Invalid;
_propSetID = 0;
}
TQVariant value( int valNo=1 ) const
{
if( 1 == valNo )
switch ( valueType( 1 ) ) {
case TQVariant::String:
return sValue;
case TQVariant::Double:
return dValue;
case TQVariant::DateTime:
return dtValue;
default:
return TQVariant();
}
else if( 2 == valNo )
switch ( valueType( 2 ) ) {
case TQVariant::Double:
return dValue2;
case TQVariant::DateTime:
return dtValue2;
default:
return TQVariant();
}
else
return TQVariant();
}
/* string values are only supported for legend texts or axis labels */
TQString stringValue( int valNo=1 ) const
{
// note: the 2nd value can not be a string
// - must be a date or a number!
if ((1 == valNo) && isString( valNo ))
return sValue;
else
return TQString();
}
double doubleValue( int valNo=1 ) const
{
return isDouble( valNo )
? ((1 == valNo) ? dValue : dValue2)
: DBL_MIN;
}
TQDateTime dateTimeValue( int valNo=1 ) const
{
return isDateTime( valNo )
? ((1 == valNo) ? dtValue : dtValue2)
: TQDateTime();
}
/**
Assign a property set to a data cell.
\param propSetID The ID of the property set to be assigned to this data cell.
This ID can either be one of the built-in IDs documented
at KDChartPropertySet::BuiltinDataPropertySetIDs or
a special ID that was given back by a
KDChartParams::registerProperties function call.
\sa propertySet
\sa KDCHART_PROPSET_NORMAL_DATA, KDCHART_PROPSET_TRANSPARENT_DATA
*/
void setPropertySet( int propSetID = 0 )
{
_propSetID = propSetID;
}
/**
Return the ID of the property set that is assigned to this data cell.
Use KDChartParams::properties( int ID ) for accessing the respective property set information.
\sa setPropertySet
\sa KDCHART_PROPSET_NORMAL_DATA, KDCHART_PROPSET_TRANSPARENT_DATA
*/
int propertySet() const
{
return _propSetID;
}
private:
// OBLIGATORY 1st value: usually used for ordinate axis
TQVariant::Type _valueType;
TQDateTime dtValue;
double dValue; // Sorry, d(t)Value and sValue cannot be a union,
TQString sValue; // since TQString has a non-default constructor.
// OPTIONAL 2nd value: if valid, normally used for abscissa axis
// note: this 2nd value can not be a string - must be a date or a number!
TQVariant::Type _valueType2;
TQDateTime dtValue2;
double dValue2;
// ID number of the property set assigned to this cell
int _propSetID;
};
#endif
|