scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

String2DoubleFilter.h
Go to the documentation of this file.
1 
11 
29 #ifndef STRING2DOUBLE_FILTER_H
30 #define STRING2DOUBLE_FILTER_H
31 
32 #include "../AbstractSimpleFilter.h"
33 #include <QLocale>
34 #include "lib/XmlStreamReader.h"
35 #include <QXmlStreamWriter>
36 #include <QtDebug>
37 
40 {
41  Q_OBJECT
42 
43  public:
45  void setNumericLocale(QLocale locale) { d_numeric_locale = locale; d_use_default_locale = false; }
47 
48  virtual double valueAt(int row) const {
49  if (!d_inputs.value(0)) return 0;
50  if (d_use_default_locale) // we need a new QLocale instance here in case the default changed since the last call
51  return QLocale().toDouble(d_inputs.value(0)->textAt(row));
52  return d_numeric_locale.toDouble(d_inputs.value(0)->textAt(row));
53  }
54  virtual bool isInvalid(int row) const {
55  if (!d_inputs.value(0)) return false;
56  bool ok;
58  QLocale().toDouble(d_inputs.value(0)->textAt(row), &ok);
59  else
60  d_numeric_locale.toDouble(d_inputs.value(0)->textAt(row), &ok);
61  return !ok;
62  }
63  virtual bool isInvalid(Interval<int> i) const {
64  if (!d_inputs.value(0)) return false;
65  QLocale locale;
67  locale = d_numeric_locale;
68  for (int row = i.start(); row <= i.end(); row++) {
69  bool ok;
70  locale.toDouble(d_inputs.value(0)->textAt(row), &ok);
71  if (ok)
72  return false;
73  }
74  return true;
75  }
76  virtual QList< Interval<int> > invalidIntervals() const
77  {
78  IntervalAttribute<bool> validity;
79  if (d_inputs.value(0)) {
80  int rows = d_inputs.value(0)->rowCount();
81  for (int i=0; i<rows; i++)
82  validity.setValue(i, isInvalid(i));
83  }
84  return validity.intervals();
85  }
86 
87 
90 
91  protected:
93  virtual bool inputAcceptable(int, const AbstractColumn *source) {
94  return source->dataType() == SciDAVis::TypeQString;
95  }
96 
97  private:
100 };
101 
102 #endif // ifndef STRING2DOUBLE_FILTER_H
103 
String2DoubleFilter::setNumericLocaleToDefault
void setNumericLocaleToDefault()
Definition: String2DoubleFilter.h:46
String2DoubleFilter::valueAt
virtual double valueAt(int row) const
Return the double value in row 'row'.
Definition: String2DoubleFilter.h:48
SciDAVis::TypeQString
@ TypeQString
Definition: globals.h:79
SciDAVis::ColumnDataType
ColumnDataType
Column data type.
Definition: globals.h:77
String2DoubleFilter::setNumericLocale
void setNumericLocale(QLocale locale)
Definition: String2DoubleFilter.h:45
IntervalAttribute< bool >
A class representing an interval-based attribute (bool version)
Definition: IntervalAttribute.h:198
AbstractColumn::dataType
virtual SciDAVis::ColumnDataType dataType() const =0
Return the data type of the column.
String2DoubleFilter::isInvalid
virtual bool isInvalid(int row) const
Return whether a certain row contains an invalid value
Definition: String2DoubleFilter.h:54
String2DoubleFilter::String2DoubleFilter
String2DoubleFilter()
Definition: String2DoubleFilter.h:44
IntervalAttribute< bool >::setValue
void setValue(Interval< int > i, bool value=true)
Definition: IntervalAttribute.h:210
String2DoubleFilter::d_numeric_locale
QLocale d_numeric_locale
Definition: String2DoubleFilter.h:98
String2DoubleFilter::isInvalid
virtual bool isInvalid(Interval< int > i) const
Return whether a certain interval of rows contains only invalid values
Definition: String2DoubleFilter.h:63
XmlStreamReader.h
SciDAVis::TypeDouble
@ TypeDouble
Definition: globals.h:78
String2DoubleFilter::invalidIntervals
virtual QList< Interval< int > > invalidIntervals() const
Return all intervals of invalid rows.
Definition: String2DoubleFilter.h:76
String2DoubleFilter::inputAcceptable
virtual bool inputAcceptable(int, const AbstractColumn *source)
Using typed ports: only string inputs are accepted.
Definition: String2DoubleFilter.h:93
String2DoubleFilter
Locale-aware conversion filter QString -> double.
Definition: String2DoubleFilter.h:40
IntervalAttribute< bool >::intervals
QList< Interval< int > > intervals() const
Definition: IntervalAttribute.h:292
AbstractSimpleFilter
Simplified filter interface for filters with only one output port.
Definition: AbstractSimpleFilter.h:129
String2DoubleFilter::d_use_default_locale
bool d_use_default_locale
Definition: String2DoubleFilter.h:99
String2DoubleFilter::dataType
virtual SciDAVis::ColumnDataType dataType() const
Return the data type of the column.
Definition: String2DoubleFilter.h:89
Interval< int >
AbstractFilter::d_inputs
QVector< const AbstractColumn * > d_inputs
The data sources connected to my input ports.
Definition: AbstractFilter.h:275
AbstractColumn
Interface definition for data with column logic.
Definition: AbstractColumn.h:82