tobarchart.cpp

Go to the documentation of this file.
00001 //***************************************************************************
00002 /*
00003  * TOra - An Oracle Toolkit for DBA's and developers
00004  * Copyright (C) 2000-2001,2001 Underscore AB
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation;  only version 2 of
00009  * the License is valid for this program.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  *
00020  *      As a special exception, you have permission to link this program
00021  *      with the Oracle Client libraries and distribute executables, as long
00022  *      as you follow the requirements of the GNU GPL in regard to all of the
00023  *      software in the executable aside from Oracle client libraries.
00024  *
00025  *      Specifically you are not permitted to link this program with the
00026  *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
00027  *      And you are not permitted to distribute binaries compiled against
00028  *      these libraries without written consent from Underscore AB. Observe
00029  *      that this does not disallow linking to the Qt Free Edition.
00030  *
00031  * All trademarks belong to their respective owners.
00032  *
00033  ****************************************************************************/
00034 
00035 #include <qpainter.h>
00036 #include <qworkspace.h>
00037 
00038 #include "tobarchart.h"
00039 /*
00040 #include "tomain.h"
00041 #include "toconf.h"
00042 #include "totool.h"
00043 */
00044 
00045 // #include "tobarchart.moc"
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     p->setBrush(toChartColor(--cp));
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 //  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 }
00205 

Generated on Sat Dec 15 00:00:58 2007 for BulmaGes by  doxygen 1.5.1