toBarChart Class Reference

#include <tobarchart.h>

Inheritance diagram for toBarChart:

toLineChart QWidget

Public Slots

virtual void openCopy (void)

Public Member Functions

 toBarChart (QWidget *parent=NULL, const char *name=NULL, WFlags f=0)
 toBarChart (toBarChart *chart, QWidget *parent=NULL, const char *name=NULL, WFlags f=0)

Protected Member Functions

virtual void paintChart (QPainter *p, QRect &rect)

Detailed Description

A widget that displays a barchart. Each line is added onto the next one.

Definition at line 44 of file tobarchart.h.


Constructor & Destructor Documentation

toBarChart::toBarChart ( QWidget parent = NULL,
const char *  name = NULL,
WFlags  f = 0 
)

Create a new barchart.

Parameters:
parent Parent widget.
name Name of widget.
f Widget flags.

Definition at line 47 of file tobarchart.cpp.

References toLineChart::setMinValue().

Referenced by openCopy().

00048   : toLineChart(parent,name,f)
00049 {
00050   setMinValue(0);
00051 }

toBarChart::toBarChart ( toBarChart chart,
QWidget parent = NULL,
const char *  name = NULL,
WFlags  f = 0 
)

Create a new barchart by copying all the data from another barchart.

Parameters:
chart Chart to copy data from.
parent Parent widget.
name Name of widget.
f Widget flags.

Definition at line 174 of file tobarchart.cpp.

00175   : toLineChart(chart,parent,name,f)
00176 {
00177 }


Member Function Documentation

void toBarChart::paintChart ( QPainter *  p,
QRect &  rect 
) [protected, virtual]

Reimplemented from toLineChart.

Definition at line 55 of file tobarchart.cpp.

References toLineChart::countSamples(), toLineChart::MaxAuto, toLineChart::MaxValue, toLineChart::MinAuto, toLineChart::MinValue, toLineChart::paintAxis(), toLineChart::paintLegend(), toLineChart::paintTitle(), toLineChart::round(), toLineChart::samples(), toLineChart::SkipSamples, toLineChart::Values, toLineChart::zMaxValue, toLineChart::zMinValue, and toLineChart::Zooming.

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     p->setBrush(toChartColor(--cp));
00168 */
00169     p->drawPolygon(a);
00170     p->restore();
00171   }
00172 }

void toBarChart::openCopy ( void   )  [virtual, slot]

Open chart in new window.

Reimplemented from toLineChart.

Definition at line 179 of file tobarchart.cpp.

References toBarChart().

00180 {
00181   QWidget *newWin=new toBarChart(this,0,NULL,WDestructiveClose);
00182   newWin->show();
00183 //  toMainWidget()->windowsMenu();
00184 /*
00185 #if 1
00186   // This is a really ugly workaround for a Qt layout bug
00187   QWidget *tmp=NULL;
00188   QWidget *tmp2=NULL;
00189   for (unsigned int i=0;i<toMainWidget()->workspace()->windowList().count();i++) {
00190     QWidget *widget=toMainWidget()->workspace()->windowList().at(i);
00191     if (newWin!=widget)
00192       tmp2=widget;
00193     else
00194       tmp=newWin;
00195     if (tmp2&&tmp)
00196       break;
00197   }
00198   if(tmp2&&tmp) {
00199     tmp2->setFocus();
00200     tmp->setFocus();
00201   }
00202 #endif
00203 */
00204 }


The documentation for this class was generated from the following files:
Generated on Sat Dec 15 00:02:20 2007 for BulmaGes by  doxygen 1.5.1