Add strig based representation and setting for date in datefieldbackend

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-08-07 23:00:13 +08:00 committed by Matthieu Gallien
parent eb66f51a92
commit d4f8b4f3bc
2 changed files with 18 additions and 0 deletions

View file

@ -14,6 +14,8 @@
#include "datefieldbackend.h"
#include <QLocale>
namespace OCC
{
namespace Quick
@ -49,5 +51,18 @@ void DateFieldBackend::setDateTimeMsecs(const qint64 dateTimeMsecs)
setDateTime(dt);
}
QString DateFieldBackend::dateTimeString() const
{
const auto locale = QLocale::system();
return m_dateTime.toString(locale.dateTimeFormat(QLocale::ShortFormat));
}
void DateFieldBackend::setDateTimeString(const QString &dateTimeString)
{
const auto locale = QLocale::system();
const auto dt = locale.toDateTime(dateTimeString, locale.dateTimeFormat(QLocale::ShortFormat));
setDateTime(dt);
}
}
}

View file

@ -28,16 +28,19 @@ class DateFieldBackend : public QObject
Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged)
Q_PROPERTY(qint64 dateTimeMsecs READ dateTimeMsecs WRITE setDateTimeMsecs NOTIFY dateTimeChanged)
Q_PROPERTY(QString dateTimeString READ dateTimeString WRITE setDateTimeString NOTIFY dateTimeChanged)
public:
explicit DateFieldBackend() = default;
[[nodiscard]] QDateTime dateTime() const;
[[nodiscard]] qint64 dateTimeMsecs() const;
[[nodiscard]] QString dateTimeString() const;
public slots:
void setDateTime(const QDateTime &dateTime);
void setDateTimeMsecs(const qint64 dateTimeMsecs);
void setDateTimeString(const QString &dateTimeString);
signals:
void dateTimeChanged();