File indexing completed on 2024-05-12 03:48:29
0001 /* 0002 File : DateTimeSpinBox.h 0003 Project : LabPlot 0004 Description : widget for setting datetimes with a spinbox 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2019 Martin Marmsoler <martin.marmsoler@gmail.com> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef DATETIMESPINBOX_H 0011 #define DATETIMESPINBOX_H 0012 0013 #include <QAbstractSpinBox> 0014 0015 #include "src/backend/core/Time.h" 0016 0017 class QRegularExpressionValidator; 0018 0019 // Assumption: Month has always 30 days 0020 /*! 0021 * Intended to be used for differences in datetimes 0022 */ 0023 class DateTimeSpinBox : public QAbstractSpinBox { 0024 Q_OBJECT 0025 private: 0026 enum Type { year, month, day, hour, minute, second, millisecond }; 0027 0028 public: 0029 explicit DateTimeSpinBox(QWidget* parent); 0030 ~DateTimeSpinBox() override; 0031 0032 void keyPressEvent(QKeyEvent*) override; 0033 void stepBy(int steps) override; 0034 QAbstractSpinBox::StepEnabled stepEnabled() const override; 0035 bool increaseValue(Type type, int step); 0036 bool changeValue(qint64& thisType, Type nextTypeType, int step); 0037 Type determineType(int cursorPos) const; 0038 void writeValue(); 0039 void setValue(qint64 increment); 0040 qint64 value(); 0041 void getValue(); 0042 void setCursorPosition(Type type); 0043 bool valid(); 0044 0045 private: 0046 QRegularExpressionValidator* m_regularExpressionValidator; 0047 DateTime::DateTime mDateTime; 0048 0049 Q_SIGNALS: 0050 void valueChanged(); 0051 }; 0052 0053 #endif // DATETIMESPINBOX_H