File indexing completed on 2024-06-16 03:42:35

0001 /*
0002     File                 : BigInt2DayOfWeekFilter.h
0003     Project              : AbstractColumn
0004     Description          : Conversion filter bigint -> QDateTime, interpreting
0005     the input numbers as days of the week (1 -> Monday).
0006     --------------------------------------------------------------------
0007     SPDX-FileCopyrightText: 2020 Stefan Gerlach <stefan.gerlach@uni.kn>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef BIGINT2DAY_OF_WEEK_FILTER_H
0012 #define BIGINT2DAY_OF_WEEK_FILTER_H
0013 
0014 #include "../AbstractSimpleFilter.h"
0015 #include <QDateTime>
0016 
0017 //! Conversion filter int -> QDateTime, interpreting the input numbers as days of the week (1 = Monday).
0018 class BigInt2DayOfWeekFilter : public AbstractSimpleFilter {
0019     Q_OBJECT
0020 
0021 public:
0022     QDate dateAt(int row) const override {
0023         if (!m_inputs.value(0))
0024             return QDate();
0025         qint64 inputValue = m_inputs.value(0)->bigIntAt(row);
0026         // Don't use Julian days here since support for years < 1 is bad
0027         // Use 1900-01-01 instead (a Monday)
0028         return QDate(1900, 1, 1).addDays(inputValue);
0029     }
0030     QTime timeAt(int row) const override {
0031         Q_UNUSED(row)
0032         return QTime(0, 0, 0, 0);
0033     }
0034     QDateTime dateTimeAt(int row) const override {
0035         return QDateTime(dateAt(row), timeAt(row));
0036     }
0037 
0038     //! Return the data type of the column
0039     AbstractColumn::ColumnMode columnMode() const override {
0040         return AbstractColumn::ColumnMode::Day;
0041     }
0042 
0043 protected:
0044     //! Using typed ports: only bigint inputs are accepted.
0045     bool inputAcceptable(int, const AbstractColumn* source) override {
0046         return source->columnMode() == AbstractColumn::ColumnMode::BigInt;
0047     }
0048 };
0049 
0050 #endif // ifndef BIGINT2DAY_OF_WEEK_FILTER_H