SciDAVis  1.D4
Double2StringFilter.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Double2StringFilter.h
3  Project : SciDAVis
4  --------------------------------------------------------------------
5  Copyright : (C) 2007 by Knut Franke, Tilman Benkert
6  Email (use @ for *) : knut.franke*gmx.de, thzs@gmx.net
7  Description : Locale-aware conversion filter double -> QString.
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 DOUBLE2STRING_FILTER_H
30 #define DOUBLE2STRING_FILTER_H
31 
32 #include "../AbstractSimpleFilter.h"
33 #include <QLocale>
34 #include <QChar>
35 #include <QtDebug>
36 
39 {
40  Q_OBJECT
41 
42  public:
44  explicit Double2StringFilter(char format='e', int digits=6) : d_format(format), d_digits(digits) {}
46  void setNumericFormat(char format);
48  void setNumDigits(int digits);
50  char numericFormat() const { return d_format; }
52  int numDigits() const { return d_digits; }
53 
56 
57  signals:
58  void formatChanged();
59 
60  private:
64  char d_format;
66  int d_digits;
67 
68 
70 
71  virtual void writeExtraAttributes(QXmlStreamWriter * writer) const;
72  virtual bool load(XmlStreamReader * reader);
74 
75  public:
76  virtual QString textAt(int row) const {
77  if (!d_inputs.value(0)) return QString();
78  if (d_inputs.value(0)->rowCount() <= row) return QString();
79  if (d_inputs.value(0)->isInvalid(row)) return QString();
80  return QLocale().toString(d_inputs.value(0)->valueAt(row), d_format, d_digits);
81  }
82 
83  protected:
85  virtual bool inputAcceptable(int, const AbstractColumn *source) {
86  return source->dataType() == SciDAVis::TypeDouble;
87  }
88 };
89 
90 class Double2StringFilterSetFormatCmd : public QUndoCommand
91 {
92  public:
93  Double2StringFilterSetFormatCmd(Double2StringFilter* target, char new_format);
94 
95  virtual void redo();
96  virtual void undo();
97 
98  private:
101 };
102 
103 class Double2StringFilterSetDigitsCmd : public QUndoCommand
104 {
105  public:
106  Double2StringFilterSetDigitsCmd(Double2StringFilter* target, int new_digits);
107 
108  virtual void redo();
109  virtual void undo();
110 
111  private:
114 };
115 
116 
117 #endif // ifndef DOUBLE2STRING_FILTER_H
118