Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlocale_mac.mm
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qlocale_p.h"
5
6#include "qstringlist.h"
7#include "qvariant.h"
8#include "qdatetime.h"
9
10#include "private/qstringiterator_p.h"
11#include "private/qgregoriancalendar_p.h"
12#ifdef Q_OS_DARWIN
13#include "private/qcore_mac_p.h"
14#include <CoreFoundation/CoreFoundation.h>
15#endif
16
17#include <QtCore/qloggingcategory.h>
18#include <QtCore/qcoreapplication.h>
19
21
22using namespace Qt::StringLiterals;
23
24/******************************************************************************
25** Wrappers for Mac locale system functions
26*/
27
28Q_LOGGING_CATEGORY(lcLocale, "qt.core.locale")
29
31{
32 if (!lcLocale().isDebugEnabled())
33 return;
34
35#if defined(Q_OS_MACOS)
36 // Trigger initialization of standard user defaults, so that Foundation picks
37 // up -AppleLanguages and -AppleLocale passed on the command line.
38 Q_UNUSED(NSUserDefaults.standardUserDefaults);
39#endif
40
41 auto singleLineDescription = [](NSArray *array) {
42 NSString *str = [array description];
43 str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
44 return [str stringByReplacingOccurrencesOfString:@" " withString:@""];
45 };
46
47 bool allowMixedLocalizations = [NSBundle.mainBundle.infoDictionary[@"CFBundleAllowMixedLocalizations"] boolValue];
48
49 NSBundle *foundation = [NSBundle bundleForClass:NSBundle.class];
50 qCDebug(lcLocale).nospace() << "Launched with locale \"" << NSLocale.currentLocale.localeIdentifier
51 << "\" based on user's preferred languages " << singleLineDescription(NSLocale.preferredLanguages)
52 << ", main bundle localizations " << singleLineDescription(NSBundle.mainBundle.localizations)
53 << ", and allowing mixed localizations " << allowMixedLocalizations
54 << "; resulting in main bundle preferred localizations "
55 << singleLineDescription(NSBundle.mainBundle.preferredLocalizations)
56 << " and Foundation preferred localizations "
57 << singleLineDescription(foundation.preferredLocalizations);
58 qCDebug(lcLocale) << "Reflected by Qt as system locale"
59 << QLocale::system() << "with UI languges " << QLocale::system().uiLanguages();
60}
62
64{
65 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
66 CFStringRef locale = CFLocaleGetIdentifier(l);
67 return QString::fromCFString(locale);
68}
69
71{
72 month -= 1;
73 if (month < 0 || month > 11)
74 return {};
75
76 QCFType<CFDateFormatterRef> formatter
77 = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
78 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
79
80 CFDateFormatterKey formatterType;
81 switch (type) {
83 formatterType = kCFDateFormatterMonthSymbols;
84 break;
86 formatterType = kCFDateFormatterShortMonthSymbols;
87 break;
89 formatterType = kCFDateFormatterVeryShortMonthSymbols;
90 break;
92 formatterType = kCFDateFormatterStandaloneMonthSymbols;
93 break;
95 formatterType = kCFDateFormatterShortStandaloneMonthSymbols;
96 break;
98 formatterType = kCFDateFormatterVeryShortStandaloneMonthSymbols;
99 break;
100 default:
101 qWarning("macMonthName: Unsupported query type %d", type);
102 return {};
103 }
104 QCFType<CFArrayRef> values
105 = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, formatterType));
106
107 if (values != 0) {
108 CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month));
109 return QString::fromCFString(cfstring);
110 }
111 return {};
112}
113
115{
116 if (day < 1 || day > 7)
117 return {};
118
119 QCFType<CFDateFormatterRef> formatter
120 = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
121 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
122
123 CFDateFormatterKey formatterType;
124 switch (type) {
126 formatterType = kCFDateFormatterWeekdaySymbols;
127 break;
129 formatterType = kCFDateFormatterShortWeekdaySymbols;
130 break;
132 formatterType = kCFDateFormatterVeryShortWeekdaySymbols;
133 break;
135 formatterType = kCFDateFormatterStandaloneWeekdaySymbols;
136 break;
138 formatterType = kCFDateFormatterShortStandaloneWeekdaySymbols;
139 break;
141 formatterType = kCFDateFormatterVeryShortStandaloneWeekdaySymbols;
142 break;
143 default:
144 qWarning("macDayName: Unsupported query type %d", type);
145 return {};
146 }
147 QCFType<CFArrayRef> values =
148 static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, formatterType));
149
150 if (values != 0) {
151 CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7));
152 return QString::fromCFString(cfstring);
153 }
154 return {};
155}
156
158{
159 static QString cachedZeroDigit;
160
161 if (cachedZeroDigit.isNull()) {
162 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
163 QCFType<CFNumberFormatterRef> numberFormatter =
164 CFNumberFormatterCreate(nullptr, locale, kCFNumberFormatterNoStyle);
165 const int zeroDigit = 0;
166 QCFType<CFStringRef> value
167 = CFNumberFormatterCreateStringWithValue(nullptr, numberFormatter,
168 kCFNumberIntType, &zeroDigit);
169 cachedZeroDigit = QString::fromCFString(value);
170 }
171
172 static QMacNotificationObserver localeChangeObserver = QMacNotificationObserver(
173 nil, NSCurrentLocaleDidChangeNotification, [&] {
174 qCDebug(lcLocale) << "System locale changed";
175 cachedZeroDigit = QString();
176 });
177
178 return cachedZeroDigit;
179}
180
181static QString zeroPad(QString &&number, qsizetype minDigits, const QString &zero)
182{
183 // Need to pad with zeros, possibly after a sign.
184 qsizetype insert = -1, digits = 0;
185 auto it = QStringIterator(number);
186 while (it.hasNext()) {
187 qsizetype here = it.index();
188 if (QChar::isDigit(it.next())) {
189 if (insert < 0)
190 insert = here;
191 ++digits;
192 } // else: assume we're stepping over a sign (or maybe grouping separator)
193 }
194 Q_ASSERT(digits > 0);
195 Q_ASSERT(insert >= 0);
196 while (digits++ < minDigits)
197 number.insert(insert, zero);
198
199 return std::move(number);
200}
201
203{
204 // Retain any sign, but remove all but the last two digits.
205 // We know number has at least four digits - it came from fourDigitYear().
206 // Note that each digit might be a surrogate pair.
207 qsizetype first = -1, prev = -1, last = -1;
208 auto it = QStringIterator(number);
209 while (it.hasNext()) {
210 qsizetype here = it.index();
211 if (QChar::isDigit(it.next())) {
212 if (first == -1)
213 last = first = here;
214 else if (last != -1)
215 prev = std::exchange(last, here);
216 }
217 }
218 Q_ASSERT(first >= 0);
219 Q_ASSERT(prev > first);
220 Q_ASSERT(last > prev);
221 number.remove(first, prev - first);
222 return std::move(number);
223}
224
225static QString fourDigitYear(int year, const QString &zero)
226{
227 // Return year formatted as an (at least) four digit number:
228 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
229 QCFType<CFNumberFormatterRef> numberFormatter =
230 CFNumberFormatterCreate(nullptr, locale, kCFNumberFormatterNoStyle);
231 QCFType<CFStringRef> value = CFNumberFormatterCreateStringWithValue(nullptr, numberFormatter,
232 kCFNumberIntType, &year);
233 auto text = QString::fromCFString(value);
234 if (year > -1000 && year < 1000)
235 text = zeroPad(std::move(text), 4, zero);
236 return text;
237}
238
239static QString macDateToStringImpl(QDate date, CFDateFormatterStyle style)
240{
241 // Use noon on the given date, to avoid complications that can arise for
242 // dates before 1900 (see QTBUG-54955) using different UTC offset than
243 // QDateTime extrapolates backwards from time_t functions that only work
244 // back to 1900. (Alaska and Phillipines may still be borked, though.)
245 QCFType<CFDateRef> myDate = QDateTime(date, QTime(12, 0)).toCFDate();
246 QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent();
247 QCFType<CFDateFormatterRef> myFormatter
248 = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, style,
249 kCFDateFormatterNoStyle);
250 QCFType<CFStringRef> text = CFDateFormatterCreateStringWithDate(nullptr, myFormatter, myDate);
251 return QString::fromCFString(text);
252}
253
254static QVariant macDateToString(QDate date, bool short_format)
255{
256 const int year = date.year();
257 QString fakeYear, trueYear;
258 if (year < 1583) {
259 // System API (in macOS 11.0, at least) discards sign :-(
260 // Simply negating the year won't do as the resulting year typically has
261 // a different pattern of week-days.
262 // Furthermore (see QTBUG-54955), Darwin uses the Julian calendar for
263 // dates before 1582-10-15, leading to discrepancies.
265 Q_ASSERT(matcher >= 1583);
266 Q_ASSERT(matcher % 100 != date.month());
267 Q_ASSERT(matcher % 100 != date.day());
268 // i.e. there can't be any confusion between the two-digit year and
269 // month or day-of-month in the formatted date.
271 fakeYear = fourDigitYear(matcher, zero);
272 trueYear = fourDigitYear(year, zero);
274 }
275 QString text = macDateToStringImpl(date, short_format
276 ? kCFDateFormatterShortStyle
277 : kCFDateFormatterLongStyle);
278 if (year < 1583) {
279 if (text.contains(fakeYear))
280 return std::move(text).replace(fakeYear, trueYear);
281 // Cope with two-digit year:
282 fakeYear = trimTwoDigits(std::move(fakeYear));
283 trueYear = trimTwoDigits(std::move(trueYear));
284 if (text.contains(fakeYear))
285 return std::move(text).replace(fakeYear, trueYear);
286 // That should have worked.
287 qWarning("Failed to fix up year when formatting a date in year %d", year);
288 }
289 return text;
290}
291
292static QVariant macTimeToString(QTime time, bool short_format)
293{
294 QCFType<CFDateRef> myDate = QDateTime(QDate::currentDate(), time).toCFDate();
295 QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent();
296 CFDateFormatterStyle style = short_format ? kCFDateFormatterShortStyle : kCFDateFormatterLongStyle;
297 QCFType<CFDateFormatterRef> myFormatter = CFDateFormatterCreate(kCFAllocatorDefault,
298 mylocale,
299 kCFDateFormatterNoStyle,
300 style);
301 QCFType<CFStringRef> text = CFDateFormatterCreateStringWithDate(0, myFormatter, myDate);
302 return QString::fromCFString(text);
303}
304
305// Mac uses the Unicode CLDR format codes
306// http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
307// See also qtbase/util/locale_database/dateconverter.py
308// Makes the assumption that input formats are always well formed and consecutive letters
309// never exceed the maximum for the format code.
311{
313 qsizetype i = 0;
314
315 while (i < sys_fmt.size()) {
316 if (sys_fmt.at(i).unicode() == '\'') {
318 if (text == "'"_L1)
319 result += "''"_L1;
320 else
321 result += u'\'' + text + u'\'';
322 continue;
323 }
324
325 QChar c = sys_fmt.at(i);
326 qsizetype repeat = qt_repeatCount(sys_fmt.sliced(i));
327
328 switch (c.unicode()) {
329 // Qt does not support the following options
330 case 'A': // Milliseconds in Day (1..n): 1..n = padded number
331 case 'C': // Input skeleton symbol.
332 case 'D': // Day of Year (1..3): 1..3 = padded number
333 case 'F': // Day of Week in Month (1): 1 = number
334 case 'g': // Modified Julian Day (1..n): 1..n = padded number
335 case 'G': // Era (1..5): 4 = long, 1..3 = short, 5 = narrow
336 case 'j': // Input skeleton symbol.
337 case 'J': // Input skeleton symbol.
338 case 'l': // Deprecated Chinese leap month indicator.
339 case 'q': // Standalone Quarter (1..4): 4 = long, 3 = short, 1,2 = padded number
340 case 'Q': // Quarter (1..4): 4 = long, 3 = short, 1,2 = padded number
341 case 'U': // Cyclic Year Name (1..5): 4 = long, 1..3 = short, 5 = narrow
342 case 'w': // Week of Year (1,2): 1,2 = padded number
343 case 'W': // Week of Month (1): 1 = number
344 case 'Y': // Year for Week-of-year calendars (1..n): 1..n = padded number
345 break;
346
347 case 'u': // Extended Year (1..n), padded number.
348 // Explicitly has no special case for 'uu' as only the last two digits.
349 result += "yyyy"_L1;
350 break;
351 case 'y': // Year (1..n): 2 = short year, 1 & 3..n = padded number
352 // Qt only supports long (4) or short (2) year, use long for all others
353 if (repeat == 2)
354 result += "yy"_L1;
355 else
356 result += "yyyy"_L1;
357 break;
358 case 'L': // Standalone Month (1..5): 4 = long, 3 = short, 1,2 = number, 5 = narrow
359 case 'M': // Month (1..5): 4 = long, 3 = short, 1,2 = number, 5 = narrow
360 // Qt only supports long, short and number, use short for narrow
361 if (repeat == 5)
362 result += "MMM"_L1;
363 else
364 result += QString(repeat, u'M');
365 break;
366 case 'd': // Day of Month (1,2): 1,2 padded number
367 result += QString(repeat, c);
368 break;
369 case 'c': // Standalone version of 'e'
370 case 'e': // Local Day of Week (1..6): 4 = long, 3 = short, 5,6 = narrow, 1,2 padded number
371 // "Local" only affects numeric form: depends on locale's start-day of the week.
372 case 'E': // Day of Week (1..6): 4 = long, 1..3 = short, 5,6 = narrow
373 // Qt only supports long, short: use short for narrow and padded number.
374 if (repeat == 4)
375 result += "dddd"_L1;
376 else
377 result += "ddd"_L1;
378 break;
379 case 'a': // AM/PM (1..n): Qt supports no distinctions
380 case 'b': // Like a, but also distinguishing noon, midnight (ignore difference).
381 case 'B': // Flexible day period (at night, &c.)
382 // Translate to Qt AM/PM, using locale-appropriate case:
383 result += "Ap"_L1;
384 break;
385 case 'h': // Hour [1..12] (1,2): 1,2 = padded number
386 case 'K': // Hour [0..11] (1,2): 1,2 = padded number
387 result += QString(repeat, 'h'_L1);
388 break;
389 case 'H': // Hour [0..23] (1,2): 1,2 = padded number
390 case 'k': // Hour [1..24] (1,2): 1,2 = padded number
391 // Qt H is 0..23 hour
392 result += QString(repeat, 'H'_L1);
393 break;
394 case 'm': // Minutes (1,2): 1,2 = padded number
395 case 's': // Seconds (1,2): 1,2 = padded number
396 result += QString(repeat, c);
397 break;
398 case 'S': // Fractional second (1..n): 1..n = truncates to decimal places
399 // Qt uses msecs either unpadded or padded to 3 places
400 if (repeat < 3)
401 result += u'z';
402 else
403 result += "zzz"_L1;
404 break;
405 case 'O': // Time Zone (1, 4)
406 result += u't';
407 break;
408 case 'v': // Time Zone (1, 4)
409 case 'V': // Time Zone (1..4)
410 result += "tttt"_L1;
411 break;
412 case 'x': // Time Zone (1..5)
413 case 'X': // Time Zone (1..5)
414 result += (repeat > 1 && (repeat & 1)) ? "ttt"_L1 : "tt"_L1;
415 break;
416 case 'z': // Time Zone (1..4)
417 case 'Z': // Time Zone (1..5)
418 result += repeat < 4 ? "tt"_L1 : repeat > 4 ? "ttt"_L1 : "t"_L1;
419 break;
420 default:
421 // a..z and A..Z are reserved for format codes, so any occurrence of these not
422 // already processed are not known and so unsupported formats to be ignored.
423 // All other chars are allowed as literals.
424 if (c < u'A' || c > u'z' || (c > u'Z' && c < u'a'))
425 result += QString(repeat, c);
426 break;
427 }
428
429 i += repeat;
430 }
431
432 return !result.isEmpty() ? QVariant::fromValue(result) : QVariant();
433}
434
435static QVariant getMacDateFormat(CFDateFormatterStyle style)
436{
437 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
438 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault,
439 l, style, kCFDateFormatterNoStyle);
440 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
441}
442
443static QVariant getMacTimeFormat(CFDateFormatterStyle style)
444{
445 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
446 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault,
447 l, kCFDateFormatterNoStyle, style);
448 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
449}
450
451static QVariant getCFLocaleValue(CFStringRef key)
452{
453 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
454 CFTypeRef value = CFLocaleGetValue(locale, key);
455 if (!value)
456 return QVariant();
457 return QString::fromCFString(CFStringRef(static_cast<CFTypeRef>(value)));
458}
459
461{
462 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
463 CFStringRef system = static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleMeasurementSystem));
464 if (QString::fromCFString(system) == "Metric"_L1) {
466 } else {
468 }
469}
470
471
473{
474 QCFType<CFCalendarRef> calendar = CFCalendarCopyCurrent();
475 quint8 day = static_cast<quint8>(CFCalendarGetFirstWeekday(calendar))-1;
476 if (day == 0)
477 day = 7;
478 return day;
479}
480
482{
483 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
484 switch (format) {
486 return QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode)));
488 return QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleCurrencySymbol)));
490 CFStringRef code = static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode));
491 QCFType<CFStringRef> value = CFLocaleCopyDisplayNameForPropertyValue(locale, kCFLocaleCurrencyCode, code);
492 return QString::fromCFString(value);
493 }
494 default:
495 break;
496 }
497 return {};
498}
499
500#ifndef QT_NO_SYSTEMLOCALE
502{
503 QCFType<CFNumberRef> value;
504 switch (arg.value.metaType().id()) {
505 case QMetaType::Int:
506 case QMetaType::UInt: {
507 int v = arg.value.toInt();
508 value = CFNumberCreate(NULL, kCFNumberIntType, &v);
509 break;
510 }
511 case QMetaType::Double: {
512 double v = arg.value.toDouble();
513 value = CFNumberCreate(NULL, kCFNumberDoubleType, &v);
514 break;
515 }
516 case QMetaType::LongLong:
517 case QMetaType::ULongLong: {
518 qint64 v = arg.value.toLongLong();
519 value = CFNumberCreate(NULL, kCFNumberLongLongType, &v);
520 break;
521 }
522 default:
523 return {};
524 }
525
526 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
527 QCFType<CFNumberFormatterRef> currencyFormatter =
528 CFNumberFormatterCreate(NULL, locale, kCFNumberFormatterCurrencyStyle);
529 if (!arg.symbol.isEmpty()) {
530 CFNumberFormatterSetProperty(currencyFormatter, kCFNumberFormatterCurrencySymbol,
531 arg.symbol.toCFString());
532 }
533 QCFType<CFStringRef> result = CFNumberFormatterCreateStringWithNumber(NULL, currencyFormatter, value);
534 return QString::fromCFString(result);
535}
536
538{
540 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
541 switch (type) {
543 begin = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey)));
544 end = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey)));
545 return QString(begin % str % end);
547 begin = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey)));
548 end = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey)));
549 return QString(begin % str % end);
550 default:
551 break;
552 }
553 return QVariant();
554}
555#endif //QT_NO_SYSTEMLOCALE
556
557#ifndef QT_NO_SYSTEMLOCALE
558
563
564template <auto CodeToValueFunction>
565static QVariant getLocaleValue(CFStringRef key)
566{
567 if (auto code = getCFLocaleValue(key); !code.isNull()) {
568 // If an invalid locale is requested with -AppleLocale, the system APIs
569 // will report invalid or empty locale values back to us, which codeToLanguage()
570 // and friends will fail to parse, resulting in returning QLocale::Any{L/C/S}.
571 // If this is the case, we fall down and return a null-variant, which
572 // QLocale's updateSystemPrivate() will interpret to use fallback logic.
573 if (auto value = CodeToValueFunction(code.toString()))
574 return value;
575 }
576 return QVariant();
577}
578
583
585{
587
588 switch(type) {
589 case LanguageId:
590 return getLocaleValue<codeToLanguage>(kCFLocaleLanguageCode);
591 case TerritoryId:
592 return getLocaleValue<QLocalePrivate::codeToTerritory>(kCFLocaleCountryCode);
593 case ScriptId:
594 return getLocaleValue<QLocalePrivate::codeToScript>(kCFLocaleScriptCode);
595 case DecimalPoint:
596 return getCFLocaleValue(kCFLocaleDecimalSeparator);
597 case GroupSeparator:
598 return getCFLocaleValue(kCFLocaleGroupingSeparator);
599 case DateFormatLong:
600 case DateFormatShort:
602 ? kCFDateFormatterShortStyle
603 : kCFDateFormatterLongStyle);
604 case TimeFormatLong:
605 case TimeFormatShort:
607 ? kCFDateFormatterShortStyle
608 : kCFDateFormatterLongStyle);
609 case DayNameLong:
610 case DayNameShort:
611 case DayNameNarrow:
615 return macDayName(in.toInt(), type);
616 case MonthNameLong:
617 case MonthNameShort:
618 case MonthNameNarrow:
622 return macMonthName(in.toInt(), type);
624 case DateToStringLong:
625 return macDateToString(in.toDate(), (type == DateToStringShort));
627 case TimeToStringLong:
628 return macTimeToString(in.toTime(), (type == TimeToStringShort));
629
630 case NegativeSign:
631 case PositiveSign:
632 break;
633 case ZeroDigit:
634 return macZeroDigit();
635
637 return macMeasurementSystem();
638
639 case AMText:
640 case PMText: {
641 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
642 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(NULL, locale, kCFDateFormatterLongStyle, kCFDateFormatterLongStyle);
643 QCFType<CFStringRef> value = static_cast<CFStringRef>(CFDateFormatterCopyProperty(formatter,
644 (type == AMText ? kCFDateFormatterAMSymbol : kCFDateFormatterPMSymbol)));
645 return QString::fromCFString(value);
646 }
647 case FirstDayOfWeek:
648 return QVariant(macFirstDayOfWeek());
649 case CurrencySymbol:
651 case CurrencyToString:
653 case UILanguages: {
655 QCFType<CFArrayRef> languages = CFLocaleCopyPreferredLanguages();
656 const CFIndex cnt = CFArrayGetCount(languages);
657 result.reserve(cnt);
658 for (CFIndex i = 0; i < cnt; ++i) {
659 const QString lang = QString::fromCFString(
660 static_cast<CFStringRef>(CFArrayGetValueAtIndex(languages, i)));
661 result.append(lang);
662 }
663 return QVariant(result);
664 }
667 return macQuoteString(type, in.value<QStringView>());
668 default:
669 break;
670 }
671 return QVariant();
672}
673
674#endif // QT_NO_SYSTEMLOCALE
675
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore \reentrant
Definition qdatetime.h:29
int month() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int day() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int year() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QDate currentDate()
Returns the system clock's current date.
static int yearSharingWeekDays(QDate date)
static QLocale::Language codeToLanguage(QStringView code, QLocale::LanguageCodeTypes codeTypes=QLocale::AnyLanguageCode) noexcept
Definition qlocale.cpp:95
@ MetricSystem
Definition qlocale.h:868
@ ImperialSystem
Definition qlocale.h:871
CurrencySymbolFormat
Definition qlocale.h:896
@ CurrencySymbol
Definition qlocale.h:898
@ CurrencyIsoCode
Definition qlocale.h:897
@ CurrencyDisplayName
Definition qlocale.h:899
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition qlocale.cpp:2862
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1369
@ StringToAlternateQuotation
Definition qlocale_p.h:160
@ StandaloneMonthNameLong
Definition qlocale_p.h:166
@ StandaloneDayNameNarrow
Definition qlocale_p.h:171
@ StandaloneMonthNameNarrow
Definition qlocale_p.h:168
@ StringToStandardQuotation
Definition qlocale_p.h:159
@ StandaloneDayNameShort
Definition qlocale_p.h:170
@ StandaloneDayNameLong
Definition qlocale_p.h:169
@ StandaloneMonthNameShort
Definition qlocale_p.h:167
virtual QLocale fallbackLocale() const
virtual QVariant query(QueryType type, QVariant &&in=QVariant()) const
\inmodule QtCore \reentrant
Definition qdatetime.h:215
\inmodule QtCore
Definition qvariant.h:65
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
QString str
[2]
QString text
QDate date
[1]
cache insert(employee->id(), employee)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define Q_COREAPP_STARTUP_FUNCTION(AFUNC)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qsizetype qt_repeatCount(QStringView s)
Definition qlocale.cpp:675
QString qt_readEscapedFormatString(QStringView format, qsizetype *idx)
Definition qlocale.cpp:625
static QVariant getMacTimeFormat(CFDateFormatterStyle style)
static QVariant macDateToString(QDate date, bool short_format)
static QVariant getCFLocaleValue(CFStringRef key)
static void printLocalizationInformation()
static QVariant macDayName(int day, QSystemLocale::QueryType type)
static QVariant macMeasurementSystem()
static QVariant macTimeToString(QTime time, bool short_format)
static QVariant macMonthName(int month, QSystemLocale::QueryType type)
static QVariant macCurrencySymbol(QLocale::CurrencySymbolFormat format)
static QString zeroPad(QString &&number, qsizetype minDigits, const QString &zero)
static QVariant macToQtFormat(QStringView sys_fmt)
static QString fourDigitYear(int year, const QString &zero)
static QVariant macFormatCurrency(const QSystemLocale::CurrencyToStringArgument &arg)
static QString getMacLocaleName()
static QString trimTwoDigits(QString &&number)
static QVariant getMacDateFormat(CFDateFormatterStyle style)
static QString macDateToStringImpl(QDate date, CFDateFormatterStyle style)
static QString macZeroDigit()
static quint8 macFirstDayOfWeek()
static QLocale::Language codeToLanguage(QStringView s)
static QVariant macQuoteString(QSystemLocale::QueryType type, QStringView str)
static QVariant getLocaleValue(CFStringRef key)
static constexpr int digits(int number)
#define qWarning
Definition qlogging.h:166
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
GLuint64 key
GLuint GLuint end
GLenum type
GLint first
GLint GLsizei GLsizei GLenum format
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLenum array
GLuint in
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
SSL_CTX int void * arg
#define zero
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
unsigned char quint8
Definition qtypes.h:46
static const auto matcher
[0]
QCalendarWidget * calendar
[0]