Qt 6.x
The Qt SDK
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 // Trigger initialization of standard user defaults, so that Foundation picks
36 // up -AppleLanguages and -AppleLocale passed on the command line.
37 Q_UNUSED(NSUserDefaults.standardUserDefaults);
38
39 auto singleLineDescription = [](NSArray *array) {
40 NSString *str = [array description];
41 str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
42 return [str stringByReplacingOccurrencesOfString:@" " withString:@""];
43 };
44
45 bool allowMixedLocalizations = [NSBundle.mainBundle.infoDictionary[@"CFBundleAllowMixedLocalizations"] boolValue];
46
47 NSBundle *foundation = [NSBundle bundleForClass:NSBundle.class];
48 qCDebug(lcLocale).nospace() << "Launched with locale \"" << NSLocale.currentLocale.localeIdentifier
49 << "\" based on user's preferred languages " << singleLineDescription(NSLocale.preferredLanguages)
50 << ", main bundle localizations " << singleLineDescription(NSBundle.mainBundle.localizations)
51 << ", and allowing mixed localizations " << allowMixedLocalizations
52 << "; resulting in main bundle preferred localizations "
53 << singleLineDescription(NSBundle.mainBundle.preferredLocalizations)
54 << " and Foundation preferred localizations "
55 << singleLineDescription(foundation.preferredLocalizations);
56 qCDebug(lcLocale) << "Reflected by Qt as system locale"
57 << QLocale::system() << "with UI languges " << QLocale::system().uiLanguages();
58}
60
62{
63 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
64 CFStringRef locale = CFLocaleGetIdentifier(l);
65 return QString::fromCFString(locale);
66}
67
69{
70 month -= 1;
71 if (month < 0 || month > 11)
72 return {};
73
75 = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
76 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
77
78 CFDateFormatterKey formatterType;
79 switch (type) {
81 formatterType = kCFDateFormatterMonthSymbols;
82 break;
84 formatterType = kCFDateFormatterShortMonthSymbols;
85 break;
87 formatterType = kCFDateFormatterVeryShortMonthSymbols;
88 break;
90 formatterType = kCFDateFormatterStandaloneMonthSymbols;
91 break;
93 formatterType = kCFDateFormatterShortStandaloneMonthSymbols;
94 break;
96 formatterType = kCFDateFormatterVeryShortStandaloneMonthSymbols;
97 break;
98 default:
99 qWarning("macMonthName: Unsupported query type %d", type);
100 return {};
101 }
103 = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, formatterType));
104
105 if (values != 0) {
106 CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month));
107 return QString::fromCFString(cfstring);
108 }
109 return {};
110}
111
113{
114 if (day < 1 || day > 7)
115 return {};
116
118 = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()),
119 kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
120
121 CFDateFormatterKey formatterType;
122 switch (type) {
124 formatterType = kCFDateFormatterWeekdaySymbols;
125 break;
127 formatterType = kCFDateFormatterShortWeekdaySymbols;
128 break;
130 formatterType = kCFDateFormatterVeryShortWeekdaySymbols;
131 break;
133 formatterType = kCFDateFormatterStandaloneWeekdaySymbols;
134 break;
136 formatterType = kCFDateFormatterShortStandaloneWeekdaySymbols;
137 break;
139 formatterType = kCFDateFormatterVeryShortStandaloneWeekdaySymbols;
140 break;
141 default:
142 qWarning("macDayName: Unsupported query type %d", type);
143 return {};
144 }
146 static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, formatterType));
147
148 if (values != 0) {
149 CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7));
150 return QString::fromCFString(cfstring);
151 }
152 return {};
153}
154
156{
157 static QString cachedZeroDigit;
158
159 if (cachedZeroDigit.isNull()) {
160 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
161 QCFType<CFNumberFormatterRef> numberFormatter =
162 CFNumberFormatterCreate(nullptr, locale, kCFNumberFormatterNoStyle);
163 const int zeroDigit = 0;
165 = CFNumberFormatterCreateStringWithValue(nullptr, numberFormatter,
166 kCFNumberIntType, &zeroDigit);
167 cachedZeroDigit = QString::fromCFString(value);
168 }
169
170 static QMacNotificationObserver localeChangeObserver = QMacNotificationObserver(
171 nil, NSCurrentLocaleDidChangeNotification, [&] {
172 qCDebug(lcLocale) << "System locale changed";
173 cachedZeroDigit = QString();
174 });
175
176 return cachedZeroDigit;
177}
178
179static QString zeroPad(QString &&number, qsizetype minDigits, const QString &zero)
180{
181 // Need to pad with zeros, possibly after a sign.
182 qsizetype insert = -1, digits = 0;
183 auto it = QStringIterator(number);
184 while (it.hasNext()) {
185 qsizetype here = it.index();
186 if (QChar::isDigit(it.next())) {
187 if (insert < 0)
188 insert = here;
189 ++digits;
190 } // else: assume we're stepping over a sign (or maybe grouping separator)
191 }
192 Q_ASSERT(digits > 0);
193 Q_ASSERT(insert >= 0);
194 while (digits++ < minDigits)
195 number.insert(insert, zero);
196
197 return std::move(number);
198}
199
201{
202 // Retain any sign, but remove all but the last two digits.
203 // We know number has at least four digits - it came from fourDigitYear().
204 // Note that each digit might be a surrogate pair.
205 qsizetype first = -1, prev = -1, last = -1;
206 auto it = QStringIterator(number);
207 while (it.hasNext()) {
208 qsizetype here = it.index();
209 if (QChar::isDigit(it.next())) {
210 if (first == -1)
211 last = first = here;
212 else if (last != -1)
213 prev = std::exchange(last, here);
214 }
215 }
216 Q_ASSERT(first >= 0);
217 Q_ASSERT(prev > first);
218 Q_ASSERT(last > prev);
219 number.remove(first, prev - first);
220 return std::move(number);
221}
222
223static QString fourDigitYear(int year, const QString &zero)
224{
225 // Return year formatted as an (at least) four digit number:
226 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
227 QCFType<CFNumberFormatterRef> numberFormatter =
228 CFNumberFormatterCreate(nullptr, locale, kCFNumberFormatterNoStyle);
229 QCFType<CFStringRef> value = CFNumberFormatterCreateStringWithValue(nullptr, numberFormatter,
230 kCFNumberIntType, &year);
231 auto text = QString::fromCFString(value);
232 if (year > -1000 && year < 1000)
233 text = zeroPad(std::move(text), 4, zero);
234 return text;
235}
236
237static QString macDateToStringImpl(QDate date, CFDateFormatterStyle style)
238{
239 // Use noon on the given date, to avoid complications that can arise for
240 // dates before 1900 (see QTBUG-54955) using different UTC offset than
241 // QDateTime extrapolates backwards from time_t functions that only work
242 // back to 1900. (Alaska and Phillipines may still be borked, though.)
243 QCFType<CFDateRef> myDate = QDateTime(date, QTime(12, 0)).toCFDate();
244 QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent();
246 = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, style,
247 kCFDateFormatterNoStyle);
248 QCFType<CFStringRef> text = CFDateFormatterCreateStringWithDate(nullptr, myFormatter, myDate);
249 return QString::fromCFString(text);
250}
251
252static QVariant macDateToString(QDate date, bool short_format)
253{
254 const int year = date.year();
255 QString fakeYear, trueYear;
256 if (year < 1583) {
257 // System API (in macOS 11.0, at least) discards sign :-(
258 // Simply negating the year won't do as the resulting year typically has
259 // a different pattern of week-days.
260 // Furthermore (see QTBUG-54955), Darwin uses the Julian calendar for
261 // dates before 1582-10-15, leading to discrepancies.
263 Q_ASSERT(matcher >= 1583);
264 Q_ASSERT(matcher % 100 != date.month());
265 Q_ASSERT(matcher % 100 != date.day());
266 // i.e. there can't be any confusion between the two-digit year and
267 // month or day-of-month in the formatted date.
269 fakeYear = fourDigitYear(matcher, zero);
270 trueYear = fourDigitYear(year, zero);
272 }
273 QString text = macDateToStringImpl(date, short_format
274 ? kCFDateFormatterShortStyle
275 : kCFDateFormatterLongStyle);
276 if (year < 1583) {
277 if (text.contains(fakeYear))
278 return std::move(text).replace(fakeYear, trueYear);
279 // Cope with two-digit year:
280 fakeYear = trimTwoDigits(std::move(fakeYear));
281 trueYear = trimTwoDigits(std::move(trueYear));
282 if (text.contains(fakeYear))
283 return std::move(text).replace(fakeYear, trueYear);
284 // That should have worked.
285 qWarning("Failed to fix up year when formatting a date in year %d", year);
286 }
287 return text;
288}
289
290static QVariant macTimeToString(QTime time, bool short_format)
291{
292 QCFType<CFDateRef> myDate = QDateTime(QDate::currentDate(), time).toCFDate();
293 QCFType<CFLocaleRef> mylocale = CFLocaleCopyCurrent();
294 CFDateFormatterStyle style = short_format ? kCFDateFormatterShortStyle : kCFDateFormatterLongStyle;
295 QCFType<CFDateFormatterRef> myFormatter = CFDateFormatterCreate(kCFAllocatorDefault,
296 mylocale,
297 kCFDateFormatterNoStyle,
298 style);
299 QCFType<CFStringRef> text = CFDateFormatterCreateStringWithDate(0, myFormatter, myDate);
300 return QString::fromCFString(text);
301}
302
303// Mac uses the Unicode CLDR format codes
304// http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
305// See also qtbase/util/locale_database/dateconverter.py
306// Makes the assumption that input formats are always well formed and consecutive letters
307// never exceed the maximum for the format code.
309{
311 qsizetype i = 0;
312
313 while (i < sys_fmt.size()) {
314 if (sys_fmt.at(i).unicode() == '\'') {
316 if (text == "'"_L1)
317 result += "''"_L1;
318 else
319 result += u'\'' + text + u'\'';
320 continue;
321 }
322
323 QChar c = sys_fmt.at(i);
324 qsizetype repeat = qt_repeatCount(sys_fmt.mid(i));
325
326 switch (c.unicode()) {
327 // Qt does not support the following options
328 case 'G': // Era (1..5): 4 = long, 1..3 = short, 5 = narrow
329 case 'Y': // Year of Week (1..n): 1..n = padded number
330 case 'U': // Cyclic Year Name (1..5): 4 = long, 1..3 = short, 5 = narrow
331 case 'Q': // Quarter (1..4): 4 = long, 3 = short, 1..2 = padded number
332 case 'q': // Standalone Quarter (1..4): 4 = long, 3 = short, 1..2 = padded number
333 case 'w': // Week of Year (1..2): 1..2 = padded number
334 case 'W': // Week of Month (1): 1 = number
335 case 'D': // Day of Year (1..3): 1..3 = padded number
336 case 'F': // Day of Week in Month (1): 1 = number
337 case 'g': // Modified Julian Day (1..n): 1..n = padded number
338 case 'A': // Milliseconds in Day (1..n): 1..n = padded number
339 break;
340
341 case 'y': // Year (1..n): 2 = short year, 1 & 3..n = padded number
342 case 'u': // Extended Year (1..n): 2 = short year, 1 & 3..n = padded number
343 // Qt only supports long (4) or short (2) year, use long for all others
344 if (repeat == 2)
345 result += "yy"_L1;
346 else
347 result += "yyyy"_L1;
348 break;
349 case 'M': // Month (1..5): 4 = long, 3 = short, 1..2 = number, 5 = narrow
350 case 'L': // Standalone Month (1..5): 4 = long, 3 = short, 1..2 = number, 5 = narrow
351 // Qt only supports long, short and number, use short for narrow
352 if (repeat == 5)
353 result += "MMM"_L1;
354 else
355 result += QString(repeat, u'M');
356 break;
357 case 'd': // Day of Month (1..2): 1..2 padded number
358 result += QString(repeat, c);
359 break;
360 case 'E': // Day of Week (1..6): 4 = long, 1..3 = short, 5..6 = narrow
361 // Qt only supports long, short and padded number, use short for narrow
362 if (repeat == 4)
363 result += "dddd"_L1;
364 else
365 result += "ddd"_L1;
366 break;
367 case 'e': // Local Day of Week (1..6): 4 = long, 3 = short, 5..6 = narrow, 1..2 padded number
368 case 'c': // Standalone Local Day of Week (1..6): 4 = long, 3 = short, 5..6 = narrow, 1..2 padded number
369 // Qt only supports long, short and padded number, use short for narrow
370 if (repeat >= 5)
371 result += "ddd"_L1;
372 else
373 result += QString(repeat, 'd'_L1);
374 break;
375 case 'a': // AM/PM (1): 1 = short
376 // Translate to Qt uppercase AM/PM
377 result += "AP"_L1;
378 break;
379 case 'h': // Hour [1..12] (1..2): 1..2 = padded number
380 case 'K': // Hour [0..11] (1..2): 1..2 = padded number
381 case 'j': // Local Hour [12 or 24] (1..2): 1..2 = padded number
382 // Qt h is local hour
383 result += QString(repeat, 'h'_L1);
384 break;
385 case 'H': // Hour [0..23] (1..2): 1..2 = padded number
386 case 'k': // Hour [1..24] (1..2): 1..2 = padded number
387 // Qt H is 0..23 hour
388 result += QString(repeat, 'H'_L1);
389 break;
390 case 'm': // Minutes (1..2): 1..2 = padded number
391 case 's': // Seconds (1..2): 1..2 = padded number
392 result += QString(repeat, c);
393 break;
394 case 'S': // Fractional second (1..n): 1..n = truncates to decimal places
395 // Qt uses msecs either unpadded or padded to 3 places
396 if (repeat < 3)
397 result += u'z';
398 else
399 result += "zzz"_L1;
400 break;
401 case 'z': // Time Zone (1..4)
402 case 'Z': // Time Zone (1..5)
403 case 'O': // Time Zone (1, 4)
404 case 'v': // Time Zone (1, 4)
405 case 'V': // Time Zone (1..4)
406 case 'X': // Time Zone (1..5)
407 case 'x': // Time Zone (1..5)
408 result += u't';
409 break;
410 default:
411 // a..z and A..Z are reserved for format codes, so any occurrence of these not
412 // already processed are not known and so unsupported formats to be ignored.
413 // All other chars are allowed as literals.
414 if (c < u'A' || c > u'z' || (c > u'Z' && c < u'a'))
415 result += QString(repeat, c);
416 break;
417 }
418
419 i += repeat;
420 }
421
422 return !result.isEmpty() ? QVariant::fromValue(result) : QVariant();
423}
424
425static QVariant getMacDateFormat(CFDateFormatterStyle style)
426{
427 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
428 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault,
429 l, style, kCFDateFormatterNoStyle);
430 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
431}
432
433static QVariant getMacTimeFormat(CFDateFormatterStyle style)
434{
435 QCFType<CFLocaleRef> l = CFLocaleCopyCurrent();
436 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(kCFAllocatorDefault,
437 l, kCFDateFormatterNoStyle, style);
438 return macToQtFormat(QString::fromCFString(CFDateFormatterGetFormat(formatter)));
439}
440
441static QVariant getCFLocaleValue(CFStringRef key)
442{
443 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
444 CFTypeRef value = CFLocaleGetValue(locale, key);
445 if (!value)
446 return QVariant();
447 return QString::fromCFString(CFStringRef(static_cast<CFTypeRef>(value)));
448}
449
451{
452 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
453 CFStringRef system = static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleMeasurementSystem));
454 if (QString::fromCFString(system) == "Metric"_L1) {
456 } else {
458 }
459}
460
461
463{
464 QCFType<CFCalendarRef> calendar = CFCalendarCopyCurrent();
465 quint8 day = static_cast<quint8>(CFCalendarGetFirstWeekday(calendar))-1;
466 if (day == 0)
467 day = 7;
468 return day;
469}
470
472{
473 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
474 switch (format) {
476 return QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode)));
478 return QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleCurrencySymbol)));
480 CFStringRef code = static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleCurrencyCode));
481 QCFType<CFStringRef> value = CFLocaleCopyDisplayNameForPropertyValue(locale, kCFLocaleCurrencyCode, code);
482 return QString::fromCFString(value);
483 }
484 default:
485 break;
486 }
487 return {};
488}
489
490#ifndef QT_NO_SYSTEMLOCALE
492{
494 switch (arg.value.metaType().id()) {
495 case QMetaType::Int:
496 case QMetaType::UInt: {
497 int v = arg.value.toInt();
498 value = CFNumberCreate(NULL, kCFNumberIntType, &v);
499 break;
500 }
501 case QMetaType::Double: {
502 double v = arg.value.toDouble();
503 value = CFNumberCreate(NULL, kCFNumberDoubleType, &v);
504 break;
505 }
506 case QMetaType::LongLong:
507 case QMetaType::ULongLong: {
508 qint64 v = arg.value.toLongLong();
509 value = CFNumberCreate(NULL, kCFNumberLongLongType, &v);
510 break;
511 }
512 default:
513 return {};
514 }
515
516 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
517 QCFType<CFNumberFormatterRef> currencyFormatter =
518 CFNumberFormatterCreate(NULL, locale, kCFNumberFormatterCurrencyStyle);
519 if (!arg.symbol.isEmpty()) {
520 CFNumberFormatterSetProperty(currencyFormatter, kCFNumberFormatterCurrencySymbol,
521 arg.symbol.toCFString());
522 }
523 QCFType<CFStringRef> result = CFNumberFormatterCreateStringWithNumber(NULL, currencyFormatter, value);
524 return QString::fromCFString(result);
525}
526
528{
530 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
531 switch (type) {
533 begin = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey)));
534 end = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey)));
535 return QString(begin % str % end);
537 begin = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey)));
538 end = QString::fromCFString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey)));
539 return QString(begin % str % end);
540 default:
541 break;
542 }
543 return QVariant();
544}
545#endif //QT_NO_SYSTEMLOCALE
546
547#ifndef QT_NO_SYSTEMLOCALE
548
550{
551 return QLocale(getMacLocaleName());
552}
553
554template <auto CodeToValueFunction>
555static QVariant getLocaleValue(CFStringRef key)
556{
557 if (auto code = getCFLocaleValue(key); !code.isNull()) {
558 // If an invalid locale is requested with -AppleLocale, the system APIs
559 // will report invalid or empty locale values back to us, which codeToLanguage()
560 // and friends will fail to parse, resulting in returning QLocale::Any{L/C/S}.
561 // If this is the case, we fall down and return a null-variant, which
562 // QLocale's updateSystemPrivate() will interpret to use fallback logic.
563 if (auto value = CodeToValueFunction(code.toString()))
564 return value;
565 }
566 return QVariant();
567}
568
570{
572}
573
575{
577
578 switch(type) {
579 case LanguageId:
580 return getLocaleValue<codeToLanguage>(kCFLocaleLanguageCode);
581 case TerritoryId:
582 return getLocaleValue<QLocalePrivate::codeToTerritory>(kCFLocaleCountryCode);
583 case ScriptId:
584 return getLocaleValue<QLocalePrivate::codeToScript>(kCFLocaleScriptCode);
585 case DecimalPoint:
586 return getCFLocaleValue(kCFLocaleDecimalSeparator);
587 case GroupSeparator:
588 return getCFLocaleValue(kCFLocaleGroupingSeparator);
589 case DateFormatLong:
590 case DateFormatShort:
592 ? kCFDateFormatterShortStyle
593 : kCFDateFormatterLongStyle);
594 case TimeFormatLong:
595 case TimeFormatShort:
597 ? kCFDateFormatterShortStyle
598 : kCFDateFormatterLongStyle);
599 case DayNameLong:
600 case DayNameShort:
601 case DayNameNarrow:
605 return macDayName(in.toInt(), type);
606 case MonthNameLong:
607 case MonthNameShort:
608 case MonthNameNarrow:
612 return macMonthName(in.toInt(), type);
614 case DateToStringLong:
615 return macDateToString(in.toDate(), (type == DateToStringShort));
617 case TimeToStringLong:
618 return macTimeToString(in.toTime(), (type == TimeToStringShort));
619
620 case NegativeSign:
621 case PositiveSign:
622 break;
623 case ZeroDigit:
624 return macZeroDigit();
625
627 return macMeasurementSystem();
628
629 case AMText:
630 case PMText: {
631 QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
632 QCFType<CFDateFormatterRef> formatter = CFDateFormatterCreate(NULL, locale, kCFDateFormatterLongStyle, kCFDateFormatterLongStyle);
633 QCFType<CFStringRef> value = static_cast<CFStringRef>(CFDateFormatterCopyProperty(formatter,
634 (type == AMText ? kCFDateFormatterAMSymbol : kCFDateFormatterPMSymbol)));
635 return QString::fromCFString(value);
636 }
637 case FirstDayOfWeek:
638 return QVariant(macFirstDayOfWeek());
639 case CurrencySymbol:
641 case CurrencyToString:
643 case UILanguages: {
645 QCFType<CFArrayRef> languages = CFLocaleCopyPreferredLanguages();
646 const CFIndex cnt = CFArrayGetCount(languages);
647 result.reserve(cnt);
648 for (CFIndex i = 0; i < cnt; ++i) {
649 const QString lang = QString::fromCFString(
650 static_cast<CFStringRef>(CFArrayGetValueAtIndex(languages, i)));
651 result.append(lang);
652 }
653 return QVariant(result);
654 }
657 return macQuoteString(type, in.value<QStringView>());
658 default:
659 break;
660 }
661 return QVariant();
662}
663
664#endif // QT_NO_SYSTEMLOCALE
665
\inmodule QtCore
Definition qchar.h:48
constexpr bool isDigit() const noexcept
Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false.
Definition qchar.h:473
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
Definition qchar.h:458
\inmodule QtCore\reentrant
Definition qdatetime.h:257
\inmodule QtCore \reentrant
Definition qdatetime.h:27
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:93
QStringList uiLanguages() const
List of locale names for use in selecting translations.
Definition qlocale.cpp:4580
@ MetricSystem
Definition qlocale.h:858
@ ImperialSystem
Definition qlocale.h:861
CurrencySymbolFormat
Definition qlocale.h:883
@ CurrencySymbol
Definition qlocale.h:885
@ CurrencyIsoCode
Definition qlocale.h:884
@ CurrencyDisplayName
Definition qlocale.h:886
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition qlocale.cpp:2742
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:76
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3794
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1217
@ StringToAlternateQuotation
Definition qlocale_p.h:147
@ StandaloneMonthNameLong
Definition qlocale_p.h:153
@ StandaloneDayNameNarrow
Definition qlocale_p.h:158
@ StandaloneMonthNameNarrow
Definition qlocale_p.h:155
@ StringToStandardQuotation
Definition qlocale_p.h:146
@ StandaloneDayNameShort
Definition qlocale_p.h:157
@ StandaloneDayNameLong
Definition qlocale_p.h:156
@ StandaloneMonthNameShort
Definition qlocale_p.h:154
virtual QVariant query(QueryType type, QVariant in=QVariant()) const
virtual QLocale fallbackLocale() const
\inmodule QtCore \reentrant
Definition qdatetime.h:189
\inmodule QtCore
Definition qvariant.h:64
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:531
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:673
QString qt_readEscapedFormatString(QStringView format, qsizetype *idx)
Definition qlocale.cpp:623
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:162
#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
const GLubyte * c
GLenum array
GLuint in
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
#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:70
long long qint64
Definition qtypes.h:55
unsigned char quint8
Definition qtypes.h:41
static const auto matcher
[0]
QCalendarWidget * calendar
[0]