kchart

KDChartDataIntern.h
1/*
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 **********************************************************************/
29#ifndef __KDCHARTDATAINTERN_H__
30#define __KDCHARTDATAINTERN_H__
31
32#include <tqvariant.h>
33#include <tqstring.h>
34#include <tqdatetime.h>
35#include "KDChartGlobal.h"
36
42
43
44
45// Please leave all methods in this class inline!
46// It's necessary since it's part of the interface provided by KDChart
47class KDCHART_EXPORT KDChartData
48{
49public:
50 // 0. default c'tor: initializing all values as undefined
51
53 _valueType( TQVariant::Invalid ),
54 _valueType2( TQVariant::Invalid ),
55 _propSetID( 0 )
56 {}
57
58 // 1. simple c'tors: used for 1-coordinate data
59
60 KDChartData( double value ) :
61 _valueType( TQVariant::Double ), dValue( value ),
62 _valueType2( TQVariant::Invalid ),
63 _propSetID( 0 )
64 {}
65 /* string values are only supported for legend texts or axis labels */
66 KDChartData( const TQString& value ) :
67 _valueType( TQVariant::String ), sValue( value ),
68 _valueType2( TQVariant::Invalid ),
69 _propSetID( 0 )
70 {}
71 /* date/time values for /ordinate/ axes are not implemented yet
72 KDChartData( TQDateTime value ) :
73 _valueType( TQVariant::DateTime ), dtValue( value ),
74 _valueType2( TQVariant::Invalid ),
75 _propSetID( 0 )
76 {}*/
77
78 // 2. complex c'tors: used for 2-coordinate data
79
80 // 2.a) with additional Date/Time: normally used when Date on x-axis
81 // e.g. for time related index numbers like water level measurements
82 KDChartData( double yValue, TQDateTime xValue ) :
83 _valueType( TQVariant::Double ), dValue( yValue ),
84 _valueType2( TQVariant::DateTime ), dtValue2( xValue ),
85 _propSetID( 0 )
86 {}
87
88
89 KDChartData( const TQVariant& _value1,
90 const TQVariant& _value2 )
91 {
92 switch( _value1.type() ){
93 case TQVariant::Int:
94 case TQVariant::UInt:
95 case TQVariant::Double:
96 _valueType = TQVariant::Double;
97 dValue = _value1.toDouble();
98 break;
99 case TQVariant::DateTime:
100 _valueType = TQVariant::DateTime;
101 dtValue = _value1.toDateTime();
102 break;
103 case TQVariant::String:
104 _valueType = TQVariant::String;
105 sValue = _value1.toString();
106 break;
107 default:
108 _valueType = TQVariant::Invalid;
109 }
110 switch( _value2.type() ){
111 case TQVariant::Int:
112 case TQVariant::UInt:
113 case TQVariant::Double:
114 _valueType2 = TQVariant::Double;
115 dValue2 = _value2.toDouble();
116 break;
117 case TQVariant::DateTime:
118 _valueType2 = TQVariant::DateTime;
119 dtValue2 = _value2.toDateTime();
120 break;
121 default:
122 _valueType2 = TQVariant::Invalid;
123 }
124 _propSetID = 0;
125 }
126
127 /* date/time values for /ordinate/ axes are not implemented yet
128 KDChartData( TQDateTime yValue, TQDateTime xValue ) :
129 _valueType( DateTime ), dtValue( yValue ),
130 _valueType2( DateTime ), dtValue2( xValue ),
131 _propSetID( 0 )
132 {}*/
133 // 2.b) with additional Double: may be used for mathematical data...
134 KDChartData( double yValue, double xValue ) :
135 _valueType( TQVariant::Double ), dValue( yValue ),
136 _valueType2( TQVariant::Double ), dValue2( xValue ),
137 _propSetID( 0 )
138 {}
139 /* date/time values for /ordinate/ axes are not implemented yet
140 KDChartData( TQDateTime yValue, double xValue ) :
141 _valueType( DateTime ), dtValue( yValue ),
142 _valueType2( Double ), dValue2( xValue ),
143 _propSetID( 0 )
144 {}*/
145
146/*
147 /-**
148 Copy constructor.
149
150 \sa setData
151 * /
152 KDChartData( const KDChartData& other ) :
153 {
154 setData( other );
155 }
156
157 /-**
158 Assignment operator.
159
160 \sa setData
161 * /
162 KDChartData& operator=( const KDChartData& R )
163 {
164 setData( R );
165 return *this;
166 }
167*/
173 bool operator==( const KDChartData& it ) const
174 {
175 return isEqual(*this, it);
176 }
177
183 bool operator!=( const KDChartData& it ) const
184 {
185 return !isEqual(*this, it);
186 }
187
195 bool isEqual( const KDChartData& a, const KDChartData& b ) const
196 {
197 bool bRet = (a.hasValue( 1 ) == b.hasValue( 1 )) &&
198 (a.hasValue( 2 ) == b.hasValue( 2 ));
199 if ( bRet && a.hasValue( 1 ) ) {
200 bRet = a.valueType( 1 ) == b.valueType( 1 );
201 if ( bRet ) {
202 switch ( a.valueType( 1 ) ) {
203 case TQVariant::String:
204 bRet = a.stringValue( 1 ) == b.stringValue( 1 );
205 break;
206 case TQVariant::Double:
207 bRet = a.doubleValue( 1 ) == b.doubleValue( 1 );
208 break;
209 case TQVariant::DateTime:
210 bRet = a.dateTimeValue( 1 ) == b.dateTimeValue( 1 );
211 break;
212 default:
213 bRet = false;
214 }
215 }
216 if ( bRet && a.hasValue( 2 ) ) {
217 bRet = a.valueType( 2 ) == b.valueType( 2 );
218 if ( bRet ) {
219 switch ( a.valueType( 2 ) ) {
220 // note: the 2nd value can not be a string
221 // - must be a date or a number!
222 case TQVariant::Double:
223 bRet = a.doubleValue( 2 ) == b.doubleValue( 2 );
224 break;
225 case TQVariant::DateTime:
226 bRet = a.dateTimeValue( 2 ) == b.dateTimeValue( 2 );
227 break;
228 default:
229 bRet = false;
230 }
231 }
232 }
233 // Note: We do *not* compare the _propSetID here since it contains
234 // no values but is used to handle some layout information...
235 }
236 return bRet;
237 }
238
246 void setAll( const KDChartData& R )
247 {
248 setData( R );
250 }
251
252
261 void setData( const KDChartData& R )
262 {
263 if( &R != this ){
264 _valueType = R._valueType;
265 _valueType2 = R._valueType2;
266 switch ( valueType( 1 ) ) {
267 case TQVariant::String:
268 sValue = R.sValue;
269 break;
270 case TQVariant::Double:
271 dValue = R.dValue;
272 break;
273 case TQVariant::DateTime:
274 dtValue = R.dtValue;
275 break;
276 default:
277 /* NOOP */;
278 }
279 switch ( valueType( 2 ) ) {
280 // note: the 2nd value can not be a string
281 // - must be a date or a number!
282 case TQVariant::Double:
283 dValue2 = R.dValue2;
284 break;
285 case TQVariant::DateTime:
286 dtValue2 = R.dtValue2;
287 break;
288 default:
289 /* NOOP */;
290 }
291 // Note: We do *not* copy the _propSetID here since it contains
292 // no values but is used to handle some layout information...
293 }
294 }
295
296 TQVariant::Type valueType( int valNo=1 ) const
297 {
298 return (1 == valNo)
299 ? _valueType
300 : _valueType2;
301 }
302 bool hasValue( int valNo=1 ) const
303 {
304 return (1 == valNo)
305 ? (_valueType != TQVariant::Invalid)
306 : ((_valueType2 == TQVariant::Double) || (_valueType2 == TQVariant::DateTime));
307 }
308 /* string values are only supported for legend texts or axis labels */
309 bool isString( int valNo=1 ) const
310 {
311 return (1 == valNo)
312 ? (_valueType == TQVariant::String)
313 : false;
314 }
315 bool isDouble( int valNo=1 ) const
316 {
317 return (1 == valNo)
318 ? (_valueType == TQVariant::Double)
319 : (_valueType2 == TQVariant::Double);
320 }
321 bool isDateTime( int valNo=1 ) const
322 {
323 return (1 == valNo)
324 ? (_valueType == TQVariant::DateTime)
325 : (_valueType2 == TQVariant::DateTime);
326 }
327
328
330 {
331 _valueType = TQVariant::Invalid;
332 _valueType2 = TQVariant::Invalid;
333 _propSetID = 0;
334 }
335
336 TQVariant value( int valNo=1 ) const
337 {
338 if( 1 == valNo )
339 switch ( valueType( 1 ) ) {
340 case TQVariant::String:
341 return sValue;
342 case TQVariant::Double:
343 return dValue;
344 case TQVariant::DateTime:
345 return dtValue;
346 default:
347 return TQVariant();
348 }
349 else if( 2 == valNo )
350 switch ( valueType( 2 ) ) {
351 case TQVariant::Double:
352 return dValue2;
353 case TQVariant::DateTime:
354 return dtValue2;
355 default:
356 return TQVariant();
357 }
358 else
359 return TQVariant();
360 }
361
362 /* string values are only supported for legend texts or axis labels */
363 TQString stringValue( int valNo=1 ) const
364 {
365 // note: the 2nd value can not be a string
366 // - must be a date or a number!
367 if ((1 == valNo) && isString( valNo ))
368 return sValue;
369 else
370 return TQString();
371 }
372 double doubleValue( int valNo=1 ) const
373 {
374 return isDouble( valNo )
375 ? ((1 == valNo) ? dValue : dValue2)
376 : DBL_MIN;
377 }
378 TQDateTime dateTimeValue( int valNo=1 ) const
379 {
380 return isDateTime( valNo )
381 ? ((1 == valNo) ? dtValue : dtValue2)
382 : TQDateTime();
383 }
384
397 void setPropertySet( int propSetID = 0 )
398 {
399 _propSetID = propSetID;
400 }
401
409 int propertySet() const
410 {
411 return _propSetID;
412 }
413
414
415private:
416 // OBLIGATORY 1st value: usually used for ordinate axis
417 TQVariant::Type _valueType;
418 TQDateTime dtValue;
419 double dValue; // Sorry, d(t)Value and sValue cannot be a union,
420 TQString sValue; // since TQString has a non-default constructor.
421
422 // OPTIONAL 2nd value: if valid, normally used for abscissa axis
423 // note: this 2nd value can not be a string - must be a date or a number!
424 TQVariant::Type _valueType2;
425 TQDateTime dtValue2;
426 double dValue2;
427
428 // ID number of the property set assigned to this cell
429 int _propSetID;
430};
431
432#endif
Encapsulates one data cell in a chart.
TQString stringValue(int valNo=1) const
Returns the string value represented by this object, or TQString() if this object does not represent ...
bool operator==(const KDChartData &it) const
Compare operator.
bool isDateTime(int valNo=1) const
Returns true if the object represents a TQDateTime value and false otherwise.
KDChartData(double yValue, double xValue)
Constructor.
KDChartData()
Constructor.
void clearValue()
Resets both of the data types of this cell to KDChartData::NoValue and sets the property set ID to KD...
void setPropertySet(int propSetID=0)
Assign a property set to a data cell.
double doubleValue(int valNo=1) const
Returns the double value represented by this object, or DBL_MIN if this object does not represent a d...
int propertySet() const
Return the ID of the property set that is assigned to this data cell.
bool isString(int valNo=1) const
Returns true if the object represents a TQString value and false otherwise.
TQVariant::Type valueType(int valNo=1) const
Returns the type of the respective value.
bool isDouble(int valNo=1) const
Returns true if the object represents a double value and false otherwise.
bool hasValue(int valNo=1) const
Returns true if the object represents a value (double or TQString) and false otherwise.
KDChartData(double value)
Constructor.
void setData(const KDChartData &R)
Method setData.
bool operator!=(const KDChartData &it) const
Compare operator.
bool isEqual(const KDChartData &a, const KDChartData &b) const
Compare method.
KDChartData(const TQString &value)
Constructor.
KDChartData(double yValue, TQDateTime xValue)
Constructor.
void setAll(const KDChartData &R)
Method setAll.
TQDateTime dateTimeValue(int valNo=1) const
Returns the TQDateTime value represented by this object, or TQDateTime() if this object does not repr...