summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@nokia.com>2011-02-15 12:50:20 (GMT)
committerZeno Albisser <zeno.albisser@nokia.com>2011-02-15 15:58:03 (GMT)
commit049cc0e6717f684453d40f78e9ec0e9093df2c1d (patch)
tree57c6acce26322e35c36f3e306f8a2581c4d34be0 /src
parent6f313a63d4155b53659917a3f7a71f4de60d0d91 (diff)
downloadQt-049cc0e6717f684453d40f78e9ec0e9093df2c1d.zip
Qt-049cc0e6717f684453d40f78e9ec0e9093df2c1d.tar.gz
Qt-049cc0e6717f684453d40f78e9ec0e9093df2c1d.tar.bz2
Implemented QLocale::firstDayOfWeek()
REMARK: This commit is missing updated static cldr data in src/corelib/tools/qlocale_data_p.h that has been left out intentionally to avoid repository bloating. Before compiling make sure to update that file using the scripts util/local_database/cldr2qlocalexml.py and util/local_database/qlocalexml2cpp.py. Otherwise you will most likely experience segmentation faults. Reviewed-By: Denis Dzyubenko
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale.cpp41
-rw-r--r--src/corelib/tools/qlocale.h5
-rw-r--r--src/corelib/tools/qlocale_p.h1
3 files changed, 46 insertions, 1 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index fcfa8f0..3f19c27 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -647,6 +647,17 @@ static QString winSystemPMText()
return QString();
}
+static quint8 winSystemFirstDayOfWeek()
+{
+ LCID id = GetUserDefaultLCID();
+ wchar_t output[4]; // maximum length including terminating zero character for Win2003+
+
+ if (GetLocaleInfo(id, LOCALE_IFIRSTDAYOFWEEK, output, 4))
+ return QString::fromWCharArray(output).toUInt()+1;
+
+ return 1;
+}
+
/*!
\since 4.6
Returns the fallback locale obtained from the system.
@@ -736,6 +747,8 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const
return QVariant(winSystemAMText());
case PMText:
return QVariant(winSystemPMText());
+ case FirstDayOfWeek:
+ return QVariant(winSystemFirstDayOfWeek());
default:
break;
}
@@ -1162,6 +1175,15 @@ static QLocale::MeasurementSystem macMeasurementSystem()
}
}
+static quint8 macFirstDayOfWeek()
+{
+ QCFType<CFCalendarRef> calendar = CFCalendarCopyCurrent();
+ quint8 day = static_cast<quint8>(CFCalendarGetFirstWeekday(calendar))-1;
+ if (day == 0)
+ day = 7;
+ return day;
+}
+
static void getMacPreferredLanguageAndCountry(QString *language, QString *country)
{
QCFType<CFArrayRef> languages = (CFArrayRef)CFPreferencesCopyValue(
@@ -1243,6 +1265,8 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const
case AMText:
case PMText:
break;
+ case FirstDayOfWeek:
+ return QVariant(macFirstDayOfWeek());
default:
break;
}
@@ -3449,6 +3473,23 @@ QString QLocale::standaloneDayName(int day, FormatType type) const
}
/*!
+ \since 4.8
+
+ Returns the first day of the week according to the current locale.
+*/
+Qt::DayOfWeek QLocale::firstDayOfWeek() const
+{
+#ifndef QT_NO_SYSTEMLOCALE
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(QSystemLocale::FirstDayOfWeek, QVariant());
+ if (!res.isNull())
+ return static_cast<Qt::DayOfWeek>(res.toUInt());
+ }
+#endif
+ return static_cast<Qt::DayOfWeek>(d()->m_first_day_of_week);
+}
+
+/*!
\since 4.4
Returns the measurement system for the locale.
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index 6bb9f79..be58faf 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -94,7 +94,8 @@ public:
MeasurementSystem, // uint
PositiveSign, // QString
AMText, // QString
- PMText // QString
+ PMText, // QString
+ FirstDayOfWeek // Qt::DayOfWeek
};
virtual QVariant query(QueryType type, QVariant in) const;
virtual QLocale fallbackLocale() const;
@@ -661,6 +662,8 @@ public:
QString dayName(int, FormatType format = LongFormat) const;
QString standaloneDayName(int, FormatType format = LongFormat) const;
+ Qt::DayOfWeek firstDayOfWeek() const;
+
QString amText() const;
QString pmText() const;
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index d310d9b..b2c86d8 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -167,6 +167,7 @@ public:
quint16 m_narrow_day_names_idx, m_narrow_day_names_size;
quint16 m_am_idx, m_am_size;
quint16 m_pm_idx, m_pm_size;
+ quint8 m_first_day_of_week : 3;
};
inline char QLocalePrivate::digitToCLocale(const QChar &in) const