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)  

String2MonthFilter.h
Go to the documentation of this file.
1 
12 
30 #ifndef STRING2MONTH_FILTER_H
31 #define STRING2MONTH_FILTER_H
32 
33 #include "../AbstractSimpleFilter.h"
34 #include <QDateTime>
35 #include <math.h>
36 #include "lib/XmlStreamReader.h"
37 #include <QXmlStreamWriter>
38 
41 {
42  Q_OBJECT
43 
44  public:
45  virtual QDate dateAt(int row) const
46  {
47  return dateTimeAt(row).date();
48  }
49 
50  virtual QTime timeAt(int row) const
51  {
52  return dateTimeAt(row).time();
53  }
54 
55  virtual QDateTime dateTimeAt(int row) const
56  {
57  if (!d_inputs.value(0)) return QDateTime();
58 
59  QString input_value = d_inputs.value(0)->textAt(row);
60  bool ok;
61  int month_value = input_value.toInt(&ok);
62  if(!ok)
63  {
64  QDate temp = QDate::fromString(input_value, "MMM");
65  if(!temp.isValid())
66  temp = QDate::fromString(input_value, "MMMM");
67  if(!temp.isValid())
68  return QDateTime();
69  else
70  month_value = temp.month();
71  }
72 
73  // Don't use Julian days here since support for years < 1 is bad
74  // Use 1900-01-01 instead
75  QDate result_date = QDate(1900,1,1).addMonths(month_value - 1);
76  QTime result_time = QTime(0,0,0,0);
77  return QDateTime(result_date, result_time);
78  }
79  virtual bool isInvalid(int row) const {
80  const AbstractColumn *col = d_inputs.value(0);
81  if (!col) return false;
82  return !(dateTimeAt(row).isValid()) || col->isInvalid(row);
83  }
84  virtual bool isInvalid(Interval<int> i) const {
85  if (!d_inputs.value(0)) return false;
86  for (int row = i.start(); row <= i.end(); row++) {
87  if (!isInvalid(row))
88  return false;
89  }
90  return true;
91  }
92  virtual QList< Interval<int> > invalidIntervals() const
93  {
94  IntervalAttribute<bool> validity;
95  if (d_inputs.value(0)) {
96  int rows = d_inputs.value(0)->rowCount();
97  for (int i=0; i<rows; i++)
98  validity.setValue(i, isInvalid(i));
99  }
100  return validity.intervals();
101  }
102 
105 
106  protected:
107  virtual bool inputAcceptable(int, const AbstractColumn *source) {
108  return source->dataType() == SciDAVis::TypeQString;
109  }
110 };
111 
112 #endif // ifndef STRING2MONTH_FILTER_H
113 
String2MonthFilter::dateAt
virtual QDate dateAt(int row) const
Return the date part of row 'row'.
Definition: String2MonthFilter.h:45
SciDAVis::TypeQString
@ TypeQString
Definition: globals.h:79
String2MonthFilter
Conversion filter String -> QDateTime, interpreting the input as months of the year (either numeric o...
Definition: String2MonthFilter.h:41
String2MonthFilter::timeAt
virtual QTime timeAt(int row) const
Return the time part of row 'row'.
Definition: String2MonthFilter.h:50
SciDAVis::ColumnDataType
ColumnDataType
Column data type.
Definition: globals.h:77
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.
String2MonthFilter::inputAcceptable
virtual bool inputAcceptable(int, const AbstractColumn *source)
Give implementations a chance to reject connections to their input ports.
Definition: String2MonthFilter.h:107
IntervalAttribute< bool >::setValue
void setValue(Interval< int > i, bool value=true)
Definition: IntervalAttribute.h:210
String2MonthFilter::isInvalid
virtual bool isInvalid(Interval< int > i) const
Return whether a certain interval of rows contains only invalid values
Definition: String2MonthFilter.h:84
XmlStreamReader.h
String2MonthFilter::dataType
virtual SciDAVis::ColumnDataType dataType() const
Return the data type of the column.
Definition: String2MonthFilter.h:104
String2MonthFilter::dateTimeAt
virtual QDateTime dateTimeAt(int row) const
Set the content of row 'row'.
Definition: String2MonthFilter.h:55
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
SciDAVis::TypeQDateTime
@ TypeQDateTime
Definition: globals.h:80
AbstractColumn::isInvalid
virtual bool isInvalid(int row) const
Return whether a certain row contains an invalid value
Definition: AbstractColumn.h:154
Interval< int >
String2MonthFilter::isInvalid
virtual bool isInvalid(int row) const
Return whether a certain row contains an invalid value
Definition: String2MonthFilter.h:79
AbstractFilter::d_inputs
QVector< const AbstractColumn * > d_inputs
The data sources connected to my input ports.
Definition: AbstractFilter.h:275
String2MonthFilter::invalidIntervals
virtual QList< Interval< int > > invalidIntervals() const
Return all intervals of invalid rows.
Definition: String2MonthFilter.h:92
AbstractColumn
Interface definition for data with column logic.
Definition: AbstractColumn.h:82