00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef __TOLINECHART_H
00036 #define __TOLINECHART_H
00037
00038 #include <list>
00039 #include <qwidget.h>
00040
00041 class QPopupMenu;
00042
00045 class toLineChart : public QWidget {
00046 Q_OBJECT
00047
00048 QPopupMenu *Menu;
00049
00050 protected:
00051 std::list<std::list<double> > Values;
00052 std::list<QString> XValues;
00053 std::list<QString> Labels;
00054 bool Legend;
00055 bool Last;
00056 int Grid;
00057 bool AxisText;
00058 double MinValue;
00059 bool MinAuto;
00060 double MaxValue;
00061 bool MaxAuto;
00062 QString YPostfix;
00063 int Samples;
00064 QString Title;
00065
00066 QRect Chart;
00067 QPoint MousePoint[2];
00068 int SkipSamples;
00069 int UseSamples;
00070 bool Zooming;
00071 double zMinValue;
00072 double zMaxValue;
00073
00074 static double round(double round,bool up);
00075 QRect fixRect(QPoint p1,QPoint p2);
00076 virtual void mouseReleaseEvent(QMouseEvent *e);
00077 virtual void mouseMoveEvent(QMouseEvent *e);
00078 virtual void mouseDoubleClickEvent(QMouseEvent *e);
00079 virtual void mousePressEvent(QMouseEvent *e);
00080
00081 int countSamples(void);
00082 void clearZoom(void);
00083
00084 virtual void paintLegend(QPainter *p,QRect &rect);
00085 virtual void paintTitle(QPainter *p,QRect &rect);
00086 virtual void paintAxis(QPainter *p,QRect &rect);
00087 virtual void paintChart(QPainter *p,QRect &rect);
00088 public:
00094 toLineChart(QWidget *parent=NULL,const char *name=NULL,WFlags f=0);
00095
00102 toLineChart(toLineChart *chart,QWidget *parent=NULL,const char *name=NULL,WFlags f=0);
00103
00107 void showLegend(bool on)
00108 { Legend=on; update(); }
00112 bool legend(void) const
00113 { return Legend; }
00114
00118 void showLast(bool on)
00119 { Last=on; update(); }
00123 bool last(void) const
00124 { return Last; }
00125
00129 void setTitle(const QString &title=QString::null)
00130 { Title=title; update(); }
00134 const QString &title(void)
00135 { return Title; }
00136
00140 void showGrid(int div=0)
00141 { Grid=div; update(); }
00145 int grid(void) const
00146 { return Grid; }
00147
00151 void showAxisLegend(bool on)
00152 { AxisText=on; update(); }
00156 bool axisLegend(void) const
00157 { return AxisText; }
00158
00162 void setYPostfix(const QString &postfix)
00163 { YPostfix=postfix; update(); }
00166 void setMaxValueAuto(void)
00167 { MaxAuto=true; update(); }
00170 void setMinValueAuto(void)
00171 { MinAuto=true; update(); }
00175 void setMaxValue(double maxVal)
00176 { MaxAuto=false; MaxValue=maxVal; update(); }
00180 void setMinValue(double minVal)
00181 { MinAuto=false; MinValue=minVal; update(); }
00185 double minValue(void) const
00186 { return MinValue; }
00190 double maxValue(void) const
00191 { return MaxValue; }
00192
00196 void setSamples(int samples=-1);
00200 int samples(void) const
00201 { return Samples; }
00202
00206 void setLabels(const std::list<QString> &labels)
00207 { Labels=labels; update(); }
00211 std::list<QString> &labels(void)
00212 { return Labels; }
00213
00218 virtual void addValues(std::list<double> &value,const QString &xValues);
00219
00223 std::list<QString> &xValues(void)
00224 { return XValues; }
00225
00229 std::list<std::list<double> > &values(void)
00230 { return Values; }
00231
00232 public slots:
00235 virtual void clear(void)
00236 { Values.clear(); XValues.clear(); update(); }
00237
00240 virtual void setup(void);
00241
00244 virtual void editPrint(void);
00245
00248 virtual void openCopy(void);
00249 protected:
00252 virtual void paintEvent(QPaintEvent *e);
00253 };
00254
00255
00259 template <class T>
00260 T max(T a, T b)
00261 {
00262 return a > b ? a : b ;
00263 }
00264
00268 template <class T>
00269 T min(T a, T b)
00270 {
00271 return a < b ? a : b ;
00272 }
00273
00274 #endif