SciDAVis  1.D4
ScaleDraw.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : ScaleDraw.h
3  Project : SciDAVis
4  --------------------------------------------------------------------
5  Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
6  Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
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 #include <QMap>
36 
37 #include <qwt_scale_draw.h>
38 
40 class ScaleDraw: public QwtScaleDraw
41 {
42 public:
43  enum TicksStyle{None = 0, Out = 1, Both = 2, In = 3};
44 
45  ScaleDraw(const QString& s = QString::null);
46  ScaleDraw(const ScaleDraw &other, const QString &s = QString::null);
47  virtual ~ScaleDraw(){};
48 
49  QString formulaString() {return formula_string;};
50  void setFormulaString(const QString& formula) {formula_string = formula;};
51 
52  double transformValue(double value) const;
53 
54  virtual QwtText label(double value) const
55  {
56  return QwtText(QLocale().toString(transformValue(value), d_fmt, d_prec));
57  };
58 
59  void labelFormat(char &f, int &prec) const;
60  void setLabelFormat(char f, int prec);
61 
62  int labelNumericPrecision() const { return d_prec; };
63 
64  int majorTicksStyle() const { return d_majTicks; };
66 
67  int minorTicksStyle() const { return d_minTicks; };
69 
70 protected:
71  void drawTick(QPainter *p, double value, int len) const;
72 
73 private:
74  QString formula_string;
75  char d_fmt;
76  int d_prec;
78 };
79 
81 {
82 public:
83  QwtTextScaleDraw(const QMap<int, QString>& list);
84  QwtTextScaleDraw(const ScaleDraw &other, const QMap<int, QString>& list) :
85  ScaleDraw(other), labels(list)
86  {}
88 
89  QwtText label(double value) const;
90 
91  QStringList labelsList() { return QStringList(labels.values()); }
92  QMap<int, QString> labelsMap() { return labels; }
93  void setLabelsMap(const QMap<int, QString>& list) { labels = list; }
94 private:
95  QMap<int, QString> labels;
96 };
97 
98 class TimeScaleDraw: public ScaleDraw
99 {
100 public:
101  TimeScaleDraw(const QTime& t, const QString& format);
102  TimeScaleDraw(const ScaleDraw &other, const QTime& t, const QString& format) :
103  ScaleDraw(other), t_origin(t), t_format(format)
104  {}
106 
107  QString origin();
108  QString timeFormat() {return t_format;};
109 
110  QwtText label(double value) const;
111 
112 private:
113  QTime t_origin;
114  QString t_format;
115 };
116 
118 {
119 public:
120  DateScaleDraw(const QDate& t, const QString& format);
121  DateScaleDraw(const ScaleDraw &other, const QDate& t, const QString& format) :
122  ScaleDraw(other), t_origin(t), t_format(format)
123  {}
125 
126  QString origin();
127 
128  QString format() {return t_format;};
129  QwtText label(double value) const;
130 
131 private:
132  QDate t_origin;
133  QString t_format;
134 };
135 
137 {
138 public:
139  DateTimeScaleDraw(const QDateTime & origin, const QString & format);
140  DateTimeScaleDraw(const ScaleDraw &other, const QDateTime & origin, const QString & format)
141  : ScaleDraw(other), d_origin(origin), d_format(format)
142  {}
144 
145  QString origin();
146 
147  QString format() { return d_format; };
148  QwtText label(double value) const;
149 
150 private:
151  QDateTime d_origin;
152  QString d_format;
153 };
154 
156 {
157 public:
159 
162  ScaleDraw(other), d_format(format)
163  {}
165 
167  QwtText label(double value) const;
168 
169 private:
171 };
172 
174 {
175 public:
177 
180  ScaleDraw(other), d_format(format)
181  {}
183 
185  QwtText label(double value) const;
186 
187 private:
189 };
190 
192 {
193 public:
194  QwtSupersciptsScaleDraw(const QString& s = QString::null);
195  QwtSupersciptsScaleDraw(const ScaleDraw &other, const QString& s = QString::null) :
196  ScaleDraw(other)
197  {
198  setFormulaString(s);
199  }
201 
202  QwtText label(double value) const;
203 };
204 
205 #endif