From d4f8b4f3bcd90a657db47571b2fb13b5fccf442b Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 7 Aug 2023 23:00:13 +0800 Subject: [PATCH] Add strig based representation and setting for date in datefieldbackend Signed-off-by: Claudio Cambra --- src/gui/filedetails/datefieldbackend.cpp | 15 +++++++++++++++ src/gui/filedetails/datefieldbackend.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/gui/filedetails/datefieldbackend.cpp b/src/gui/filedetails/datefieldbackend.cpp index e2dc679f1..5fadabe0c 100644 --- a/src/gui/filedetails/datefieldbackend.cpp +++ b/src/gui/filedetails/datefieldbackend.cpp @@ -14,6 +14,8 @@ #include "datefieldbackend.h" +#include + 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); +} + } } \ No newline at end of file diff --git a/src/gui/filedetails/datefieldbackend.h b/src/gui/filedetails/datefieldbackend.h index 92e5508c8..b20e17dca 100644 --- a/src/gui/filedetails/datefieldbackend.h +++ b/src/gui/filedetails/datefieldbackend.h @@ -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();