QtiPlot 0.9.8.2
|
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(){return d_format_info;} 00058 00059 QString formula() {return d_formula;}; 00060 void setFormula(const QString& formula) {d_formula = formula;}; 00061 00062 double transformValue(double value) const; 00063 virtual QwtText label(double value) const; 00064 QString labelString(double value) const; 00065 00066 int labelNumericPrecision()const {return d_prec;}; 00067 void setNumericPrecision(int prec){d_prec = prec;}; 00068 00069 int majorTicksStyle()const {return d_majTicks;}; 00070 void setMajorTicksStyle(TicksStyle type){d_majTicks = type;}; 00071 00072 int minorTicksStyle()const {return d_minTicks;}; 00073 void setMinorTicksStyle(TicksStyle type){d_minTicks = type;}; 00074 00075 ShowTicksPolicy showTicksPolicy(){return d_show_ticks_policy;}; 00076 void setShowTicksPolicy(const ShowTicksPolicy& policy){d_show_ticks_policy = policy;}; 00077 00078 void setSelected(bool select = true){d_selected = select;}; 00079 00080 int axis() const; 00081 00082 ScaleType scaleType(){return d_type;}; 00083 void setScaleType(ScaleType type){d_type = type;}; 00084 00085 void labelFormat(char &f, int &prec) const; 00086 00087 NumericFormat labelNumericFormat(){return d_numeric_format;}; 00088 void setNumericFormat(NumericFormat format); 00089 00090 void setDayFormat(NameFormat format); 00091 void setMonthFormat(NameFormat format); 00092 void setTimeFormat(const QString& format); 00093 void setDateFormat(const QString& format); 00094 00095 QStringList labelsList(){return d_text_labels;}; 00096 void setLabelsList(const QStringList& list){d_text_labels = list;}; 00097 00098 NameFormat nameFormat(){return d_name_format;}; 00099 00100 QString prefix(){return d_prefix;}; 00101 void setPrefix(const QString& s){d_prefix = s;}; 00102 QString suffix(){return d_suffix;}; 00103 void setSuffix(const QString& s){d_suffix = s;}; 00104 00105 protected: 00106 virtual void draw (QPainter *, const QPalette &) const; 00107 virtual void drawLabel(QPainter *painter, double value) const; 00108 virtual void drawTick(QPainter *p, double value, int len) const; 00109 void drawInwardTick(QPainter *painter, double value, int len) const; 00110 virtual void drawBackbone(QPainter *painter) const; 00111 void drawBreak(QPainter *) const; 00112 00113 private: 00115 Graph *d_plot; 00117 ScaleType d_type; 00119 NumericFormat d_numeric_format; 00121 char d_fmt; 00123 int d_prec; 00125 QString d_formula; 00127 int d_majTicks; 00129 int d_minTicks; 00131 bool d_selected; 00133 NameFormat d_name_format; 00135 /* - the date/time format used to calculate labels for Date/Time scales 00136 * - the Column/Table name in the case of Text/ColHeader scales 00137 */ 00138 QString d_format_info; 00140 QStringList d_text_labels; 00141 00142 ShowTicksPolicy d_show_ticks_policy; 00143 QString d_prefix, d_suffix; 00144 }; 00145 #endif