Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

Plot.h

Go to the documentation of this file.
00001 //LabPlot : Plot.h
00002 
00003 #ifndef PLOT_H
00004 #define PLOT_H
00005 
00006 #include <math.h>
00007 #include "Worksheet.h"
00008 #include "Legend.h"
00009 #include "Label.h"
00010 #include "Axis.h"
00011 
00012 class Plot {
00013 public:
00014         Plot(class Worksheet *p);
00015         virtual ~Plot() {}
00016         GraphList *getGraphList() { return graphlist; }
00017         void clear() {graphlist->clear();}
00018         void save(QTextStream *t);
00019         virtual void saveAxes(QTextStream *t) = 0;
00020         void saveAxis(QTextStream *t,Axis *axis,int gridenabled, int borderenabled, int minorgridenabled);
00021         void open(QTextStream *t, int version);
00022         void openAxis(QTextStream *t,int version, Axis *axis,bool *gridenabled,bool *borderenabled, bool *minorgridenabled);
00023         virtual void openAxes(QTextStream *t, int version) = 0;
00024 
00025         QString getTicLabel(int axisnr, int atlf, int prec, QString dtf, double value);
00026         
00027         virtual Axis *getAxis(int i) = 0;
00028         class Legend* getLegend() { return &legend; }
00029         void setType(PType i) { type = i; }
00030         PType getType() { return type; }
00031         Label* getTitle() { return title; }
00032         virtual void setRanges(LRange *) = 0;
00033         LRange* getRanges() { return range;}
00034         virtual void setActRanges(LRange *) = 0;
00035         LRange* getActRanges() { return actrange;}
00036         void setRegionMin(double min) {region.setMin(min);}
00037         void setRegionMax(double max) {region.setMax(max);}
00038         double getRegionMin() {return region.Min();}
00039         double getRegionMax() {return region.Max();}
00040         bool regionEnabled() { return region_enabled; }
00041         void setRegionEnabled(bool e) { region_enabled = e; }
00042         void setTransparent(bool t) { transparent = t; }
00043         bool getTransparent() { return transparent; }
00044         void setClipOffset(int c) { clipoffset=c;}
00045         int getClipOffset() { return clipoffset;}
00046 
00047         virtual void enableGrid(int index,bool b) = 0;
00048         virtual bool gridEnabled(int index) = 0;
00049         virtual void enableBorder(int index,bool b) = 0;
00050         virtual bool borderEnabled(int index) = 0;
00051         bool baselineEnabled() { return baseline_enabled; }
00052         double Baseline() { return baseline; }
00053         void setBaselineEnabled(bool e) { baseline_enabled = e; }
00054         void setBaseline(double b) { baseline = b; }
00055 
00056         virtual void draw(QPainter *p, int w, int h) = 0;
00057         void drawStyle(QPainter *p, Style s, int oldx, int oldy,int x,int y,int ymin, int ymax);
00058         void drawErrorBar(QPainter *p, int x, int y, int xleft, int xright, int ytop, int ybottom);
00059         virtual void setBorder(int,bool) = 0;
00060         bool inside(double x, double y) {
00061                 if(x>position.X() && x<position.X()+size.X() && y>position.Y() && y<position.Y()+size.Y())
00062                         return true;
00063                 else
00064                         return false;
00065         }
00066         bool insideLegend(int x,int y) { if (legend.inside(x,y)) return true; return false;}
00067         bool insidePlottingArea(double x,double y) {
00068                 if (x>p1.X() && x<p2.X() && y>p1.Y() && y<p2.Y()) return true; return false;
00069         }
00070         bool insideF1Corner(double x, double y) {
00071                 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y())<0.01)
00072                         return true;
00073                 return false;
00074         }
00075         bool insideF2Corner(double x, double y) {
00076                 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00077                         return true;
00078                 return false;
00079         }
00080         bool insideB1Corner(double x, double y) {
00081                 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00082                         return true;
00083                 return false;
00084         }
00085         bool insideB2Corner(double x, double y) {
00086                 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y())<0.01)
00087                         return true;
00088                 return false;
00089         }
00090         bool insideX1Border(double x, double y) {
00091                 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y()-size.Y())<0.01)
00092                         return true;
00093                 return false;
00094         }
00095         bool insideX2Border(double x, double y) {
00096                 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y())<0.01)
00097                         return true;
00098                 return false;
00099         }
00100         bool insideY1Border(double x, double y) {
00101                 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X())<0.01)
00102                         return true;
00103                 return false;
00104         }
00105         bool insideY2Border(double x, double y) {
00106                 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X()-size.X())<0.01)
00107                         return true;
00108                 return false;
00109         }
00110         bool insideCenter(double x, double y) {
00111                 if(fabs(x-position.X()-size.X()/2.0)<0.01 && fabs(y-position.Y()-size.Y()/2.0)<0.01)
00112                         return true;
00113                 return false;
00114         }
00115         void setPosition(Point p) { position = p; }
00116         void setPosition(double x, double y) { position = Point(x,y); }
00117         Point getPosition() { return position; }
00118         void setSize(Point s) { size = s; }
00119         void setSize(double x, double y) { size = Point(x,y); }
00120         Point getSize() { return size; }
00121         void setBackground(QColor c) { bgcolor = c; }
00122         QColor Background() { return bgcolor; }
00123         void setGraphBackground(QColor c) { gbgcolor = c;}
00124         QColor graphBackground() { return gbgcolor; }
00125         void autoScaleX() {actrange[0].setMin(range[0].Min());actrange[0].setMax(range[0].Max());}
00126         void autoScaleY() {actrange[1].setMin(range[1].Min());actrange[1].setMax(range[1].Max());}
00127         void autoScaleZ() {actrange[2].setMin(range[2].Min());actrange[2].setMax(range[2].Max());}
00128         void setXRange(double x1, double x2) {actrange[0].setMin(x1); actrange[0].setMax(x2); }
00129         void setYRange(double y1, double y2) {actrange[1].setMin(y1); actrange[1].setMax(y2); }
00130         void setZRange(double z1, double z2) {actrange[2].setMin(z1); actrange[2].setMax(z2); }
00131 
00132         Point getP1() { return p1;}
00133         Point getP2() { return p2;}
00134         void setP1(Point p) { p1=p;}
00135         void setP2(Point p) { p2=p;}
00136 
00137         void setXMin(int xmin,int X) { p1.setPoint((xmin/(double)X-position.X())/size.X(),p1.Y()); }
00138         void setXMax(int xmax,int X) { p2.setPoint((xmax/(double)X-position.X())/size.X(),p2.Y()); }
00139         void setYMin(int ymin,int Y) { p1.setPoint(p1.X(),(ymin/(double)Y-position.Y())/size.Y()); }
00140         void setYMax(int ymax,int Y) { p2.setPoint(p2.X(),(ymax/(double)Y-position.Y())/size.Y()); }
00141 
00142         void shiftRight() {double x1=actrange[0].Min(), x2=actrange[0].Max();
00143                 actrange[0].setMin(x1-fabs(x2-x1)/3.0);actrange[0].setMax(x2-fabs(x2-x1)/3.0);}
00144         void shiftLeft() {double x1=actrange[0].Min(), x2=actrange[0].Max();
00145                 actrange[0].setMin(x1+fabs(x2-x1)/3.0);actrange[0].setMax(x2+fabs(x2-x1)/3.0);}
00146         void shiftUp() {double y1=actrange[1].Min(), y2=actrange[1].Max();
00147                 actrange[1].setMin(y1-fabs(y2-y1)/3.0);actrange[1].setMax(y2-fabs(y2-y1)/3.0);}
00148         void shiftDown() {double y1=actrange[1].Min(), y2=actrange[1].Max();
00149                 actrange[1].setMin(y1+fabs(y2-y1)/3.0);actrange[1].setMax(y2+fabs(y2-y1)/3.0);}
00150         void scaleXUp() {double x1=actrange[0].Min(), x2=actrange[0].Max();
00151                 actrange[0].setMin(x1+fabs(x2-x1)/4.0);actrange[0].setMax(x2-fabs(x2-x1)/4.0);}
00152         void scaleXDown() {double x1=actrange[0].Min(), x2=actrange[0].Max();
00153                 actrange[0].setMin(x1-fabs(x2-x1)/4.0);actrange[0].setMax(x2+fabs(x2-x1)/4.0);}
00154         void scaleYUp() {double y1=actrange[1].Min(), y2=actrange[1].Max();
00155                 actrange[1].setMin(y1+fabs(y2-y1)/4.0);actrange[1].setMax(y2-fabs(y2-y1)/4.0);}
00156         void scaleYDown() {double y1=actrange[1].Min(), y2=actrange[1].Max();
00157                 actrange[1].setMin(y1-fabs(y2-y1)/4.0);actrange[1].setMax(y2+fabs(y2-y1)/4.0);}
00158         void scaleZUp() {double z1=actrange[2].Min(), z2=actrange[2].Max();
00159                 actrange[2].setMin(z1+fabs(z2-z1)/4.0);actrange[2].setMax(z2-fabs(z2-z1)/4.0);}
00160         void scaleZDown() {double z1=actrange[2].Min(), z2=actrange[2].Max();
00161                 actrange[2].setMin(z1-fabs(z2-z1)/4.0);actrange[2].setMax(z2+fabs(z2-z1)/4.0);}
00162 protected:
00163         Worksheet *worksheet;                   // parent worksheet
00164         PType type;                             // type of the plot
00165         GraphList *graphlist;                   // list of graphs
00166         Point position, size;                           // position and size (0..1)
00167         Label *title;                                   // Title
00168         Legend legend;                          // Legend
00169         QColor bgcolor, gbgcolor;               // background & graph background color
00170         Point p1, p2;                                   // plotting area        (0..1)
00171         LRange range[3];                                // graph ranges (x,y,z)
00172         LRange actrange[3];                     // actual plotting range (x,y,z)
00173         double baseline;                                // baseline
00174         bool baseline_enabled;                  // draw it ?
00175         LRange region;                          // region
00176         bool region_enabled;                    // draw it ?
00177         bool transparent;                               // draw bgcolor & gbgcolor ?
00178         int clipoffset;                                 // offset for clipping area drawing (Symbols->full drawn, line section->limited)
00179 };
00180 
00181 #ifndef HAVE_LOG2
00182 inline double log2(double x) {return log(x)/log(2.0);}
00183 #endif
00184 
00185 #endif // PLOT_H

Generated on Sun Aug 29 14:56:04 2004 for LabPlot by doxygen 1.3.6