QtiPlot 0.9.8.2
ScaleEngine.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : ScaleEngine.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2007 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Extensions to QwtScaleEngine and QwtScaleTransformation
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef SCALE_ENGINE_H
00030 #define SCALE_ENGINE_H
00031 
00032 #include <qwt_scale_engine.h>
00033 #include <qwt_scale_map.h>
00034 #include <float.h>
00035 
00036 class ScaleEngine;
00037 
00038 class ScaleTransformation: public QwtScaleTransformation
00039 {
00040 public:
00041     enum Type{Linear, Log10, Ln, Log2, Reciprocal, Probability, Logit};
00042 
00043     ScaleTransformation(const ScaleEngine *engine):QwtScaleTransformation(Other), d_engine(engine){};
00044     virtual double xForm(double x, double, double, double p1, double p2) const;
00045     virtual double invXForm(double x, double s1, double s2, double p1, double p2) const;
00046     QwtScaleTransformation* copy() const;
00047 
00048 protected:
00049     QwtScaleTransformation* newScaleTransformation() const;
00051     const ScaleEngine* d_engine;
00052 };
00053 
00054 class ScaleEngine: public QwtScaleEngine
00055 {
00056 public:
00057     ScaleEngine(ScaleTransformation::Type type = ScaleTransformation::Linear,
00058                 double left_break = -DBL_MAX, double right_break = DBL_MAX);
00059     QwtScaleTransformation* transformation() const;
00060     virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajSteps,
00061         int maxMinSteps, double stepSize = 0.0) const;
00062     virtual void autoScale (int maxNumSteps, double &x1, double &x2, double &stepSize) const;
00063 
00064     double axisBreakLeft() const;
00065     double axisBreakRight() const;
00066     void setBreakRegion(double from, double to){d_break_left = from; d_break_right = to;};
00067 
00068     int breakWidth() const;
00069     void setBreakWidth(int width){d_break_width = width;};
00070 
00071     int breakPosition() const;
00072     void setBreakPosition(int pos){d_break_pos = pos;};
00073 
00074     double stepBeforeBreak() const;
00075     void setStepBeforeBreak(double step){d_step_before = step;};
00076 
00077     double stepAfterBreak() const;
00078     void setStepAfterBreak(double step){d_step_after = step;};
00079 
00080     int minTicksBeforeBreak() const;
00081     void setMinTicksBeforeBreak(int ticks){d_minor_ticks_before = ticks;};
00082 
00083     int minTicksAfterBreak() const;
00084     void setMinTicksAfterBreak(int ticks){d_minor_ticks_after = ticks;};
00085 
00086     bool log10ScaleAfterBreak() const;
00087     void setLog10ScaleAfterBreak(bool on){d_log10_scale_after = on;};
00088 
00089     ScaleTransformation::Type type() const;
00090     void setType(ScaleTransformation::Type type){d_type = type;};
00091 
00092     bool hasBreak() const;
00093     void clone(const ScaleEngine *engine);
00094 
00095     bool hasBreakDecoration() const;
00096     void drawBreakDecoration(bool draw){d_break_decoration = draw;};
00097 
00098 private:
00099 
00100     QwtScaleEngine *newScaleEngine() const;
00101 
00102     ScaleTransformation::Type d_type;
00103     double d_break_left, d_break_right;
00105     int d_break_pos;
00107     double d_step_before, d_step_after;
00109     int d_minor_ticks_before, d_minor_ticks_after;
00111     bool d_log10_scale_after;
00113     int d_break_width;
00115     bool d_break_decoration;
00116 };
00117 
00118 #endif