author | drw <drw> | 2004-03-30 17:49:34 (UTC) |
---|---|---|
committer | drw <drw> | 2004-03-30 17:49:34 (UTC) |
commit | c74a24cbd04cb74d832908eb2b373aed7b3cea71 (patch) (unidiff) | |
tree | 3ea474f4c8fa64495b8e0604f34ae5a1bd55ac56 | |
parent | 2e5d236b647b1747dca61486ecdd85c8f3869487 (diff) | |
download | opie-c74a24cbd04cb74d832908eb2b373aed7b3cea71.zip opie-c74a24cbd04cb74d832908eb2b373aed7b3cea71.tar.gz opie-c74a24cbd04cb74d832908eb2b373aed7b3cea71.tar.bz2 |
Fix drawing of account balance graph when balance < 0.0
-rw-r--r-- | noncore/apps/checkbook/graph.cpp | 17 | ||||
-rw-r--r-- | noncore/apps/checkbook/graph.h | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/graphinfo.cpp | 13 | ||||
-rw-r--r-- | noncore/apps/checkbook/graphinfo.h | 3 |
4 files changed, 26 insertions, 9 deletions
diff --git a/noncore/apps/checkbook/graph.cpp b/noncore/apps/checkbook/graph.cpp index 389972e..72da738 100644 --- a/noncore/apps/checkbook/graph.cpp +++ b/noncore/apps/checkbook/graph.cpp | |||
@@ -21,150 +21,153 @@ | |||
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "graph.h" | 29 | #include "graph.h" |
30 | #include "graphinfo.h" | 30 | #include "graphinfo.h" |
31 | 31 | ||
32 | #include <qpainter.h> | 32 | #include <qpainter.h> |
33 | 33 | ||
34 | #include <math.h> | 34 | #include <math.h> |
35 | 35 | ||
36 | Graph::Graph( QWidget *parent, GraphInfo *d, const QString &name, int flags ) | 36 | Graph::Graph( QWidget *parent, GraphInfo *d, const QString &name, int flags ) |
37 | : QWidget( parent, name, flags ) | 37 | : QWidget( parent, name, flags ) |
38 | { | 38 | { |
39 | data = d; | 39 | data = d; |
40 | 40 | ||
41 | graph.setOptimization( QPixmap::BestOptim ); | 41 | graph.setOptimization( QPixmap::BestOptim ); |
42 | } | 42 | } |
43 | 43 | ||
44 | void Graph::setGraphInfo( GraphInfo *d ) | 44 | void Graph::setGraphInfo( GraphInfo *d ) |
45 | { | 45 | { |
46 | data = d; | 46 | data = d; |
47 | } | 47 | } |
48 | 48 | ||
49 | void Graph::drawGraph( bool regen ) | 49 | void Graph::drawGraph( bool regen ) |
50 | { | 50 | { |
51 | if ( regen ) | 51 | if ( regen ) |
52 | { | 52 | { |
53 | initGraph(); | 53 | initGraph(); |
54 | } | 54 | } |
55 | QPainter p( this ); | 55 | QPainter p( this ); |
56 | p.drawPixmap( 0, 0, graph ); | 56 | p.drawPixmap( 0, 0, graph ); |
57 | } | 57 | } |
58 | 58 | ||
59 | void Graph::paintEvent( QPaintEvent * ) | 59 | void Graph::paintEvent( QPaintEvent * ) |
60 | { | 60 | { |
61 | drawGraph( FALSE ); | 61 | drawGraph( FALSE ); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Graph::resizeEvent( QResizeEvent * ) | 64 | void Graph::resizeEvent( QResizeEvent * ) |
65 | { | 65 | { |
66 | drawGraph( TRUE ); | 66 | drawGraph( TRUE ); |
67 | } | 67 | } |
68 | 68 | ||
69 | void Graph::initGraph() | 69 | void Graph::initGraph() |
70 | { | 70 | { |
71 | graph.resize( width(), height() ); | 71 | graph.resize( width(), height() ); |
72 | graph.fill( QColor( 255, 255, 255 ) ); | 72 | graph.fill( QColor( 255, 255, 255 ) ); |
73 | 73 | ||
74 | if ( !data ) | 74 | if ( !data ) |
75 | { | 75 | { |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | 78 | ||
79 | // Any common stuff here (titles, ???) | 79 | // Any common stuff here (titles, ???) |
80 | 80 | ||
81 | switch ( data->graphType() ) | 81 | switch ( data->graphType() ) |
82 | { | 82 | { |
83 | case GraphInfo::BarChart : | 83 | case GraphInfo::BarChart : |
84 | { | 84 | { |
85 | drawBarChart( width(), height(), data->maxValue() ); | 85 | drawBarChart( width(), height(), data->maxValue(), data->minValue() ); |
86 | } | 86 | } |
87 | break; | 87 | break; |
88 | case GraphInfo::PieChart : | 88 | case GraphInfo::PieChart : |
89 | { | 89 | { |
90 | drawPieChart( width(), height(), data->totalValue() ); | 90 | drawPieChart( width(), height(), data->totalValue() ); |
91 | } | 91 | } |
92 | }; | 92 | }; |
93 | } | 93 | } |
94 | 94 | ||
95 | void Graph::drawBarChart( int width, int height, float max ) | 95 | void Graph::drawBarChart( int width, int height, float max, float min ) |
96 | { | 96 | { |
97 | QPainter p( &graph ); | 97 | QPainter p( &graph ); |
98 | 98 | ||
99 | // Try to set the font size smaller for text | 99 | // Try to set the font size smaller for text |
100 | QFont f = font(); | 100 | QFont f = font(); |
101 | f.setPointSize( 8 ); | 101 | f.setPointSize( 8 ); |
102 | p.setFont( f ); | 102 | p.setFont( f ); |
103 | 103 | ||
104 | int x = 0; | 104 | int x = 0; |
105 | int i = 0; | 105 | int i = 0; |
106 | int n = data->numberDataPoints(); | 106 | int n = data->numberDataPoints(); |
107 | QFontMetrics fm=fontMetrics(); | 107 | QFontMetrics fm=fontMetrics(); |
108 | int fh = fm.height(); | 108 | int fh = fm.height(); |
109 | int fw; | 109 | int fw; |
110 | 110 | ||
111 | QColor c( 0, 0, 255); | 111 | QColor c( 0, 0, 255); |
112 | p.setBrush( c ); | 112 | p.setBrush( c ); |
113 | 113 | ||
114 | if ( min > 0 ) | ||
115 | min = 0.0; | ||
116 | |||
117 | int bw = ( width - width / 4 ) / n; | ||
118 | int hoffset = int( ( height - height / 4 - 1 ) * ( min * -1 ) / ( max - min ) ); | ||
114 | for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) | 119 | for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) |
115 | { | 120 | { |
116 | int bw = ( width - width / 4 - x ) / ( n - i ); | 121 | int bh = int( ( height - height / 4 - 1 ) * dp->value() / ( max - min ) ); |
117 | int bh = int( ( height - height / 4 - 1 ) * dp->value() / max ); | 122 | p.drawRect( width / 8 + x, height - height / 8 - 1 - hoffset - bh, bw, bh ); |
118 | p.drawRect( width / 8 + x, height - height / 8 - 1 - bh, bw, bh ); | ||
119 | fw = fm.width( dp->label() ); | 123 | fw = fm.width( dp->label() ); |
120 | p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8, fw, | 124 | p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8 - hoffset, fw, |
121 | fh + height / 8, AlignTop | AlignHCenter, dp->label() ); | 125 | fh + height / 8, AlignTop | AlignHCenter, dp->label() ); |
122 | // WordBreak | AlignTop | AlignHCenter, dp->label() ); | ||
123 | i++; | 126 | i++; |
124 | x += bw; | 127 | x += bw; |
125 | } | 128 | } |
126 | } | 129 | } |
127 | 130 | ||
128 | void Graph::drawPieChart( int width, int height, float sum ) | 131 | void Graph::drawPieChart( int width, int height, float sum ) |
129 | { | 132 | { |
130 | QPainter p( &graph ); | 133 | QPainter p( &graph ); |
131 | 134 | ||
132 | // Try to set the font size smaller for text | 135 | // Try to set the font size smaller for text |
133 | QFont f = font(); | 136 | QFont f = font(); |
134 | f.setPointSize( 8 ); | 137 | f.setPointSize( 8 ); |
135 | p.setFont( f ); | 138 | p.setFont( f ); |
136 | 139 | ||
137 | int n = data->numberDataPoints(); | 140 | int n = data->numberDataPoints(); |
138 | 141 | ||
139 | int apos = -90 * 16; | 142 | int apos = -90 * 16; |
140 | 143 | ||
141 | int xd = width - width / 5; | 144 | int xd = width - width / 5; |
142 | int yd = height - height / 5; | 145 | int yd = height - height / 5; |
143 | 146 | ||
144 | int i = 0; | 147 | int i = 0; |
145 | 148 | ||
146 | QColor c; | 149 | QColor c; |
147 | 150 | ||
148 | for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) | 151 | for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) |
149 | { | 152 | { |
150 | c.setHsv( ( i *255) / n, 255, 255 ); | 153 | c.setHsv( ( i *255) / n, 255, 255 ); |
151 | p.setBrush( c ); | 154 | p.setBrush( c ); |
152 | 155 | ||
153 | int a = int( ( dp->value() * 360.0 ) / sum * 16.0 + 0.5 ); | 156 | int a = int( ( dp->value() * 360.0 ) / sum * 16.0 + 0.5 ); |
154 | p.drawPie( width/10, height/10, xd, yd, -apos, -a ); | 157 | p.drawPie( width/10, height/10, xd, yd, -apos, -a ); |
155 | apos += a; | 158 | apos += a; |
156 | i++; | 159 | i++; |
157 | } | 160 | } |
158 | 161 | ||
159 | double apos2 = -90 * 3.14159 / 180; | 162 | double apos2 = -90 * 3.14159 / 180; |
160 | for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) | 163 | for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) |
161 | { | 164 | { |
162 | double a = dp->value() *360 / sum * 3.14159 / 180; | 165 | double a = dp->value() *360 / sum * 3.14159 / 180; |
163 | int x = int( cos( apos2 + a/2 ) * width * 5/16 + width/2 + 0.5 ); | 166 | int x = int( cos( apos2 + a/2 ) * width * 5/16 + width/2 + 0.5 ); |
164 | int y = int( sin( apos2 + a/2 ) * height * 5/16 + height/2 + 0.5 ); | 167 | int y = int( sin( apos2 + a/2 ) * height * 5/16 + height/2 + 0.5 ); |
165 | p.drawText( x - width/8, y - height/8, width/4, height/4, WordBreak | AlignCenter, | 168 | p.drawText( x - width/8, y - height/8, width/4, height/4, WordBreak | AlignCenter, |
166 | dp->label() ); | 169 | dp->label() ); |
167 | apos2 += a; | 170 | apos2 += a; |
168 | } | 171 | } |
169 | } | 172 | } |
170 | 173 | ||
diff --git a/noncore/apps/checkbook/graph.h b/noncore/apps/checkbook/graph.h index 340e910..616cbb6 100644 --- a/noncore/apps/checkbook/graph.h +++ b/noncore/apps/checkbook/graph.h | |||
@@ -1,63 +1,63 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef GRAPH_H | 29 | #ifndef GRAPH_H |
30 | #define GRAPH_H | 30 | #define GRAPH_H |
31 | 31 | ||
32 | #include <qpixmap.h> | 32 | #include <qpixmap.h> |
33 | #include <qwidget.h> | 33 | #include <qwidget.h> |
34 | 34 | ||
35 | class GraphInfo; | 35 | class GraphInfo; |
36 | class QPainter; | 36 | class QPainter; |
37 | 37 | ||
38 | class Graph : public QWidget | 38 | class Graph : public QWidget |
39 | { | 39 | { |
40 | Q_OBJECT | 40 | Q_OBJECT |
41 | 41 | ||
42 | public: | 42 | public: |
43 | Graph( QWidget * = 0x0, GraphInfo * = 0x0, const QString & = 0x0, int = 0 ); | 43 | Graph( QWidget * = 0x0, GraphInfo * = 0x0, const QString & = 0x0, int = 0 ); |
44 | 44 | ||
45 | void setGraphInfo( GraphInfo * ); | 45 | void setGraphInfo( GraphInfo * ); |
46 | 46 | ||
47 | void drawGraph( bool = FALSE ); | 47 | void drawGraph( bool = FALSE ); |
48 | 48 | ||
49 | protected: | 49 | protected: |
50 | void paintEvent( QPaintEvent * ); | 50 | void paintEvent( QPaintEvent * ); |
51 | void resizeEvent( QResizeEvent * ); | 51 | void resizeEvent( QResizeEvent * ); |
52 | 52 | ||
53 | private: | 53 | private: |
54 | GraphInfo *data; | 54 | GraphInfo *data; |
55 | 55 | ||
56 | QPixmap graph; | 56 | QPixmap graph; |
57 | 57 | ||
58 | void initGraph(); | 58 | void initGraph(); |
59 | void drawBarChart( int, int, float ); | 59 | void drawBarChart( int, int, float, float ); |
60 | void drawPieChart( int, int, float ); | 60 | void drawPieChart( int, int, float ); |
61 | }; | 61 | }; |
62 | 62 | ||
63 | #endif | 63 | #endif |
diff --git a/noncore/apps/checkbook/graphinfo.cpp b/noncore/apps/checkbook/graphinfo.cpp index fec6896..5b72c80 100644 --- a/noncore/apps/checkbook/graphinfo.cpp +++ b/noncore/apps/checkbook/graphinfo.cpp | |||
@@ -36,88 +36,101 @@ GraphInfo::GraphInfo( GraphType type, DataPointList *data, const QString &title, | |||
36 | gt = title; | 36 | gt = title; |
37 | xt = xtitle; | 37 | xt = xtitle; |
38 | yt = ytitle; | 38 | yt = ytitle; |
39 | } | 39 | } |
40 | 40 | ||
41 | GraphInfo::~GraphInfo() | 41 | GraphInfo::~GraphInfo() |
42 | { | 42 | { |
43 | if ( d ) | 43 | if ( d ) |
44 | { | 44 | { |
45 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) | 45 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) |
46 | { | 46 | { |
47 | delete data; | 47 | delete data; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | GraphInfo::GraphType GraphInfo::graphType() | 52 | GraphInfo::GraphType GraphInfo::graphType() |
53 | { | 53 | { |
54 | return t; | 54 | return t; |
55 | } | 55 | } |
56 | 56 | ||
57 | void GraphInfo::setGraphType( GraphType type ) | 57 | void GraphInfo::setGraphType( GraphType type ) |
58 | { | 58 | { |
59 | t = type; | 59 | t = type; |
60 | } | 60 | } |
61 | 61 | ||
62 | DataPointList *GraphInfo::dataPoints() | 62 | DataPointList *GraphInfo::dataPoints() |
63 | { | 63 | { |
64 | return d; | 64 | return d; |
65 | } | 65 | } |
66 | 66 | ||
67 | void GraphInfo::setDataPoints( DataPointList *data ) | 67 | void GraphInfo::setDataPoints( DataPointList *data ) |
68 | { | 68 | { |
69 | d = data; | 69 | d = data; |
70 | } | 70 | } |
71 | 71 | ||
72 | DataPointInfo *GraphInfo::firstDataPoint() | 72 | DataPointInfo *GraphInfo::firstDataPoint() |
73 | { | 73 | { |
74 | return( d->first() ); | 74 | return( d->first() ); |
75 | } | 75 | } |
76 | 76 | ||
77 | DataPointInfo *GraphInfo::nextDataPoint() | 77 | DataPointInfo *GraphInfo::nextDataPoint() |
78 | { | 78 | { |
79 | return( d->next() ); | 79 | return( d->next() ); |
80 | } | 80 | } |
81 | 81 | ||
82 | int GraphInfo::numberDataPoints() | 82 | int GraphInfo::numberDataPoints() |
83 | { | 83 | { |
84 | return( d->count() ); | 84 | return( d->count() ); |
85 | } | 85 | } |
86 | 86 | ||
87 | float GraphInfo::maxValue() | 87 | float GraphInfo::maxValue() |
88 | { | 88 | { |
89 | float max = 0.0; | 89 | float max = 0.0; |
90 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) | 90 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) |
91 | { | 91 | { |
92 | if ( data->value() > max ) | 92 | if ( data->value() > max ) |
93 | { | 93 | { |
94 | max = data->value(); | 94 | max = data->value(); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | return max; | 97 | return max; |
98 | } | 98 | } |
99 | 99 | ||
100 | float GraphInfo::minValue() | ||
101 | { | ||
102 | float min = 0.0; | ||
103 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) | ||
104 | { | ||
105 | if ( data->value() < min ) | ||
106 | { | ||
107 | min = data->value(); | ||
108 | } | ||
109 | } | ||
110 | return min; | ||
111 | } | ||
112 | |||
100 | float GraphInfo::totalValue() | 113 | float GraphInfo::totalValue() |
101 | { | 114 | { |
102 | float sum = 0.0; | 115 | float sum = 0.0; |
103 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) | 116 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) |
104 | { | 117 | { |
105 | sum += data->value(); | 118 | sum += data->value(); |
106 | } | 119 | } |
107 | return sum; | 120 | return sum; |
108 | } | 121 | } |
109 | 122 | ||
110 | void GraphInfo::setGraphTitle( const QString &title ) | 123 | void GraphInfo::setGraphTitle( const QString &title ) |
111 | { | 124 | { |
112 | gt = title; | 125 | gt = title; |
113 | } | 126 | } |
114 | 127 | ||
115 | void GraphInfo::setXAxisTitle( const QString &xtitle ) | 128 | void GraphInfo::setXAxisTitle( const QString &xtitle ) |
116 | { | 129 | { |
117 | xt = xtitle; | 130 | xt = xtitle; |
118 | } | 131 | } |
119 | 132 | ||
120 | void GraphInfo::setYAxisTitle( const QString &ytitle ) | 133 | void GraphInfo::setYAxisTitle( const QString &ytitle ) |
121 | { | 134 | { |
122 | yt = ytitle; | 135 | yt = ytitle; |
123 | } | 136 | } |
diff --git a/noncore/apps/checkbook/graphinfo.h b/noncore/apps/checkbook/graphinfo.h index 41927b4..f7842c6 100644 --- a/noncore/apps/checkbook/graphinfo.h +++ b/noncore/apps/checkbook/graphinfo.h | |||
@@ -1,88 +1,89 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef GRAPHINFO_H | 29 | #ifndef GRAPHINFO_H |
30 | #define GRAPHINFO_H | 30 | #define GRAPHINFO_H |
31 | 31 | ||
32 | #include <qlist.h> | 32 | #include <qlist.h> |
33 | #include <qstringlist.h> | 33 | #include <qstringlist.h> |
34 | 34 | ||
35 | class DataPointInfo | 35 | class DataPointInfo |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | DataPointInfo() | 38 | DataPointInfo() |
39 | : l( 0x0 ), v( 0.0 ) {} | 39 | : l( 0x0 ), v( 0.0 ) {} |
40 | DataPointInfo( const QString &label, float value ) | 40 | DataPointInfo( const QString &label, float value ) |
41 | : l( label ), v( value ) {} | 41 | : l( label ), v( value ) {} |
42 | 42 | ||
43 | const QString &label() { return l; } | 43 | const QString &label() { return l; } |
44 | float value() { return v; } | 44 | float value() { return v; } |
45 | 45 | ||
46 | void addToValue( float value ) { v += value; } | 46 | void addToValue( float value ) { v += value; } |
47 | 47 | ||
48 | private: | 48 | private: |
49 | QString l; | 49 | QString l; |
50 | float v; | 50 | float v; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | typedef QList<DataPointInfo> DataPointList; | 53 | typedef QList<DataPointInfo> DataPointList; |
54 | 54 | ||
55 | class GraphInfo | 55 | class GraphInfo |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | enum GraphType { BarChart, PieChart }; | 58 | enum GraphType { BarChart, PieChart }; |
59 | 59 | ||
60 | GraphInfo( GraphType = BarChart, DataPointList * = 0x0, | 60 | GraphInfo( GraphType = BarChart, DataPointList * = 0x0, |
61 | const QString & = 0x0, const QString & = 0x0, const QString & = 0x0 ); | 61 | const QString & = 0x0, const QString & = 0x0, const QString & = 0x0 ); |
62 | ~GraphInfo(); | 62 | ~GraphInfo(); |
63 | 63 | ||
64 | GraphInfo::GraphType graphType(); | 64 | GraphInfo::GraphType graphType(); |
65 | void setGraphType( GraphType ); | 65 | void setGraphType( GraphType ); |
66 | 66 | ||
67 | DataPointList *dataPoints(); | 67 | DataPointList *dataPoints(); |
68 | void setDataPoints( DataPointList * ); | 68 | void setDataPoints( DataPointList * ); |
69 | DataPointInfo *firstDataPoint(); | 69 | DataPointInfo *firstDataPoint(); |
70 | DataPointInfo *nextDataPoint(); | 70 | DataPointInfo *nextDataPoint(); |
71 | int numberDataPoints(); | 71 | int numberDataPoints(); |
72 | 72 | ||
73 | float maxValue(); | 73 | float maxValue(); |
74 | float minValue(); | ||
74 | float totalValue(); | 75 | float totalValue(); |
75 | 76 | ||
76 | void setGraphTitle( const QString & ); | 77 | void setGraphTitle( const QString & ); |
77 | void setXAxisTitle( const QString & ); | 78 | void setXAxisTitle( const QString & ); |
78 | void setYAxisTitle( const QString & ); | 79 | void setYAxisTitle( const QString & ); |
79 | 80 | ||
80 | private: | 81 | private: |
81 | GraphType t; | 82 | GraphType t; |
82 | DataPointList *d; | 83 | DataPointList *d; |
83 | QString gt; | 84 | QString gt; |
84 | QString xt; | 85 | QString xt; |
85 | QString yt; | 86 | QString yt; |
86 | }; | 87 | }; |
87 | 88 | ||
88 | #endif | 89 | #endif |