QtiPlot  0.9.8.2
ScaleDraw.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : ScaleDraw.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2006-2007 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : Extension to QwtScaleDraw
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef SCALES_H
30 #define SCALES_H
31 
32 #include <QDateTime>
33 #include <QStringList>
34 #include <QLocale>
35 
36 #include <qwt_scale_draw.h>
37 
38 class Graph;
39 
41 class ScaleDraw: public QwtScaleDraw
42 {
43 public:
44  enum TicksStyle{None = 0, Out = 1, Both = 2, In = 3};
45  enum ScaleType{Numeric = 0, Text = 1, Day = 2, Month = 3, Time = 4, Date = 5, ColHeader = 6};
49 
52  ScaleDraw(Graph *plot, const QString& formula = QString::null);
53  ScaleDraw(Graph *plot, const QStringList& labels, const QString& format, ScaleType type = Text);
54 
55  Graph *plot(){return d_plot;};
56 
57  QString formatString(){return d_format_info;}
58 
59  QString formula() {return d_formula;};
60  void setFormula(const QString& formula) {d_formula = formula;};
61 
62  double transformValue(double value) const;
63  virtual QwtText label(double value) const;
64  QString labelString(double value) const;
65 
66  int labelNumericPrecision()const {return d_prec;};
67  void setNumericPrecision(int prec){d_prec = prec;};
68 
69  int majorTicksStyle()const {return d_majTicks;};
71 
72  int minorTicksStyle()const {return d_minTicks;};
74 
76  void setShowTicksPolicy(const ShowTicksPolicy& policy){d_show_ticks_policy = policy;};
77 
78  void setSelected(bool select = true){d_selected = select;};
79 
80  int axis() const;
81 
83  void setScaleType(ScaleType type){d_type = type;};
84 
85  void labelFormat(char &f, int &prec) const;
86 
88  void setNumericFormat(NumericFormat format);
89 
90  void setDayFormat(NameFormat format);
91  void setMonthFormat(NameFormat format);
92  void setTimeFormat(const QString& format);
93  void setDateFormat(const QString& format);
94 
95  QStringList labelsList(){return d_text_labels;};
96  void setLabelsList(const QStringList& list){d_text_labels = list;};
97 
99 
100  QString prefix(){return d_prefix;};
101  void setPrefix(const QString& s){d_prefix = s;};
102  QString suffix(){return d_suffix;};
103  void setSuffix(const QString& s){d_suffix = s;};
104 
105 protected:
106  virtual void draw (QPainter *, const QPalette &) const;
107  virtual void drawLabel(QPainter *painter, double value) const;
108  virtual void drawTick(QPainter *p, double value, int len) const;
109  void drawInwardTick(QPainter *painter, double value, int len) const;
110  virtual void drawBackbone(QPainter *painter) const;
111  void drawBreak(QPainter *) const;
112 
113 private:
121  char d_fmt;
123  int d_prec;
125  QString d_formula;
135  /* - the date/time format used to calculate labels for Date/Time scales
136  * - the Column/Table name in the case of Text/ColHeader scales
137  */
138  QString d_format_info;
140  QStringList d_text_labels;
141 
143  QString d_prefix, d_suffix;
144 };
145 #endif