Clean up docs of QCalendar-related QLocale::toString() variants

Some of the new functions were added without documentation, or without
updating the docs to mention the optional calendars. Shuffle the
methods so that the one with calendar is what the primary
documentation comment describes and the one without is documented as
an overload.

Pick-to: 5.15
Change-Id: Iee4cdb1d3b0ed21a50e205a5275a0695a2667550
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2020-11-09 16:49:06 +01:00
parent c082213556
commit f884689d04
2 changed files with 64 additions and 46 deletions

View File

@ -1840,27 +1840,62 @@ QString QLocale::toString(QTime time, const QString &format) const
#endif
/*!
\since 5.10
\since 5.14
Returns a localized string representation of the given \a date in the
specified \a format.
specified \a format, optionally for a specified calendar \a cal.
If \a format is an empty string, an empty string is returned.
\sa QDate::toString()
*/
QString QLocale::toString(QDate date, QStringView format, QCalendar cal) const
{
return cal.dateTimeToString(format, QDateTime(), date, QTime(), *this);
}
/*!
\since 5.10
\overload
*/
QString QLocale::toString(QDate date, QStringView format) const
{
return QCalendar().dateTimeToString(format, QDateTime(), date, QTime(), *this);
}
/*!
\since 5.14
Returns a localized string representation of the given \a date according
to the specified \a format (see dateFormat()).
to the specified \a format (see dateFormat()), optionally for a specified
calendar \a cal.
\note Some locales may use formats that limit the range of years they can
represent.
*/
QString QLocale::toString(QDate date, FormatType format, QCalendar cal) const
{
if (!date.isValid())
return QString();
#ifndef QT_NO_SYSTEMLOCALE
if (cal.isGregorian() && d->m_data == &globalLocaleData) {
QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::DateToStringLong
: QSystemLocale::DateToStringShort,
date);
if (!res.isNull())
return res.toString();
}
#endif
QString format_str = dateFormat(format);
return toString(date, format_str, cal);
}
/*!
\since 4.5
\overload
*/
QString QLocale::toString(QDate date, FormatType format) const
{
if (!date.isValid())
@ -1899,7 +1934,7 @@ static bool timeFormatContainsAP(QStringView format)
}
/*!
\since 5.10
\since 4.5
Returns a localized string representation of the given \a time according
to the specified \a format.
@ -1913,46 +1948,39 @@ QString QLocale::toString(QTime time, QStringView format) const
}
/*!
\since 5.10
\since 5.14
Returns a localized string representation of the given \a dateTime according
to the specified \a format.
to the specified \a format, optionally for a specified calendar \a cal.
If \a format is an empty string, an empty string is returned.
\sa QDateTime::toString(), QDate::toString(), QTime::toString()
*/
QString QLocale::toString(const QDateTime &dateTime, QStringView format, QCalendar cal) const
{
return cal.dateTimeToString(format, dateTime, QDate(), QTime(), *this);
}
/*!
\since 5.10
\overload
*/
QString QLocale::toString(const QDateTime &dateTime, QStringView format) const
{
return QCalendar().dateTimeToString(format, dateTime, QDate(), QTime(), *this);
}
QString QLocale::toString(QDate date, QStringView format, QCalendar cal) const
{
return cal.dateTimeToString(format, QDateTime(), date, QTime(), *this);
}
/*!
\since 5.14
QString QLocale::toString(QDate date, QLocale::FormatType format, QCalendar cal) const
{
if (!date.isValid())
return QString();
Returns a localized string representation of the given \a dateTime according
to the specified \a format (see dateTimeFormat()), optionally for a
specified calendar \a cal.
#ifndef QT_NO_SYSTEMLOCALE
if (cal.isGregorian() && d->m_data == &globalLocaleData) {
QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::DateToStringLong
: QSystemLocale::DateToStringShort,
date);
if (!res.isNull())
return res.toString();
}
#endif
QString format_str = dateFormat(format);
return toString(date, format_str, cal);
}
QString QLocale::toString(const QDateTime &dateTime, QLocale::FormatType format,
QCalendar cal) const
\note Some locales may use formats that limit the range of years they can
represent.
*/
QString QLocale::toString(const QDateTime &dateTime, FormatType format, QCalendar cal) const
{
if (!dateTime.isValid())
return QString();
@ -1972,21 +2000,10 @@ QString QLocale::toString(const QDateTime &dateTime, QLocale::FormatType format,
return toString(dateTime, format_str, cal);
}
QString QLocale::toString(const QDateTime &dateTime, QStringView format, QCalendar cal) const
{
return cal.dateTimeToString(format, dateTime, QDate(), QTime(), *this);
}
/*!
\since 4.4
Returns a localized string representation of the given \a dateTime according
to the specified \a format (see dateTimeFormat()).
\note Some locales may use formats that limit the range of years they can
represent.
\overload
*/
QString QLocale::toString(const QDateTime &dateTime, FormatType format) const
{
if (!dateTime.isValid())

View File

@ -995,9 +995,10 @@ public:
QString toString(QDate date, FormatType format = LongFormat) const;
QString toString(QTime time, FormatType format = LongFormat) const;
QString toString(const QDateTime &dateTime, FormatType format = LongFormat) const;
/* Removing default value for `format' is done intentionally,
* after all tests we will remove non-calendar-aware version of these functions,
* and add a default value for both calendar instance, and format
/* We can't pass a default for QCalendar (its declaration mentions
* QLocale::FormatType, so it has to #include this header, which thus can't
* #include its, so we can't instantiate QCalendar() as default). This
* precludes any default for format, too.
*/
QString toString(QDate date, QStringView format, QCalendar cal) const;
QString toString(QDate date, FormatType format, QCalendar cal) const;