1
/***************************************************************************
2
File : Double2DateTimeFilter.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 double -> QDateTime, interpreting
8
the input numbers as (fractional) Julian days.
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 DOUBLE2DATE_TIME_FILTER_H
31
#define DOUBLE2DATE_TIME_FILTER_H
33
#include "../AbstractSimpleFilter.h"
37
#include "lib/XmlStreamReader.h"
38
#include <QXmlStreamWriter>
40
//! Conversion filter double -> QDateTime, interpreting the input numbers as (fractional) Julian days.
41
class Double2DateTimeFilter : public AbstractSimpleFilter
46
virtual QDate dateAt(int row) const {
47
if (!d_inputs.value(0)) return QDate();
48
return QDate::fromJulianDay(qRound(d_inputs.value(0)->valueAt(row)));
50
virtual QTime timeAt(int row) const {
51
if (!d_inputs.value(0)) return QTime();
52
double input_value = d_inputs.value(0)->valueAt(row);
53
// we only want the digits behind the dot and
54
// convert them from fraction of day to milliseconds
55
return QTime(12,0,0,0).addMSecs(int( (input_value - int(input_value)) * 86400000.0 ));
57
virtual QDateTime dateTimeAt(int row) const {
58
return QDateTime(dateAt(row), timeAt(row));
61
//! Return the data type of the column
62
virtual SciDAVis::ColumnDataType dataType() const { return SciDAVis::TypeQDateTime; }
65
//! Using typed ports: only double inputs are accepted.
66
virtual bool inputAcceptable(int, const AbstractColumn *source) {
67
return source->dataType() == SciDAVis::TypeDouble;
71
#endif // ifndef DOUBLE2DATE_TIME_FILTER_H