ScaleDraw.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : ScaleDraw.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
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 
00039 class ScaleDraw: public QwtScaleDraw
00040 {
00041 public:
00042     enum TicksStyle{None = 0, Out = 1, Both = 2, In = 3};
00043 
00044     ScaleDraw(const QString& s = QString::null);
00045     virtual ~ScaleDraw(){};
00046 
00047     QString formulaString() {return formula_string;};
00048     void setFormulaString(const QString& formula) {formula_string = formula;};
00049 
00050     double transformValue(double value) const;
00051 
00052     virtual QwtText label(double value) const
00053     {
00054     return QwtText(QLocale().toString(transformValue(value), d_fmt, d_prec));
00055     };
00056 
00057     void labelFormat(char &f, int &prec) const;
00058     void setLabelFormat(char f, int prec);
00059 
00060     int labelNumericPrecision(){return d_prec;};
00061 
00062     int majorTicksStyle(){return d_majTicks;};
00063     void setMajorTicksStyle(TicksStyle type){d_majTicks = type;};
00064 
00065     int minorTicksStyle(){return d_minTicks;};
00066     void setMinorTicksStyle(TicksStyle type){d_minTicks = type;};
00067 
00068 protected:
00069     void drawTick(QPainter *p, double value, int len) const;
00070 
00071 private:
00072     QString formula_string;
00073     char d_fmt;
00074     int d_prec;
00075     int d_minTicks, d_majTicks;
00076 };
00077 
00078 class QwtTextScaleDraw: public ScaleDraw
00079 {
00080 public:
00081     QwtTextScaleDraw(const QStringList& list);
00082     ~QwtTextScaleDraw(){};
00083 
00084     QwtText label(double value) const;
00085 
00086     QStringList labelsList(){return labels;};
00087 private:
00088     QStringList labels;
00089 };
00090 
00091 class TimeScaleDraw: public ScaleDraw
00092 {
00093 public:
00094     TimeScaleDraw(const QTime& t, const QString& format);
00095     ~TimeScaleDraw(){};
00096 
00097     QString origin();
00098     QString timeFormat() {return t_format;};
00099 
00100     QwtText label(double value) const;
00101 
00102 private:
00103     QTime t_origin;
00104     QString t_format;
00105 };
00106 
00107 class DateScaleDraw: public ScaleDraw
00108 {
00109 public:
00110     DateScaleDraw(const QDate& t, const QString& format);
00111     ~DateScaleDraw(){};
00112 
00113     QString origin();
00114 
00115     QString format() {return t_format;};
00116     QwtText label(double value) const;
00117 
00118 private:
00119     QDate t_origin;
00120     QString t_format;
00121 };
00122 
00123 class WeekDayScaleDraw: public ScaleDraw
00124 {
00125 public:
00126     enum NameFormat{ShortName, LongName, Initial};
00127 
00128     WeekDayScaleDraw(NameFormat format = ShortName);
00129     ~WeekDayScaleDraw(){};
00130 
00131     NameFormat format() {return d_format;};
00132     QwtText label(double value) const;
00133 
00134 private:
00135     NameFormat d_format;
00136 };
00137 
00138 class MonthScaleDraw: public ScaleDraw
00139 {
00140 public:
00141     enum NameFormat{ShortName, LongName, Initial};
00142 
00143     MonthScaleDraw(NameFormat format = ShortName);
00144     ~MonthScaleDraw(){};
00145 
00146     NameFormat format() {return d_format;};
00147     QwtText label(double value) const;
00148 
00149 private:
00150     NameFormat d_format;
00151 };
00152 
00153 class QwtSupersciptsScaleDraw: public ScaleDraw
00154 {
00155 public:
00156     QwtSupersciptsScaleDraw(const QString& s = QString::null);
00157     ~QwtSupersciptsScaleDraw(){};
00158 
00159     QwtText label(double value) const;
00160 };
00161 
00162 #endif

Generated on Mon Oct 15 06:11:42 2007 for QtiPlot by  doxygen 1.5.3