QtiPlot 0.9.8.2
ScaleDraw.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : ScaleDraw.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006-2007 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Extension to QwtScaleDraw
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 SCALES_H
00030 #define SCALES_H
00031 
00032 #include <QDateTime>
00033 #include <QStringList>
00034 #include <QLocale>
00035 
00036 #include <qwt_scale_draw.h>
00037 
00038 class Graph;
00039     
00041 class ScaleDraw: public QwtScaleDraw
00042 {
00043 public:
00044     enum TicksStyle{None = 0, Out = 1, Both = 2, In = 3};
00045     enum ScaleType{Numeric = 0, Text = 1, Day = 2, Month = 3, Time = 4, Date = 5, ColHeader = 6};
00046     enum NumericFormat{Automatic, Decimal, Scientific, Superscripts, Engineering, SuperscriptsGER};
00047     enum NameFormat{ShortName, LongName, Initial};
00048     enum ShowTicksPolicy{ShowAll = 0, HideBegin = 1, HideEnd = 2, HideBeginEnd = 3};
00049 
00051     ScaleDraw(Graph *plot, ScaleDraw *sd);
00052     ScaleDraw(Graph *plot, const QString& formula = QString::null);
00053     ScaleDraw(Graph *plot, const QStringList& labels, const QString& format, ScaleType type = Text);
00054 
00055     Graph *plot(){return d_plot;};
00056 
00057     QString formatString();
00058     QString format(){return d_format_info;};
00059 
00060     QString formula() {return d_formula;};
00061     void setFormula(const QString& formula) {d_formula = formula;};
00062 
00063     double transformValue(double value) const;
00064     virtual QwtText label(double value) const;
00065     QString labelString(double value) const;
00066 
00067     int labelNumericPrecision()const {return d_prec;};
00068     void setNumericPrecision(int prec){d_prec = prec;};
00069 
00070     int majorTicksStyle()const {return d_majTicks;};
00071     void setMajorTicksStyle(TicksStyle type){d_majTicks = type;};
00072 
00073     int minorTicksStyle()const {return d_minTicks;};
00074     void setMinorTicksStyle(TicksStyle type){d_minTicks = type;};
00075 
00076     ShowTicksPolicy showTicksPolicy(){return d_show_ticks_policy;};
00077     void setShowTicksPolicy(const ShowTicksPolicy& policy){d_show_ticks_policy = policy;};
00078 
00079     void setSelected(bool select = true){d_selected = select;};
00080 
00081     int axis() const;
00082 
00083     ScaleType scaleType(){return d_type;};
00084     void setScaleType(ScaleType type){d_type = type;};
00085 
00086     void labelFormat(char &f, int &prec) const;
00087 
00088     NumericFormat labelNumericFormat(){return d_numeric_format;};
00089     void setNumericFormat(NumericFormat format);
00090 
00091     void setDayFormat(NameFormat format);
00092     void setMonthFormat(NameFormat format);
00093     void setTimeFormat(const QString& format, const QTime& t = QTime());
00094     void setDateFormat(const QString& format, const QDateTime& d = QDateTime());
00095 
00096     QDateTime dateTimeOrigin(){return d_date_time_origin;};
00097     void setDateTimeOrigin(const QDateTime& d){d_date_time_origin = d;};
00098 
00099     QStringList labelsList(){return d_text_labels;};
00100     void setLabelsList(const QStringList& list){d_text_labels = list;};
00101 
00102     NameFormat nameFormat(){return d_name_format;};
00103 
00104     QString prefix(){return d_prefix;};
00105     void setPrefix(const QString& s){d_prefix = s;};
00106     QString suffix(){return d_suffix;};
00107     void setSuffix(const QString& s){d_suffix = s;};
00108 
00109 protected:
00110     virtual void draw (QPainter *, const QPalette &) const;
00111     virtual void drawLabel(QPainter *painter, double value) const;
00112     virtual void drawTick(QPainter *p, double value, int len) const;
00113     void drawInwardTick(QPainter *painter, double value, int len) const;
00114     virtual void drawBackbone(QPainter *painter) const;
00115     void drawBreak(QPainter *) const;
00116 
00117 private:
00119     Graph *d_plot;
00121     ScaleType d_type;
00123     NumericFormat d_numeric_format;
00125     char d_fmt;
00127     int d_prec;
00129     QString d_formula;
00131     int d_majTicks;
00133     int d_minTicks;
00135     bool d_selected;
00137     NameFormat d_name_format;
00139     QDateTime d_date_time_origin;
00141     /* - the date/time format used to calculate labels for Date/Time scales
00142      * - the Column/Table name in the case of Text/ColHeader scales
00143      */
00144     QString d_format_info;
00146     QStringList d_text_labels;
00147 
00148     ShowTicksPolicy d_show_ticks_policy;
00149     QString d_prefix, d_suffix;
00150 };
00151 #endif