1
/***************************************************************************
2
File : String2DateTimeFilter.h
4
--------------------------------------------------------------------
5
Copyright : (C) 2007 by Tilman Benkert,
7
Email (use @ for *) : thzs*gmx.net, knut.franke*gmx.de
8
Description : Conversion filter QString -> QDateTime.
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 STRING2DATE_TIME_FILTER_H
31
#define STRING2DATE_TIME_FILTER_H
33
#include "core/AbstractSimpleFilter.h"
39
* \brief Conversion filter QString -> QDateTime.
41
* The standard use of this filter is explicitly specifiying the date/time format of the strings
42
* on the input, either in the constructor or via setFormat().
43
* However, if the input fails to comply to this format, String2DateTimeFilter
44
* tries to guess the format, using internal lists of common date and time formats (#date_formats
47
class String2DateTimeFilter : public AbstractSimpleFilter
52
//! Standard constructor.
53
explicit String2DateTimeFilter(QString format="yyyy-MM-dd hh:mm:ss.zzz") : d_format(format) {}
54
//! Set the format string to be used for conversion.
55
void setFormat(const QString& format);
56
//! Return the format string
58
* The default format string is "yyyy-MM-dd hh:mm:ss.zzz".
59
* \sa QDate::toString()
61
QString format() const { return d_format; }
63
//! Return the data type of the column
64
virtual SciDAVis::ColumnDataType dataType() const { return SciDAVis::TypeQDateTime; }
66
//! \name XML related functions
68
virtual void writeExtraAttributes(QXmlStreamWriter * writer) const;
69
virtual bool load(XmlStreamReader * reader);
76
friend class String2DateTimeFilterSetFormatCmd;
77
//! The format string.
80
static const char * date_formats[];
81
static const char * time_formats[];
84
virtual QDateTime dateTimeAt(int row) const;
85
virtual QDate dateAt(int row) const { return dateTimeAt(row).date(); }
86
virtual QTime timeAt(int row) const { return dateTimeAt(row).time(); }
87
virtual bool isInvalid(int row) const {
88
const AbstractColumn *col = d_inputs.value(0);
89
if (!col) return false;
90
return !(dateTimeAt(row).isValid()) || col->isInvalid(row);
92
virtual bool isInvalid(Interval<int> i) const {
93
if (!d_inputs.value(0)) return false;
94
for (int row = i.start(); row <= i.end(); row++) {
100
virtual QList< Interval<int> > invalidIntervals() const
102
IntervalAttribute<bool> validity;
103
if (d_inputs.value(0)) {
104
int rows = d_inputs.value(0)->rowCount();
105
for (int i=0; i<rows; i++)
106
validity.setValue(i, isInvalid(i));
108
return validity.intervals();
112
//! Using typed ports: only string inputs are accepted.
113
virtual bool inputAcceptable(int, const AbstractColumn *source) {
114
return source->dataType() == SciDAVis::TypeQString;
118
class String2DateTimeFilterSetFormatCmd : public QUndoCommand
121
String2DateTimeFilterSetFormatCmd(String2DateTimeFilter* target, const QString &new_format);
127
String2DateTimeFilter* d_target;
128
QString d_other_format;
131
#endif // ifndef STRING2DATE_TIME_FILTER_H