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)  

String2DayOfWeekFilter.h
Go to the documentation of this file.
1 
12 
30 #ifndef STRING2DAYOFWEEK_FILTER_H
31 #define STRING2DAYOFWEEK_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  if (input_value.isEmpty()) return QDateTime();
61  bool ok;
62  int day_value = input_value.toInt(&ok);
63  if(!ok)
64  {
65 #if QT_VERSION <= 0x040300
66  // workaround for Qt bug #171920
67  QDate temp = QDate(1900,1,1);
68  for(int i=1; i<=7; i++)
69  if( (input_value.toLower() == QDate::longDayName(i).toLower())
70  || (input_value.toLower() == QDate::shortDayName(i).toLower()) )
71  {
72  temp = QDate(1900,1,i);
73  break;
74  }
75 
76 #else
77  QDate temp = QDate::fromString(input_value, "ddd");
78  if(!temp.isValid())
79  temp = QDate::fromString(input_value, "dddd");
80 #endif
81  if(!temp.isValid())
82  return QDateTime();
83  else
84  day_value = temp.dayOfWeek();
85  }
86 
87  // Don't use Julian days here since support for years < 1 is bad
88  // Use 1900-01-01 instead (a Monday)
89  QDate result_date = QDate(1900,1,1).addDays(day_value - 1);
90  QTime result_time = QTime(0,0,0,0);
91  return QDateTime(result_date, result_time);
92  }
93  virtual bool isInvalid(int row) const {
94  const AbstractColumn *col = d_inputs.value(0);
95  if (!col) return false;
96  return !(dateTimeAt(row).isValid()) || col->isInvalid(row);
97  }
98  virtual bool isInvalid(Interval<int> i) const {
99  if (!d_inputs.value(0)) return false;
100  for (int row = i.start(); row <= i.end(); row++) {
101  if (!isInvalid(row))
102  return false;
103  }
104  return true;
105  }
106  virtual QList< Interval<int> > invalidIntervals() const
107  {
108  IntervalAttribute<bool> validity;
109  if (d_inputs.value(0)) {
110  int rows = d_inputs.value(0)->rowCount();
111  for (int i=0; i<rows; i++)
112  validity.setValue(i, isInvalid(i));
113  }
114  return validity.intervals();
115  }
116 
119 
120  protected:
121  virtual bool inputAcceptable(int, const AbstractColumn *source) {
122  return source->dataType() == SciDAVis::TypeQString;
123  }
124 };
125 
126 #endif // ifndef STRING2DAYOFWEEK_FILTER_H
127 
String2DayOfWeekFilter::inputAcceptable
virtual bool inputAcceptable(int, const AbstractColumn *source)
Give implementations a chance to reject connections to their input ports.
Definition: String2DayOfWeekFilter.h:121
String2DayOfWeekFilter::dateAt
virtual QDate dateAt(int row) const
Return the date part of row 'row'.
Definition: String2DayOfWeekFilter.h:45
String2DayOfWeekFilter::dateTimeAt
virtual QDateTime dateTimeAt(int row) const
Set the content of row 'row'.
Definition: String2DayOfWeekFilter.h:55
SciDAVis::TypeQString
@ TypeQString
Definition: globals.h:79
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
String2DayOfWeekFilter::invalidIntervals
virtual QList< Interval< int > > invalidIntervals() const
Return all intervals of invalid rows.
Definition: String2DayOfWeekFilter.h:106
AbstractColumn::dataType
virtual SciDAVis::ColumnDataType dataType() const =0
Return the data type of the column.
String2DayOfWeekFilter::isInvalid
virtual bool isInvalid(int row) const
Return whether a certain row contains an invalid value
Definition: String2DayOfWeekFilter.h:93
IntervalAttribute< bool >::setValue
void setValue(Interval< int > i, bool value=true)
Definition: IntervalAttribute.h:210
String2DayOfWeekFilter::isInvalid
virtual bool isInvalid(Interval< int > i) const
Return whether a certain interval of rows contains only invalid values
Definition: String2DayOfWeekFilter.h:98
XmlStreamReader.h
String2DayOfWeekFilter
Conversion filter String -> QDateTime, interpreting the input as days of the week (either numeric or ...
Definition: String2DayOfWeekFilter.h:41
String2DayOfWeekFilter::timeAt
virtual QTime timeAt(int row) const
Return the time part of row 'row'.
Definition: String2DayOfWeekFilter.h:50
IntervalAttribute< bool >::intervals
QList< Interval< int > > intervals() const
Definition: IntervalAttribute.h:292
String2DayOfWeekFilter::dataType
virtual SciDAVis::ColumnDataType dataType() const
Return the data type of the column.
Definition: String2DayOfWeekFilter.h:118
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 >
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