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

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

trunk: Merged in qt 4.6.1 sources.

File size: 19.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 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 QDoubleValidator;
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 LastLanguage = Chewa
291 };
292
293 enum Country {
294 AnyCountry = 0,
295 Afghanistan = 1,
296 Albania = 2,
297 Algeria = 3,
298 AmericanSamoa = 4,
299 Andorra = 5,
300 Angola = 6,
301 Anguilla = 7,
302 Antarctica = 8,
303 AntiguaAndBarbuda = 9,
304 Argentina = 10,
305 Armenia = 11,
306 Aruba = 12,
307 Australia = 13,
308 Austria = 14,
309 Azerbaijan = 15,
310 Bahamas = 16,
311 Bahrain = 17,
312 Bangladesh = 18,
313 Barbados = 19,
314 Belarus = 20,
315 Belgium = 21,
316 Belize = 22,
317 Benin = 23,
318 Bermuda = 24,
319 Bhutan = 25,
320 Bolivia = 26,
321 BosniaAndHerzegowina = 27,
322 Botswana = 28,
323 BouvetIsland = 29,
324 Brazil = 30,
325 BritishIndianOceanTerritory = 31,
326 BruneiDarussalam = 32,
327 Bulgaria = 33,
328 BurkinaFaso = 34,
329 Burundi = 35,
330 Cambodia = 36,
331 Cameroon = 37,
332 Canada = 38,
333 CapeVerde = 39,
334 CaymanIslands = 40,
335 CentralAfricanRepublic = 41,
336 Chad = 42,
337 Chile = 43,
338 China = 44,
339 ChristmasIsland = 45,
340 CocosIslands = 46,
341 Colombia = 47,
342 Comoros = 48,
343 DemocraticRepublicOfCongo = 49,
344 PeoplesRepublicOfCongo = 50,
345 CookIslands = 51,
346 CostaRica = 52,
347 IvoryCoast = 53,
348 Croatia = 54,
349 Cuba = 55,
350 Cyprus = 56,
351 CzechRepublic = 57,
352 Denmark = 58,
353 Djibouti = 59,
354 Dominica = 60,
355 DominicanRepublic = 61,
356 EastTimor = 62,
357 Ecuador = 63,
358 Egypt = 64,
359 ElSalvador = 65,
360 EquatorialGuinea = 66,
361 Eritrea = 67,
362 Estonia = 68,
363 Ethiopia = 69,
364 FalklandIslands = 70,
365 FaroeIslands = 71,
366 FijiCountry = 72,
367 Finland = 73,
368 France = 74,
369 MetropolitanFrance = 75,
370 FrenchGuiana = 76,
371 FrenchPolynesia = 77,
372 FrenchSouthernTerritories = 78,
373 Gabon = 79,
374 Gambia = 80,
375 Georgia = 81,
376 Germany = 82,
377 Ghana = 83,
378 Gibraltar = 84,
379 Greece = 85,
380 Greenland = 86,
381 Grenada = 87,
382 Guadeloupe = 88,
383 Guam = 89,
384 Guatemala = 90,
385 Guinea = 91,
386 GuineaBissau = 92,
387 Guyana = 93,
388 Haiti = 94,
389 HeardAndMcDonaldIslands = 95,
390 Honduras = 96,
391 HongKong = 97,
392 Hungary = 98,
393 Iceland = 99,
394 India = 100,
395 Indonesia = 101,
396 Iran = 102,
397 Iraq = 103,
398 Ireland = 104,
399 Israel = 105,
400 Italy = 106,
401 Jamaica = 107,
402 Japan = 108,
403 Jordan = 109,
404 Kazakhstan = 110,
405 Kenya = 111,
406 Kiribati = 112,
407 DemocraticRepublicOfKorea = 113,
408 RepublicOfKorea = 114,
409 Kuwait = 115,
410 Kyrgyzstan = 116,
411 Lao = 117,
412 Latvia = 118,
413 Lebanon = 119,
414 Lesotho = 120,
415 Liberia = 121,
416 LibyanArabJamahiriya = 122,
417 Liechtenstein = 123,
418 Lithuania = 124,
419 Luxembourg = 125,
420 Macau = 126,
421 Macedonia = 127,
422 Madagascar = 128,
423 Malawi = 129,
424 Malaysia = 130,
425 Maldives = 131,
426 Mali = 132,
427 Malta = 133,
428 MarshallIslands = 134,
429 Martinique = 135,
430 Mauritania = 136,
431 Mauritius = 137,
432 Mayotte = 138,
433 Mexico = 139,
434 Micronesia = 140,
435 Moldova = 141,
436 Monaco = 142,
437 Mongolia = 143,
438 Montserrat = 144,
439 Morocco = 145,
440 Mozambique = 146,
441 Myanmar = 147,
442 Namibia = 148,
443 NauruCountry = 149,
444 Nepal = 150,
445 Netherlands = 151,
446 NetherlandsAntilles = 152,
447 NewCaledonia = 153,
448 NewZealand = 154,
449 Nicaragua = 155,
450 Niger = 156,
451 Nigeria = 157,
452 Niue = 158,
453 NorfolkIsland = 159,
454 NorthernMarianaIslands = 160,
455 Norway = 161,
456 Oman = 162,
457 Pakistan = 163,
458 Palau = 164,
459 PalestinianTerritory = 165,
460 Panama = 166,
461 PapuaNewGuinea = 167,
462 Paraguay = 168,
463 Peru = 169,
464 Philippines = 170,
465 Pitcairn = 171,
466 Poland = 172,
467 Portugal = 173,
468 PuertoRico = 174,
469 Qatar = 175,
470 Reunion = 176,
471 Romania = 177,
472 RussianFederation = 178,
473 Rwanda = 179,
474 SaintKittsAndNevis = 180,
475 StLucia = 181,
476 StVincentAndTheGrenadines = 182,
477 Samoa = 183,
478 SanMarino = 184,
479 SaoTomeAndPrincipe = 185,
480 SaudiArabia = 186,
481 Senegal = 187,
482 Seychelles = 188,
483 SierraLeone = 189,
484 Singapore = 190,
485 Slovakia = 191,
486 Slovenia = 192,
487 SolomonIslands = 193,
488 Somalia = 194,
489 SouthAfrica = 195,
490 SouthGeorgiaAndTheSouthSandwichIslands = 196,
491 Spain = 197,
492 SriLanka = 198,
493 StHelena = 199,
494 StPierreAndMiquelon = 200,
495 Sudan = 201,
496 Suriname = 202,
497 SvalbardAndJanMayenIslands = 203,
498 Swaziland = 204,
499 Sweden = 205,
500 Switzerland = 206,
501 SyrianArabRepublic = 207,
502 Taiwan = 208,
503 Tajikistan = 209,
504 Tanzania = 210,
505 Thailand = 211,
506 Togo = 212,
507 Tokelau = 213,
508 TongaCountry = 214,
509 TrinidadAndTobago = 215,
510 Tunisia = 216,
511 Turkey = 217,
512 Turkmenistan = 218,
513 TurksAndCaicosIslands = 219,
514 Tuvalu = 220,
515 Uganda = 221,
516 Ukraine = 222,
517 UnitedArabEmirates = 223,
518 UnitedKingdom = 224,
519 UnitedStates = 225,
520 UnitedStatesMinorOutlyingIslands = 226,
521 Uruguay = 227,
522 Uzbekistan = 228,
523 Vanuatu = 229,
524 VaticanCityState = 230,
525 Venezuela = 231,
526 VietNam = 232,
527 BritishVirginIslands = 233,
528 USVirginIslands = 234,
529 WallisAndFutunaIslands = 235,
530 WesternSahara = 236,
531 Yemen = 237,
532 Yugoslavia = 238,
533 Zambia = 239,
534 Zimbabwe = 240,
535 SerbiaAndMontenegro = 241,
536 LastCountry = SerbiaAndMontenegro
537 };
538
539 enum MeasurementSystem { MetricSystem, ImperialSystem };
540
541 enum FormatType { LongFormat, ShortFormat, NarrowFormat };
542 enum NumberOption {
543 OmitGroupSeparator = 0x01,
544 RejectGroupSeparator = 0x02
545 };
546 Q_DECLARE_FLAGS(NumberOptions, NumberOption)
547
548 QLocale();
549 QLocale(const QString &name);
550 QLocale(Language language, Country country = AnyCountry);
551 QLocale(const QLocale &other);
552
553 QLocale &operator=(const QLocale &other);
554
555 Language language() const;
556 Country country() const;
557 QString name() const;
558
559 short toShort(const QString &s, bool *ok = 0, int base = 0) const;
560 ushort toUShort(const QString &s, bool *ok = 0, int base = 0) const;
561 int toInt(const QString &s, bool *ok = 0, int base = 0) const;
562 uint toUInt(const QString &s, bool *ok = 0, int base = 0) const;
563 qlonglong toLongLong(const QString &s, bool *ok = 0, int base = 0) const;
564 qlonglong toULongLong(const QString &s, bool *ok = 0, int base = 0) const;
565 float toFloat(const QString &s, bool *ok = 0) const;
566 double toDouble(const QString &s, bool *ok = 0) const;
567
568 QString toString(qlonglong i) const;
569 QString toString(qulonglong i) const;
570 inline QString toString(short i) const;
571 inline QString toString(ushort i) const;
572 inline QString toString(int i) const;
573 inline QString toString(uint i) const;
574 QString toString(double i, char f = 'g', int prec = 6) const;
575 inline QString toString(float i, char f = 'g', int prec = 6) const;
576 QString toString(const QDate &date, const QString &formatStr) const;
577 QString toString(const QDate &date, FormatType format = LongFormat) const;
578 QString toString(const QTime &time, const QString &formatStr) const;
579 QString toString(const QTime &time, FormatType format = LongFormat) const;
580 QString toString(const QDateTime &dateTime, FormatType format = LongFormat) const;
581 QString toString(const QDateTime &dateTime, const QString &format) const;
582
583 QString dateFormat(FormatType format = LongFormat) const;
584 QString timeFormat(FormatType format = LongFormat) const;
585 QString dateTimeFormat(FormatType format = LongFormat) const;
586#ifndef QT_NO_DATESTRING
587 QDate toDate(const QString &string, FormatType = LongFormat) const;
588 QTime toTime(const QString &string, FormatType = LongFormat) const;
589 QDateTime toDateTime(const QString &string, FormatType format = LongFormat) const;
590 QDate toDate(const QString &string, const QString &format) const;
591 QTime toTime(const QString &string, const QString &format) const;
592 QDateTime toDateTime(const QString &string, const QString &format) const;
593#endif
594
595 // ### Qt 5: We need to return QString from these function since
596 // unicode data contains several characters for these fields.
597 QChar decimalPoint() const;
598 QChar groupSeparator() const;
599 QChar percent() const;
600 QChar zeroDigit() const;
601 QChar negativeSign() const;
602 QChar positiveSign() const;
603 QChar exponential() const;
604
605 QString monthName(int, FormatType format = LongFormat) const;
606 QString standaloneMonthName(int, FormatType format = LongFormat) const;
607 QString dayName(int, FormatType format = LongFormat) const;
608 QString standaloneDayName(int, FormatType format = LongFormat) const;
609
610 QString amText() const;
611 QString pmText() const;
612
613 MeasurementSystem measurementSystem() const;
614
615 inline bool operator==(const QLocale &other) const;
616 inline bool operator!=(const QLocale &other) const;
617
618 static QString languageToString(Language language);
619 static QString countryToString(Country country);
620 static void setDefault(const QLocale &locale);
621
622 static QLocale c() { return QLocale(C); }
623 static QLocale system();
624
625 static QList<Country> countriesForLanguage(Language lang);
626
627 void setNumberOptions(NumberOptions options);
628 NumberOptions numberOptions() const;
629
630//private: // this should be private, but can't be
631 struct Data {
632 quint16 index;
633 quint16 numberOptions;
634 }
635#if (defined(__arm__) || defined(__ARMEL__))
636 Q_PACKED
637#endif
638 ;
639private:
640 friend struct QLocalePrivate;
641 // ### We now use this field to pack an index into locale_data and NumberOptions.
642 // ### Qt 5: change to a QLocaleData *d; uint numberOptions.
643 union {
644 void *v;
645 Data p;
646 };
647 const QLocalePrivate *d() const;
648};
649Q_DECLARE_TYPEINFO(QLocale, Q_MOVABLE_TYPE);
650Q_DECLARE_OPERATORS_FOR_FLAGS(QLocale::NumberOptions)
651
652inline QString QLocale::toString(short i) const
653 { return toString(qlonglong(i)); }
654inline QString QLocale::toString(ushort i) const
655 { return toString(qulonglong(i)); }
656inline QString QLocale::toString(int i) const
657 { return toString(qlonglong(i)); }
658inline QString QLocale::toString(uint i) const
659 { return toString(qulonglong(i)); }
660inline QString QLocale::toString(float i, char f, int prec) const
661 { return toString(double(i), f, prec); }
662inline bool QLocale::operator==(const QLocale &other) const
663 { return d() == other.d() && numberOptions() == other.numberOptions(); }
664inline bool QLocale::operator!=(const QLocale &other) const
665 { return d() != other.d() || numberOptions() != other.numberOptions(); }
666
667#ifndef QT_NO_DATASTREAM
668Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLocale &);
669Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLocale &);
670#endif
671
672QT_END_NAMESPACE
673
674QT_END_HEADER
675
676#endif // QLOCALE_H
Note: See TracBrowser for help on using the repository browser.