From 209201b7047c605405a83e9c104f8c81f9195feb Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Mon, 21 Mar 2011 09:26:27 +0100 Subject: replaced weekendStart and weekendEnd with weekdays function Reviewed-by: Denis Dzyubenko Task-number: QTBUG-17088 --- src/corelib/tools/qlocale.cpp | 37 ++++++++++++++++--------------------- src/corelib/tools/qlocale.h | 6 ++---- src/corelib/tools/qlocale.qdoc | 3 +-- src/corelib/tools/qlocale_p.h | 1 + tests/auto/qlocale/tst_qlocale.cpp | 11 +++++++---- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 3f250ec..5ac0cf0 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -2097,35 +2097,30 @@ QLocale::MeasurementSystem QLocalePrivate::measurementSystem() const /*! \since 4.8 - Returns the first day of the weekend according to the current locale. + Returns a list of days that are considered weekdays according to the current locale. */ -Qt::DayOfWeek QLocale::weekendStart() const +QList QLocale::weekdays() const { #ifndef QT_NO_SYSTEMLOCALE if (d() == systemPrivate()) { - QVariant res = systemLocale()->query(QSystemLocale::WeekendStart, QVariant()); + QVariant res = systemLocale()->query(QSystemLocale::Weekdays, QVariant()); if (!res.isNull()) - return static_cast(res.toUInt()); + return static_cast >(res.value >()); } #endif - return static_cast(d()->m_weekend_start); -} - -/*! - \since 4.8 - - Returns the last day of the weekend according to the current locale. -*/ -Qt::DayOfWeek QLocale::weekendEnd() const -{ -#ifndef QT_NO_SYSTEMLOCALE - if (d() == systemPrivate()) { - QVariant res = systemLocale()->query(QSystemLocale::WeekendEnd, QVariant()); - if (!res.isNull()) - return static_cast(res.toUInt()); + QList weekdays; + quint16 weekendStart = d()->m_weekend_start; + quint16 weekendEnd = d()->m_weekend_end; + for(int day = Qt::Monday; day <= Qt::Sunday; day++) { + if(weekendEnd > weekendStart) { + if(day < weekendStart || day > weekendEnd) + weekdays << static_cast(day); + } else { + if(day > weekendEnd && day < weekendStart) + weekdays << static_cast(day); + } } -#endif - return static_cast(d()->m_weekend_end); + return weekdays; } /*! diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index 4736bfc..71eec47 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -106,8 +106,7 @@ public: AMText, // QString PMText, // QString FirstDayOfWeek, // Qt::DayOfWeek - WeekendStart, // Qt::DayOfWeek - WeekendEnd, // Qt::DayOfWeek + Weekdays, // QList CurrencySymbol, // QString in: CurrencyToStringArgument CurrencyToString, // QString in: qlonglong, qulonglong or double UILanguages, // QStringList @@ -712,8 +711,7 @@ public: QString standaloneDayName(int, FormatType format = LongFormat) const; Qt::DayOfWeek firstDayOfWeek() const; - Qt::DayOfWeek weekendStart() const; - Qt::DayOfWeek weekendEnd() const; + QList weekdays() const; QString amText() const; QString pmText() const; diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index 253edb3..ea5ec33 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -762,8 +762,7 @@ \value UILanguages a list of strings representing locale names that could be used for UI translation. \value StringToStandardQuotation a QString containing a quoted version of the string ref stored in the in variant using standard quotes. \value StringToAlternateQuotation a QString containing a quoted version of the string ref stored in the in variant using alternate quotes. - \value WeekendStart a Qt::DayOfWeek enum specifying the first day of the weekend - \value WeekendEnd a Qt::DayOfWeek enum specifying the last day of the weekend + \value Weekdays a QList specifying the regular weekdays */ /*! diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index ab7fde6..5326a77 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -275,5 +275,6 @@ int repeatCount(const QString &s, int i); QT_END_NAMESPACE Q_DECLARE_METATYPE(QStringRef) +Q_DECLARE_METATYPE(QList) #endif // QLOCALE_P_H diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index b6c66d5..6f4de91 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -1154,11 +1154,13 @@ void tst_QLocale::macDefaultLocale() QCOMPARE(locale.monthName(1), QString("January")); QCOMPARE(locale.monthName(12), QString("December")); QCOMPARE(locale.firstDayOfWeek(), Qt::Sunday); - QCOMPARE(locale.weekendStart(), Qt::Saturday); - QCOMPARE(locale.weekendEnd(), Qt::Sunday); QCOMPARE(locale.quoteString("string"), QString::fromUtf8("\xe2\x80\x9c" "string" "\xe2\x80\x9d")); QCOMPARE(locale.quoteString("string", QLocale::AlternateQuotation), QString::fromUtf8("\xe2\x80\x98" "string" "\xe2\x80\x99")); + QList days; + days << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday; + QCOMPARE(locale.weekdays(), days); + } #ifdef Q_OS_WIN @@ -2233,8 +2235,9 @@ void tst_QLocale::uiLanguages() void tst_QLocale::weekendDays() { const QLocale c(QLocale::C); - QCOMPARE(c.weekendStart(), Qt::Saturday); - QCOMPARE(c.weekendEnd(), Qt::Sunday); + QList days; + days << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday; + QCOMPARE(c.weekdays(), days); } void tst_QLocale::listPatterns() -- cgit v0.12