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 #include <qpainter.h>
00036 #include <qworkspace.h>
00037
00038 #include "tobarchart.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047 toBarChart::toBarChart(QWidget *parent,const char *name,WFlags f)
00048 : toLineChart(parent,name,f)
00049 {
00050 setMinValue(0);
00051 }
00052
00053 #define FONT_ALIGN AlignLeft|AlignTop|ExpandTabs
00054
00055 void toBarChart::paintChart(QPainter *p,QRect &rect)
00056 {
00057 QFontMetrics fm=p->fontMetrics();
00058
00059 if (!Zooming) {
00060 if (MinAuto) {
00061 bool first=true;
00062 std::list<std::list<double> >::reverse_iterator i=Values.rbegin();
00063 if (i!=Values.rend()) {
00064 for(std::list<double>::iterator j=(*i).begin();j!=(*i).end();j++) {
00065 if (first) {
00066 first=false;
00067 zMinValue=*j;
00068 } else if (zMinValue>*j)
00069 zMinValue=*j;
00070 }
00071 }
00072 }
00073 if (MaxAuto) {
00074 bool first=true;
00075 std::list<double> total;
00076 {
00077 for(std::list<std::list<double> >::iterator i=Values.begin();i!=Values.end();i++) {
00078 std::list<double>::iterator k=total.begin();
00079 for(std::list<double>::iterator j=(*i).begin();j!=(*i).end();j++) {
00080 if (k==total.end()) {
00081 total.insert(total.end(),*j);
00082 k=total.end();
00083 } else {
00084 *k+=*j;
00085 k++;
00086 }
00087 }
00088 }
00089 }
00090 for(std::list<double>::iterator i=total.begin();i!=total.end();i++) {
00091 if (first) {
00092 first=false;
00093 zMaxValue=*i;
00094 } else if (zMaxValue<*i)
00095 zMaxValue=*i;
00096 }
00097 }
00098 if(!MinAuto)
00099 zMinValue=MinValue;
00100 else
00101 zMinValue=round(zMinValue,false);
00102 if(!MaxAuto)
00103 zMaxValue=MaxValue;
00104 else
00105 zMaxValue=round(zMaxValue,true);
00106 }
00107
00108 paintTitle(p,rect);
00109 paintLegend(p,rect);
00110 paintAxis(p,rect);
00111
00112 std::list<QPointArray> Points;
00113 int cp=0;
00114 int samples=countSamples();
00115 int zeroy=int(rect.height()-2-(-zMinValue/(zMaxValue-zMinValue)*(rect.height()-4)));
00116 if (samples>1) {
00117 const QWMatrix &mtx=p->worldMatrix();
00118 p->setClipRect(int(mtx.dx()+2),int(mtx.dy()+2),rect.width()-3,rect.height()-3);
00119 if (Zooming)
00120 p->drawText(2,2,rect.width()-4,rect.height()-4,
00121 AlignLeft|AlignTop,"Zoom");
00122 for(std::list<std::list<double> >::reverse_iterator i=Values.rbegin();i!=Values.rend();i++) {
00123 std::list<double> &val=*i;
00124 int count=0;
00125 int skip=SkipSamples;
00126 QPointArray a(samples+10);
00127 int x=rect.width()-2;
00128 for(std::list<double>::reverse_iterator j=val.rbegin();j!=val.rend()&&x>=2;j++) {
00129 if (skip>0)
00130 skip--;
00131 else {
00132 int val=int(rect.height()-2-((*j-zMinValue)/(zMaxValue-zMinValue)*(rect.height()-4)));
00133 x=rect.width()-2-count*(rect.width()-4)/(samples-1);
00134 a.setPoint(count,x,val);
00135 count++;
00136 if (count>=samples)
00137 break;
00138 }
00139 }
00140 a.resize(count*2);
00141 Points.insert(Points.end(),a);
00142 cp++;
00143 }
00144 }
00145
00146 std::map<int,int> Bottom;
00147 for(std::list<QPointArray>::iterator i=Points.begin();i!=Points.end();i++) {
00148 QPointArray a=*i;
00149 int lx=0;
00150 int lb=0;
00151 for(unsigned int j=0;j<a.size()/2;j++) {
00152 int x,y;
00153 a.point(j,&x,&y);
00154 if(Bottom.find(x)==Bottom.end())
00155 Bottom[x]=0;
00156 if (lx!=x)
00157 lb=Bottom[x];
00158 a.setPoint(a.size()-1-j,x,zeroy-lb);
00159 y-=lb;
00160 a.setPoint(j,x,y);
00161 Bottom[x]=zeroy-y;
00162 lx=x;
00163 }
00164
00165 p->save();
00166
00167
00168
00169 p->drawPolygon(a);
00170 p->restore();
00171 }
00172 }
00173
00174 toBarChart::toBarChart (toBarChart *chart,QWidget *parent,const char *name,WFlags f)
00175 : toLineChart(chart,parent,name,f)
00176 {
00177 }
00178
00179 void toBarChart::openCopy(void)
00180 {
00181 QWidget *newWin=new toBarChart(this,0,NULL,WDestructiveClose);
00182 newWin->show();
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 }
00205