1
/***************************************************************************
2
File : String2DayOfWeekFilter.h
4
--------------------------------------------------------------------
5
Copyright : (C) 2007 by Knut Franke, Tilman Benkert
6
Email (use @ for *) : knut.franke*gmx.de, thzs*gmx.net
7
Description : Conversion filter String -> QDateTime, interpreting
8
the input as days of the week (either numeric or "Mon" etc).
10
***************************************************************************/
12
/***************************************************************************
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
19
* This program is distributed in the hope that it will be useful, *
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22
* GNU General Public License for more details. *
24
* You should have received a copy of the GNU General Public License *
25
* along with this program; if not, write to the Free Software *
26
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27
* Boston, MA 02110-1301 USA *
29
***************************************************************************/
30
#ifndef STRING2DAYOFWEEK_FILTER_H
31
#define STRING2DAYOFWEEK_FILTER_H
33
#include "../AbstractSimpleFilter.h"
36
#include "lib/XmlStreamReader.h"
37
#include <QXmlStreamWriter>
39
//! Conversion filter String -> QDateTime, interpreting the input as days of the week (either numeric or "Mon" etc).
40
class String2DayOfWeekFilter : public AbstractSimpleFilter
45
virtual QDate dateAt(int row) const
47
return dateTimeAt(row).date();
50
virtual QTime timeAt(int row) const
52
return dateTimeAt(row).time();
55
virtual QDateTime dateTimeAt(int row) const
57
if (!d_inputs.value(0)) return QDateTime();
59
QString input_value = d_inputs.value(0)->textAt(row);
60
if (input_value.isEmpty()) return QDateTime();
62
int day_value = input_value.toInt(&ok);
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()) )
72
temp = QDate(1900,1,i);
77
QDate temp = QDate::fromString(input_value, "ddd");
79
temp = QDate::fromString(input_value, "dddd");
84
day_value = temp.dayOfWeek();
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);
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);
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++) {
106
virtual QList< Interval<int> > invalidIntervals() const
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));
114
return validity.intervals();
117
//! Return the data type of the column
118
virtual SciDAVis::ColumnDataType dataType() const { return SciDAVis::TypeQDateTime; }
121
virtual bool inputAcceptable(int, const AbstractColumn *source) {
122
return source->dataType() == SciDAVis::TypeQString;
126
#endif // ifndef STRING2DAYOFWEEK_FILTER_H