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