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