source: trunk/src/corelib/tools/qlocale.h@ 890

Last change on this file since 890 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 20.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QLOCALE_H
43#define QLOCALE_H
44
45#include <QtCore/qstring.h>
46#include <QtCore/qobjectdefs.h>
47
48QT_BEGIN_HEADER
49
50QT_BEGIN_NAMESPACE
51
52QT_MODULE(Core)
53
54class QDataStream;
55class QDate;
56class QDateTime;
57class QTime;
58class QVariant;
59class QTextStream;
60class QTextStreamPrivate;
61
62class QLocale;
63
64#ifndef QT_NO_SYSTEMLOCALE
65class Q_CORE_EXPORT QSystemLocale
66{
67public:
68 QSystemLocale();
69 virtual ~QSystemLocale();
70
71 enum QueryType {
72 LanguageId, // uint
73 CountryId, // uint
74 DecimalPoint, // QString
75 GroupSeparator, // QString
76 ZeroDigit, // QString
77 NegativeSign, // QString
78 DateFormatLong, // QString
79 DateFormatShort, // QString
80 TimeFormatLong, // QString
81 TimeFormatShort, // QString
82 DayNameLong, // QString, in: int
83 DayNameShort, // QString, in: int
84 MonthNameLong, // QString, in: int
85 MonthNameShort, // QString, in: int
86 DateToStringLong, // QString, in: QDate
87 DateToStringShort, // QString in: QDate
88 TimeToStringLong, // QString in: QTime
89 TimeToStringShort, // QString in: QTime
90 DateTimeFormatLong, // QString
91 DateTimeFormatShort, // QString
92 DateTimeToStringLong, // QString in: QDateTime
93 DateTimeToStringShort, // QString in: QDateTime
94 MeasurementSystem, // uint
95 PositiveSign, // QString
96 AMText, // QString
97 PMText // QString
98 };
99 virtual QVariant query(QueryType type, QVariant in) const;
100 virtual QLocale fallbackLocale() const;
101
102private:
103 QSystemLocale(bool);
104 friend QSystemLocale *QSystemLocale_globalSystemLocale();
105};
106#endif
107
108struct QLocalePrivate;
109class Q_CORE_EXPORT QLocale
110{
111 Q_GADGET
112 Q_ENUMS(Language)
113 Q_ENUMS(Country)
114 friend class QString;
115 friend class QByteArray;
116 friend class QIntValidator;
117 friend class QDoubleValidatorPrivate;
118 friend class QTextStream;
119 friend class QTextStreamPrivate;
120
121public:
122 enum Language {
123 C = 1,
124 Abkhazian = 2,
125 Afan = 3,
126 Afar = 4,
127 Afrikaans = 5,
128 Albanian = 6,
129 Amharic = 7,
130 Arabic = 8,
131 Armenian = 9,
132 Assamese = 10,
133 Aymara = 11,
134 Azerbaijani = 12,
135 Bashkir = 13,
136 Basque = 14,
137 Bengali = 15,
138 Bhutani = 16,
139 Bihari = 17,
140 Bislama = 18,
141 Breton = 19,
142 Bulgarian = 20,
143 Burmese = 21,
144 Byelorussian = 22,
145 Cambodian = 23,
146 Catalan = 24,
147 Chinese = 25,
148 Corsican = 26,
149 Croatian = 27,
150 Czech = 28,
151 Danish = 29,
152 Dutch = 30,
153 English = 31,
154 Esperanto = 32,
155 Estonian = 33,
156 Faroese = 34,
157 FijiLanguage = 35,
158 Finnish = 36,
159 French = 37,
160 Frisian = 38,
161 Gaelic = 39,
162 Galician = 40,
163 Georgian = 41,
164 German = 42,
165 Greek = 43,
166 Greenlandic = 44,
167 Guarani = 45,
168 Gujarati = 46,
169 Hausa = 47,
170 Hebrew = 48,
171 Hindi = 49,
172 Hungarian = 50,
173 Icelandic = 51,
174 Indonesian = 52,
175 Interlingua = 53,
176 Interlingue = 54,
177 Inuktitut = 55,
178 Inupiak = 56,
179 Irish = 57,
180 Italian = 58,
181 Japanese = 59,
182 Javanese = 60,
183 Kannada = 61,
184 Kashmiri = 62,
185 Kazakh = 63,
186 Kinyarwanda = 64,
187 Kirghiz = 65,
188 Korean = 66,
189 Kurdish = 67,
190 Kurundi = 68,
191 Laothian = 69,
192 Latin = 70,
193 Latvian = 71,
194 Lingala = 72,
195 Lithuanian = 73,
196 Macedonian = 74,
197 Malagasy = 75,
198 Malay = 76,
199 Malayalam = 77,
200 Maltese = 78,
201 Maori = 79,
202 Marathi = 80,
203 Moldavian = 81,
204 Mongolian = 82,
205 NauruLanguage = 83,
206 Nepali = 84,
207 Norwegian = 85,
208 NorwegianBokmal = Norwegian,
209 Occitan = 86,
210 Oriya = 87,
211 Pashto = 88,
212 Persian = 89,
213 Polish = 90,
214 Portuguese = 91,
215 Punjabi = 92,
216 Quechua = 93,
217 RhaetoRomance = 94,
218 Romanian = 95,
219 Russian = 96,
220 Samoan = 97,
221 Sangho = 98,
222 Sanskrit = 99,
223 Serbian = 100,
224 SerboCroatian = 101,
225 Sesotho = 102,
226 Setswana = 103,
227 Shona = 104,
228 Sindhi = 105,
229 Singhalese = 106,
230 Siswati = 107,
231 Slovak = 108,
232 Slovenian = 109,
233 Somali = 110,
234 Spanish = 111,
235 Sundanese = 112,
236 Swahili = 113,
237 Swedish = 114,
238 Tagalog = 115,
239 Tajik = 116,
240 Tamil = 117,
241 Tatar = 118,
242 Telugu = 119,
243 Thai = 120,
244 Tibetan = 121,
245 Tigrinya = 122,
246 TongaLanguage = 123,
247 Tsonga = 124,
248 Turkish = 125,
249 Turkmen = 126,
250 Twi = 127,
251 Uigur = 128,
252 Ukrainian = 129,
253 Urdu = 130,
254 Uzbek = 131,
255 Vietnamese = 132,
256 Volapuk = 133,
257 Welsh = 134,
258 Wolof = 135,
259 Xhosa = 136,
260 Yiddish = 137,
261 Yoruba = 138,
262 Zhuang = 139,
263 Zulu = 140,
264 NorwegianNynorsk = 141,
265 Nynorsk = NorwegianNynorsk, // ### obsolete
266 Bosnian = 142,
267 Divehi = 143,
268 Manx = 144,
269 Cornish = 145,
270 Akan = 146,
271 Konkani = 147,
272 Ga = 148,
273 Igbo = 149,
274 Kamba = 150,
275 Syriac = 151,
276 Blin = 152,
277 Geez = 153,
278 Koro = 154,
279 Sidamo = 155,
280 Atsam = 156,
281 Tigre = 157,
282 Jju = 158,
283 Friulian = 159,
284 Venda = 160,
285 Ewe = 161,
286 Walamo = 162,
287 Hawaiian = 163,
288 Tyap = 164,
289 Chewa = 165,
290 Filipino = 166,
291 SwissGerman = 167,
292 SichuanYi = 168,
293 Kpelle = 169,
294 LowGerman = 170,
295 SouthNdebele = 171,
296 NorthernSotho = 172,
297 NorthernSami = 173,
298 Taroko = 174,
299 Gusii = 175,
300 Taita = 176,
301 Fulah = 177,
302 Kikuyu = 178,
303 Samburu = 179,
304 Sena = 180,
305 NorthNdebele = 181,
306 Rombo = 182,
307 Tachelhit = 183,
308 Kabyle = 184,
309 Nyankole = 185,
310 Bena = 186,
311 Vunjo = 187,
312 Bambara = 188,
313 Embu = 189,
314 Cherokee = 190,
315 Morisyen = 191,
316 Makonde = 192,
317 Langi = 193,
318 Ganda = 194,
319 Bemba = 195,
320 Kabuverdianu = 196,
321 Meru = 197,
322 Kalenjin = 198,
323 Nama = 199,
324 Machame = 200,
325 Colognian = 201,
326 Masai = 202,
327 Soga = 203,
328 Luyia = 204,
329 Asu = 205,
330 Teso = 206,
331 Saho = 207,
332 KoyraChiini = 208,
333 Rwa = 209,
334 Luo = 210,
335 Chiga = 211,
336 CentralMoroccoTamazight = 212,
337 KoyraboroSenni = 213,
338 Shambala = 214,
339 LastLanguage = Shambala
340 };
341
342 enum Country {
343 AnyCountry = 0,
344 Afghanistan = 1,
345 Albania = 2,
346 Algeria = 3,
347 AmericanSamoa = 4,
348 Andorra = 5,
349 Angola = 6,
350 Anguilla = 7,
351 Antarctica = 8,
352 AntiguaAndBarbuda = 9,
353 Argentina = 10,
354 Armenia = 11,
355 Aruba = 12,
356 Australia = 13,
357 Austria = 14,
358 Azerbaijan = 15,
359 Bahamas = 16,
360 Bahrain = 17,
361 Bangladesh = 18,
362 Barbados = 19,
363 Belarus = 20,
364 Belgium = 21,
365 Belize = 22,
366 Benin = 23,
367 Bermuda = 24,
368 Bhutan = 25,
369 Bolivia = 26,
370 BosniaAndHerzegowina = 27,
371 Botswana = 28,
372 BouvetIsland = 29,
373 Brazil = 30,
374 BritishIndianOceanTerritory = 31,
375 BruneiDarussalam = 32,
376 Bulgaria = 33,
377 BurkinaFaso = 34,
378 Burundi = 35,
379 Cambodia = 36,
380 Cameroon = 37,
381 Canada = 38,
382 CapeVerde = 39,
383 CaymanIslands = 40,
384 CentralAfricanRepublic = 41,
385 Chad = 42,
386 Chile = 43,
387 China = 44,
388 ChristmasIsland = 45,
389 CocosIslands = 46,
390 Colombia = 47,
391 Comoros = 48,
392 DemocraticRepublicOfCongo = 49,
393 PeoplesRepublicOfCongo = 50,
394 CookIslands = 51,
395 CostaRica = 52,
396 IvoryCoast = 53,
397 Croatia = 54,
398 Cuba = 55,
399 Cyprus = 56,
400 CzechRepublic = 57,
401 Denmark = 58,
402 Djibouti = 59,
403 Dominica = 60,
404 DominicanRepublic = 61,
405 EastTimor = 62,
406 Ecuador = 63,
407 Egypt = 64,
408 ElSalvador = 65,
409 EquatorialGuinea = 66,
410 Eritrea = 67,
411 Estonia = 68,
412 Ethiopia = 69,
413 FalklandIslands = 70,
414 FaroeIslands = 71,
415 FijiCountry = 72,
416 Finland = 73,
417 France = 74,
418 MetropolitanFrance = 75,
419 FrenchGuiana = 76,
420 FrenchPolynesia = 77,
421 FrenchSouthernTerritories = 78,
422 Gabon = 79,
423 Gambia = 80,
424 Georgia = 81,
425 Germany = 82,
426 Ghana = 83,
427 Gibraltar = 84,
428 Greece = 85,
429 Greenland = 86,
430 Grenada = 87,
431 Guadeloupe = 88,
432 Guam = 89,
433 Guatemala = 90,
434 Guinea = 91,
435 GuineaBissau = 92,
436 Guyana = 93,
437 Haiti = 94,
438 HeardAndMcDonaldIslands = 95,
439 Honduras = 96,
440 HongKong = 97,
441 Hungary = 98,
442 Iceland = 99,
443 India = 100,
444 Indonesia = 101,
445 Iran = 102,
446 Iraq = 103,
447 Ireland = 104,
448 Israel = 105,
449 Italy = 106,
450 Jamaica = 107,
451 Japan = 108,
452 Jordan = 109,
453 Kazakhstan = 110,
454 Kenya = 111,
455 Kiribati = 112,
456 DemocraticRepublicOfKorea = 113,
457 RepublicOfKorea = 114,
458 Kuwait = 115,
459 Kyrgyzstan = 116,
460 Lao = 117,
461 Latvia = 118,
462 Lebanon = 119,
463 Lesotho = 120,
464 Liberia = 121,
465 LibyanArabJamahiriya = 122,
466 Liechtenstein = 123,
467 Lithuania = 124,
468 Luxembourg = 125,
469 Macau = 126,
470 Macedonia = 127,
471 Madagascar = 128,
472 Malawi = 129,
473 Malaysia = 130,
474 Maldives = 131,
475 Mali = 132,
476 Malta = 133,
477 MarshallIslands = 134,
478 Martinique = 135,
479 Mauritania = 136,
480 Mauritius = 137,
481 Mayotte = 138,
482 Mexico = 139,
483 Micronesia = 140,
484 Moldova = 141,
485 Monaco = 142,
486 Mongolia = 143,
487 Montserrat = 144,
488 Morocco = 145,
489 Mozambique = 146,
490 Myanmar = 147,
491 Namibia = 148,
492 NauruCountry = 149,
493 Nepal = 150,
494 Netherlands = 151,
495 NetherlandsAntilles = 152,
496 NewCaledonia = 153,
497 NewZealand = 154,
498 Nicaragua = 155,
499 Niger = 156,
500 Nigeria = 157,
501 Niue = 158,
502 NorfolkIsland = 159,
503 NorthernMarianaIslands = 160,
504 Norway = 161,
505 Oman = 162,
506 Pakistan = 163,
507 Palau = 164,
508 PalestinianTerritory = 165,
509 Panama = 166,
510 PapuaNewGuinea = 167,
511 Paraguay = 168,
512 Peru = 169,
513 Philippines = 170,
514 Pitcairn = 171,
515 Poland = 172,
516 Portugal = 173,
517 PuertoRico = 174,
518 Qatar = 175,
519 Reunion = 176,
520 Romania = 177,
521 RussianFederation = 178,
522 Rwanda = 179,
523 SaintKittsAndNevis = 180,
524 StLucia = 181,
525 StVincentAndTheGrenadines = 182,
526 Samoa = 183,
527 SanMarino = 184,
528 SaoTomeAndPrincipe = 185,
529 SaudiArabia = 186,
530 Senegal = 187,
531 Seychelles = 188,
532 SierraLeone = 189,
533 Singapore = 190,
534 Slovakia = 191,
535 Slovenia = 192,
536 SolomonIslands = 193,
537 Somalia = 194,
538 SouthAfrica = 195,
539 SouthGeorgiaAndTheSouthSandwichIslands = 196,
540 Spain = 197,
541 SriLanka = 198,
542 StHelena = 199,
543 StPierreAndMiquelon = 200,
544 Sudan = 201,
545 Suriname = 202,
546 SvalbardAndJanMayenIslands = 203,
547 Swaziland = 204,
548 Sweden = 205,
549 Switzerland = 206,
550 SyrianArabRepublic = 207,
551 Taiwan = 208,
552 Tajikistan = 209,
553 Tanzania = 210,
554 Thailand = 211,
555 Togo = 212,
556 Tokelau = 213,
557 TongaCountry = 214,
558 TrinidadAndTobago = 215,
559 Tunisia = 216,
560 Turkey = 217,
561 Turkmenistan = 218,
562 TurksAndCaicosIslands = 219,
563 Tuvalu = 220,
564 Uganda = 221,
565 Ukraine = 222,
566 UnitedArabEmirates = 223,
567 UnitedKingdom = 224,
568 UnitedStates = 225,
569 UnitedStatesMinorOutlyingIslands = 226,
570 Uruguay = 227,
571 Uzbekistan = 228,
572 Vanuatu = 229,
573 VaticanCityState = 230,
574 Venezuela = 231,
575 VietNam = 232,
576 BritishVirginIslands = 233,
577 USVirginIslands = 234,
578 WallisAndFutunaIslands = 235,
579 WesternSahara = 236,
580 Yemen = 237,
581 Yugoslavia = 238,
582 Zambia = 239,
583 Zimbabwe = 240,
584 SerbiaAndMontenegro = 241,
585 Montenegro = 242,
586 Serbia = 243,
587 SaintBarthelemy = 244,
588 SaintMartin = 245,
589 LatinAmericaAndTheCaribbean = 246,
590 LastCountry = LatinAmericaAndTheCaribbean
591 };
592
593 enum MeasurementSystem { MetricSystem, ImperialSystem };
594
595 enum FormatType { LongFormat, ShortFormat, NarrowFormat };
596 enum NumberOption {
597 OmitGroupSeparator = 0x01,
598 RejectGroupSeparator = 0x02
599 };
600 Q_DECLARE_FLAGS(NumberOptions, NumberOption)
601
602 QLocale();
603 QLocale(const QString &name);
604 QLocale(Language language, Country country = AnyCountry);
605 QLocale(const QLocale &other);
606
607 QLocale &operator=(const QLocale &other);
608
609 Language language() const;
610 Country country() const;
611 QString name() const;
612
613 short toShort(const QString &s, bool *ok = 0, int base = 0) const;
614 ushort toUShort(const QString &s, bool *ok = 0, int base = 0) const;
615 int toInt(const QString &s, bool *ok = 0, int base = 0) const;
616 uint toUInt(const QString &s, bool *ok = 0, int base = 0) const;
617 qlonglong toLongLong(const QString &s, bool *ok = 0, int base = 0) const;
618 qlonglong toULongLong(const QString &s, bool *ok = 0, int base = 0) const;
619 float toFloat(const QString &s, bool *ok = 0) const;
620 double toDouble(const QString &s, bool *ok = 0) const;
621
622 QString toString(qlonglong i) const;
623 QString toString(qulonglong i) const;
624 inline QString toString(short i) const;
625 inline QString toString(ushort i) const;
626 inline QString toString(int i) const;
627 inline QString toString(uint i) const;
628 QString toString(double i, char f = 'g', int prec = 6) const;
629 inline QString toString(float i, char f = 'g', int prec = 6) const;
630 QString toString(const QDate &date, const QString &formatStr) const;
631 QString toString(const QDate &date, FormatType format = LongFormat) const;
632 QString toString(const QTime &time, const QString &formatStr) const;
633 QString toString(const QTime &time, FormatType format = LongFormat) const;
634 QString toString(const QDateTime &dateTime, FormatType format = LongFormat) const;
635 QString toString(const QDateTime &dateTime, const QString &format) const;
636
637 QString dateFormat(FormatType format = LongFormat) const;
638 QString timeFormat(FormatType format = LongFormat) const;
639 QString dateTimeFormat(FormatType format = LongFormat) const;
640#ifndef QT_NO_DATESTRING
641 QDate toDate(const QString &string, FormatType = LongFormat) const;
642 QTime toTime(const QString &string, FormatType = LongFormat) const;
643 QDateTime toDateTime(const QString &string, FormatType format = LongFormat) const;
644 QDate toDate(const QString &string, const QString &format) const;
645 QTime toTime(const QString &string, const QString &format) const;
646 QDateTime toDateTime(const QString &string, const QString &format) const;
647#endif
648
649 // ### Qt 5: We need to return QString from these function since
650 // unicode data contains several characters for these fields.
651 QChar decimalPoint() const;
652 QChar groupSeparator() const;
653 QChar percent() const;
654 QChar zeroDigit() const;
655 QChar negativeSign() const;
656 QChar positiveSign() const;
657 QChar exponential() const;
658
659 QString monthName(int, FormatType format = LongFormat) const;
660 QString standaloneMonthName(int, FormatType format = LongFormat) const;
661 QString dayName(int, FormatType format = LongFormat) const;
662 QString standaloneDayName(int, FormatType format = LongFormat) const;
663
664 QString amText() const;
665 QString pmText() const;
666
667 MeasurementSystem measurementSystem() const;
668
669 Qt::LayoutDirection textDirection() const;
670
671 inline bool operator==(const QLocale &other) const;
672 inline bool operator!=(const QLocale &other) const;
673
674 static QString languageToString(Language language);
675 static QString countryToString(Country country);
676 static void setDefault(const QLocale &locale);
677
678 static QLocale c() { return QLocale(C); }
679 static QLocale system();
680
681 static QList<Country> countriesForLanguage(Language lang);
682
683 void setNumberOptions(NumberOptions options);
684 NumberOptions numberOptions() const;
685
686//private: // this should be private, but can't be
687 struct Data {
688 quint16 index;
689 quint16 numberOptions;
690 };
691private:
692 friend struct QLocalePrivate;
693 // ### We now use this field to pack an index into locale_data and NumberOptions.
694 // ### Qt 5: change to a QLocaleData *d; uint numberOptions.
695 union {
696 void *v;
697 Data p;
698 };
699 const QLocalePrivate *d() const;
700};
701Q_DECLARE_TYPEINFO(QLocale, Q_MOVABLE_TYPE);
702Q_DECLARE_OPERATORS_FOR_FLAGS(QLocale::NumberOptions)
703
704inline QString QLocale::toString(short i) const
705 { return toString(qlonglong(i)); }
706inline QString QLocale::toString(ushort i) const
707 { return toString(qulonglong(i)); }
708inline QString QLocale::toString(int i) const
709 { return toString(qlonglong(i)); }
710inline QString QLocale::toString(uint i) const
711 { return toString(qulonglong(i)); }
712inline QString QLocale::toString(float i, char f, int prec) const
713 { return toString(double(i), f, prec); }
714inline bool QLocale::operator==(const QLocale &other) const
715 { return d() == other.d() && numberOptions() == other.numberOptions(); }
716inline bool QLocale::operator!=(const QLocale &other) const
717 { return d() != other.d() || numberOptions() != other.numberOptions(); }
718
719#ifndef QT_NO_DATASTREAM
720Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLocale &);
721Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLocale &);
722#endif
723
724QT_END_NAMESPACE
725
726QT_END_HEADER
727
728#endif // QLOCALE_H
Note: See TracBrowser for help on using the repository browser.