mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
Add validDateTime property to datefieldbackend
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
7e26bbd5f0
commit
1f8ecf416c
2 changed files with 22 additions and 3 deletions
|
@ -54,13 +54,13 @@ void DateFieldBackend::setDateTimeMsecs(const qint64 dateTimeMsecs)
|
|||
QString DateFieldBackend::dateTimeString() const
|
||||
{
|
||||
const auto locale = QLocale::system();
|
||||
return _dateTime.toString(locale.dateTimeFormat(QLocale::ShortFormat));
|
||||
return _dateTime.toString(locale.dateFormat(QLocale::ShortFormat));
|
||||
}
|
||||
|
||||
void DateFieldBackend::setDateTimeString(const QString &dateTimeString)
|
||||
{
|
||||
const auto locale = QLocale::system();
|
||||
const auto dt = locale.toDateTime(dateTimeString, locale.dateTimeFormat(QLocale::ShortFormat));
|
||||
const auto dt = locale.toDateTime(dateTimeString, locale.dateFormat(QLocale::ShortFormat));
|
||||
setDateTime(dt);
|
||||
}
|
||||
|
||||
|
@ -123,5 +123,20 @@ void DateFieldBackend::setMaximumDateTimeMsecs(const qint64 maximumDateTimeMsecs
|
|||
const auto dt = QDateTime::fromMSecsSinceEpoch(maximumDateTimeMsecs);
|
||||
setMaximumDateTime(dt);
|
||||
}
|
||||
|
||||
bool DateFieldBackend::validDateTime() const
|
||||
{
|
||||
auto valid = _dateTime.isValid();
|
||||
|
||||
if (_minimumDateTime.isValid()) {
|
||||
valid &= _dateTime >= _minimumDateTime;
|
||||
}
|
||||
|
||||
if (_maximumDateTime.isValid()) {
|
||||
valid &= _dateTime <= _maximumDateTime;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,8 @@ class DateFieldBackend : public QObject
|
|||
Q_PROPERTY(QDateTime maximumDateTime READ maximumDateTime WRITE setMaximumDateTime NOTIFY maximumDateTimeChanged)
|
||||
Q_PROPERTY(qint64 maximumDateTimeMsecs READ maximumDateTimeMsecs WRITE setMaximumDateTimeMsecs NOTIFY maximumDateTimeChanged)
|
||||
|
||||
Q_PROPERTY(bool validDateTime READ validDateTime NOTIFY dateTimeChanged NOTIFY minimumDateTimeChanged NOTIFY maximumDateTimeChanged)
|
||||
|
||||
public:
|
||||
explicit DateFieldBackend() = default;
|
||||
|
||||
|
@ -49,6 +51,8 @@ public:
|
|||
[[nodiscard]] QDateTime maximumDateTime() const;
|
||||
[[nodiscard]] qint64 maximumDateTimeMsecs() const;
|
||||
|
||||
[[nodiscard]] bool validDateTime() const;
|
||||
|
||||
public slots:
|
||||
void setDateTime(const QDateTime &dateTime);
|
||||
void setDateTimeMsecs(const qint64 dateTimeMsecs);
|
||||
|
@ -66,7 +70,7 @@ signals:
|
|||
void maximumDateTimeChanged();
|
||||
|
||||
private:
|
||||
QDateTime _dateTime;
|
||||
QDateTime _dateTime = QDateTime::currentDateTimeUtc();
|
||||
QDateTime _minimumDateTime;
|
||||
QDateTime _maximumDateTime;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue