~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/future/core/datatypes/Double2DateTimeFilter.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : Double2DateTimeFilter.h
 
3
    Project              : SciDAVis
 
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.
 
9
                           
 
10
 ***************************************************************************/
 
11
 
 
12
/***************************************************************************
 
13
 *                                                                         *
 
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.                                    *
 
18
 *                                                                         *
 
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.                           *
 
23
 *                                                                         *
 
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                                           *
 
28
 *                                                                         *
 
29
 ***************************************************************************/
 
30
#ifndef DOUBLE2DATE_TIME_FILTER_H
 
31
#define DOUBLE2DATE_TIME_FILTER_H
 
32
 
 
33
#include "../AbstractSimpleFilter.h"
 
34
#include <QDateTime>
 
35
#include <QDate>
 
36
#include <QTime>
 
37
#include "lib/XmlStreamReader.h"
 
38
#include <QXmlStreamWriter>
 
39
 
 
40
//! Conversion filter double -> QDateTime, interpreting the input numbers as (fractional) Julian days.
 
41
class Double2DateTimeFilter : public AbstractSimpleFilter
 
42
{
 
43
        Q_OBJECT
 
44
 
 
45
        public:
 
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)));
 
49
                }
 
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 ));
 
56
                }
 
57
                virtual QDateTime dateTimeAt(int row) const {
 
58
                        return QDateTime(dateAt(row), timeAt(row));
 
59
                }
 
60
 
 
61
                //! Return the data type of the column
 
62
                virtual SciDAVis::ColumnDataType dataType() const { return SciDAVis::TypeQDateTime; }
 
63
 
 
64
        protected:
 
65
                //! Using typed ports: only double inputs are accepted.
 
66
                virtual bool inputAcceptable(int, const AbstractColumn *source) {
 
67
                        return source->dataType() == SciDAVis::TypeDouble;
 
68
                }
 
69
};
 
70
 
 
71
#endif // ifndef DOUBLE2DATE_TIME_FILTER_H
 
72