1 | #ifndef ELEMENT_H
|
---|
2 | #define ELEMENT_H
|
---|
3 |
|
---|
4 | #include <qcolor.h>
|
---|
5 | #include <qnamespace.h>
|
---|
6 | #include <qstring.h>
|
---|
7 | #include <qvaluevector.h>
|
---|
8 |
|
---|
9 | class Element;
|
---|
10 |
|
---|
11 | typedef QValueVector<Element> ElementVector;
|
---|
12 |
|
---|
13 | /*
|
---|
14 | Elements are valid if they have a value which is > EPSILON.
|
---|
15 | */
|
---|
16 | const double EPSILON = 0.0000001; // Must be > INVALID.
|
---|
17 |
|
---|
18 |
|
---|
19 | class Element
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | enum { INVALID = -1 };
|
---|
23 | enum { NO_PROPORTION = -1 };
|
---|
24 | enum { MAX_PROPOINTS = 3 }; // One proportional point per chart type
|
---|
25 |
|
---|
26 | Element( double value = INVALID, QColor valueColor = Qt::gray,
|
---|
27 | int valuePattern = Qt::SolidPattern,
|
---|
28 | const QString& label = QString::null,
|
---|
29 | QColor labelColor = Qt::black ) {
|
---|
30 | init( value, valueColor, valuePattern, label, labelColor );
|
---|
31 | for ( int i = 0; i < MAX_PROPOINTS * 2; ++i )
|
---|
32 | m_propoints[i] = NO_PROPORTION;
|
---|
33 | }
|
---|
34 | ~Element() {}
|
---|
35 |
|
---|
36 | bool isValid() const { return m_value > EPSILON; }
|
---|
37 |
|
---|
38 | double value() const { return m_value; }
|
---|
39 | QColor valueColor() const { return m_valueColor; }
|
---|
40 | int valuePattern() const { return m_valuePattern; }
|
---|
41 | QString label() const { return m_label; }
|
---|
42 | QColor labelColor() const { return m_labelColor; }
|
---|
43 | double proX( int index ) const;
|
---|
44 | double proY( int index ) const;
|
---|
45 |
|
---|
46 | void set( double value = INVALID, QColor valueColor = Qt::gray,
|
---|
47 | int valuePattern = Qt::SolidPattern,
|
---|
48 | const QString& label = QString::null,
|
---|
49 | QColor labelColor = Qt::black ) {
|
---|
50 | init( value, valueColor, valuePattern, label, labelColor );
|
---|
51 | }
|
---|
52 | void setValue( double value ) { m_value = value; }
|
---|
53 | void setValueColor( QColor valueColor ) { m_valueColor = valueColor; }
|
---|
54 | void setValuePattern( int valuePattern );
|
---|
55 | void setLabel( const QString& label ) { m_label = label; }
|
---|
56 | void setLabelColor( QColor labelColor ) { m_labelColor = labelColor; }
|
---|
57 | void setProX( int index, double value );
|
---|
58 | void setProY( int index, double value );
|
---|
59 |
|
---|
60 | #ifdef Q_FULL_TEMPLATE_INSTANTIATION
|
---|
61 | // xlC 3.x workaround
|
---|
62 | Q_DUMMY_COMPARISON_OPERATOR(Element)
|
---|
63 | bool operator!=( const Element& e) const {
|
---|
64 | return ( !(e == *this) );
|
---|
65 | }
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | private:
|
---|
69 | void init( double value, QColor valueColor, int valuePattern,
|
---|
70 | const QString& label, QColor labelColor );
|
---|
71 |
|
---|
72 | double m_value;
|
---|
73 | QColor m_valueColor;
|
---|
74 | int m_valuePattern;
|
---|
75 | QString m_label;
|
---|
76 | QColor m_labelColor;
|
---|
77 | double m_propoints[2 * MAX_PROPOINTS];
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 | QTextStream &operator<<( QTextStream&, const Element& );
|
---|
82 | QTextStream &operator>>( QTextStream&, Element& );
|
---|
83 |
|
---|
84 | #endif
|
---|