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

Last change on this file since 448 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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