diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-01-28 19:45:35 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-01-31 19:20:43 +0100 |
commit | 6c4e0f2d2de5f877f698a0faa7bd0d027b7320c9 (patch) | |
tree | 6d7079cbef92387eae4652ede2c930e210c36293 /src | |
parent | d6ba2ae441b56d13edf9acf1220b50eda5e093cd (diff) |
Deprecate QLocale::toTime() variants taking a calendar
The calendar is ignored, so adding these methods was a mistake.
[ChangeLog][QtCore][QLocale] Deprecated toTime() variants taking a
calendar. The calendar is ignored in time parsing.
Change-Id: I79fa994ce88f13fdb931163b447eb1a9ad655c09
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 20 | ||||
-rw-r--r-- | src/corelib/text/qlocale.h | 8 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 022c770ac3..5fc9d9922c 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2353,14 +2353,19 @@ QTime QLocale::toTime(const QString &string, FormatType format) const return toTime(string, timeFormat(format)); } +#if QT_DEPRECATED_SINCE(5, 15) /*! \since 5.14 \overload + \deprecated */ QTime QLocale::toTime(const QString &string, FormatType format, QCalendar cal) const { +QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED return toTime(string, timeFormat(format), cal); +QT_WARNING_POP } +#endif /*! \since 4.4 @@ -2425,12 +2430,24 @@ QDateTime QLocale::toDateTime(const QString &string, FormatType format, QCalenda */ QTime QLocale::toTime(const QString &string, const QString &format) const { - return toTime(string, format, QCalendar()); + QTime time; +#if QT_CONFIG(datetimeparser) + QDateTimeParser dt(QMetaType::QTime, QDateTimeParser::FromString, QCalendar()); + dt.setDefaultLocale(*this); + if (dt.parseFormat(format)) + dt.fromString(string, nullptr, &time); +#else + Q_UNUSED(string); + Q_UNUSED(format); +#endif + return time; } +#if QT_DEPRECATED_SINCE(5, 15) /*! \since 5.14 \overload + \deprecated */ QTime QLocale::toTime(const QString &string, const QString &format, QCalendar cal) const { @@ -2447,6 +2464,7 @@ QTime QLocale::toTime(const QString &string, const QString &format, QCalendar ca #endif return time; } +#endif /*! \since 4.4 diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index 513e0f097b..0dc9e1bd00 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -1037,11 +1037,15 @@ public: QDateTime toDateTime(const QString &string, const QString &format) const; // Calendar-aware API QDate toDate(const QString &string, FormatType format, QCalendar cal) const; - QTime toTime(const QString &string, FormatType format, QCalendar cal) const; QDateTime toDateTime(const QString &string, FormatType format, QCalendar cal) const; QDate toDate(const QString &string, const QString &format, QCalendar cal) const; - QTime toTime(const QString &string, const QString &format, QCalendar cal) const; QDateTime toDateTime(const QString &string, const QString &format, QCalendar cal) const; +# if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_X("Calendar is ignored when parsing times") + QTime toTime(const QString &string, FormatType format, QCalendar cal) const; + QT_DEPRECATED_X("Calendar is ignored when parsing times") + QTime toTime(const QString &string, const QString &format, QCalendar cal) const; +# endif // 5.15 #endif // ### Qt 6: We need to return QString from these function since |