|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QLocale
public class QLocale
The QLocale class converts between numbers and their string representations in various languages.
QLocale is initialized with a language/country pair in its constructor and offers number-to-string and string-to-number conversion functions similar to those in QString.
Example:
QLocale egyptian(QLocale::Arabic, QLocale::Egypt); QString s1 = egyptian.toString(1.571429E+07, 'e'); QString s2 = egyptian.toString(10); double d = egyptian.toDouble(s1); int i = egyptian.toInt(s2);
QLocale supports the concept of a default locale, which is determined from the system's locale settings at application startup. The default locale can be changed by calling the static member setDefault. Setting the default locale has the following effects:
The following example illustrates how to use QLocale directly:
QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel)); QLocale hebrew; // Constructs a default QLocale QString s1 = hebrew.toString(15714.3, 'e'); bool ok; double d; QLocale::setDefault(QLocale::C); d = QString("1234,56").toDouble(&ok); // ok == false d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 QLocale::setDefault(QLocale::German); d = QString("1234,56").toDouble(&ok); // ok == true, d == 1234.56 d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); str = QString("%1 %L2 %L3") .arg(12345).arg(12345).arg(12345, 0, 16); // str == "12345 12,345 3039"
When a language/country pair is specified in the constructor, one of three things can happen:
The "C" locale is identical to English/UnitedStates.
Use language and country to determine the actual language and country values used.
An alternative method for constructing a QLocale object is by specifying the locale name.
QLocale korean("ko"); QLocale swiss("de_CH");
This constructor converts the locale name to a language/country pair; it does not use the system locale database.
The double-to-string and string-to-double conversion functions are covered by the following licenses:
Copyright (c) 1991 by AT&T.
Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software.
THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
This product includes software developed by the University of California, Berkeley and its contributors.
Nested Class Summary | |
---|---|
static class |
QLocale.Country
This enumerated type is used to specify a country. |
static class |
QLocale.FormatType
This enum describes the types of format that can be used when converting QDate and QTime objects to strings. |
static class |
QLocale.Language
This enumerated type is used to specify a language. |
static class |
QLocale.NumberOption
This enum defines a set of options for number-to-string and string-to-number conversions. |
static class |
QLocale.NumberOptions
This QFlag class provides flags for the int enum. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Constructor Summary | |
---|---|
QLocale()
Constructs a QLocale object initialized with the default locale. |
|
QLocale(QLocale.Language language)
Equivalent to QLocale(language, AnyCountry). |
|
QLocale(QLocale.Language language,
QLocale.Country country)
Constructs a QLocale object with the specified language and country. |
|
QLocale(QLocale other)
Constructs a QLocale object as a copy of other. |
|
QLocale(java.lang.String name)
Constructs a QLocale object with the specified name, which has the format "language[_country][.codeset][@modifier]" or "C", where: language is a lowercase, two-letter, ISO 639 language code, territory is an uppercase, two-letter, ISO 3166 country code, and codeset and modifier are ignored. |
Method Summary | |
---|---|
static QLocale |
c()
Returns a QLocale object initialized to the "C" locale. |
static java.util.List<QLocale.Country> |
countriesForLanguage(QLocale.Language lang)
Returns the list of countries that have entires for lang in Qt's locale database. |
QLocale.Country |
country()
Returns the country of this locale. |
static java.lang.String |
countryToString(QLocale.Country country)
Returns a QString containing the name of country. |
java.lang.String |
dateFormat()
Equivalent to dateFormat(LongFormat). |
java.lang.String |
dateFormat(QLocale.FormatType format)
Returns the date format used for the current locale. |
java.lang.String |
dayName(int arg__1)
Equivalent to dayName(arg__1, LongFormat). |
java.lang.String |
dayName(int arg__1,
QLocale.FormatType format)
Returns the localized name of arg__1, in the format specified by format. |
char |
decimalPoint()
Returns the decimal point character of this locale. |
boolean |
equals(java.lang.Object other)
|
char |
exponential()
Returns the exponential character of this locale. |
static QLocale |
fromNativePointer(QNativePointer nativePointer)
This function returns the QLocale instance pointed to by nativePointer |
char |
groupSeparator()
Returns the group separator character of this locale. |
QLocale.Language |
language()
Returns the language of this locale. |
static java.lang.String |
languageToString(QLocale.Language language)
Returns a QString containing the name of language. |
java.lang.String |
monthName(int arg__1)
Equivalent to monthName(arg__1, LongFormat). |
java.lang.String |
monthName(int arg__1,
QLocale.FormatType format)
Returns the localized name of arg__1, in the format specified by format. |
java.lang.String |
name()
Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two-letter ISO 3166 country code. |
static QNativePointer |
nativePointerArray(QLocale[] array)
This function returns a QNativePointer that is pointing to the specified QLocale array. |
char |
negativeSign()
Returns the negative sign character of this locale. |
QLocale.NumberOptions |
numberOptions()
Returns the options related to number conversions for this QLocale instance. |
char |
percent()
Returns the percent character of this locale. |
void |
readFrom(QDataStream arg__1)
Reads a QLocale from arg__1. |
static void |
setDefault(QLocale locale)
Sets the global default locale to locale. |
void |
setNumberOptions(QLocale.NumberOption... options)
Sets the options related to number conversions for this QLocale instance. |
void |
setNumberOptions(QLocale.NumberOptions options)
Sets the options related to number conversions for this QLocale instance. |
static QLocale |
system()
Returns a QLocale object initialized to the system locale. |
java.lang.String |
timeFormat()
Equivalent to timeFormat(LongFormat). |
java.lang.String |
timeFormat(QLocale.FormatType format)
Returns the time format used for the current locale. |
char |
toChar(java.lang.String s)
Returns the char, which must be written as a number between 0 and 255, represented by the localized string s. |
char |
toChar(java.lang.String s,
int base)
Returns the char, which must be written as a number between 0 and 255, represented by the localized string s, using base base. |
double |
toDouble(java.lang.String s)
Returns the double represented by the localized string s, or 0.0 if the conversion failed. |
float |
toFloat(java.lang.String s)
Returns the float represented by the localized string s, or 0.0 if the conversion failed. |
int |
toInt(java.lang.String s)
Returns the int represented by the localized string s, using base 10. |
int |
toInt(java.lang.String s,
int base)
Returns the int represented by the localized string s, using base base. |
long |
toLong(java.lang.String s)
Returns the long represented by the localized string s, using base 10. |
long |
toLong(java.lang.String s,
int base)
Returns the long represented by the localized string s, using base base. |
short |
toShort(java.lang.String s)
Returns the short represented by the localized string s. |
short |
toShort(java.lang.String s,
int base)
Returns the short represented by the localized string s, using base base. |
java.lang.String |
toString(char i)
Returns a string representation of i. |
java.lang.String |
toString(double i)
Equivalent to toString(i, 'g', 6). |
java.lang.String |
toString(double i,
byte f)
Equivalent to toString(i, f, 6). |
java.lang.String |
toString(double i,
byte f,
int prec)
f and prec have the same meaning as in QString::number(double, char, int). |
java.lang.String |
toString(float i)
Equivalent to toString(i, 'g', 6). |
java.lang.String |
toString(float i,
byte f)
Equivalent to toString(i, f, 6). |
java.lang.String |
toString(float i,
byte f,
int prec)
f and prec have the same meaning as in QString::number(double, char, int). |
java.lang.String |
toString(int i)
Returns a string representation of i. |
java.lang.String |
toString(long i)
Returns a localized string representation of i. |
java.lang.String |
toString(QDate date)
Equivalent to toString(date, LongFormat). |
java.lang.String |
toString(QDate date,
QLocale.FormatType format)
Returns a localized string representation of the given date according to the specified format. |
java.lang.String |
toString(QDate date,
java.lang.String formatStr)
Returns a localized string representation of the given date in the specified formatStr. |
java.lang.String |
toString(QTime time)
Equivalent to toString(time, LongFormat). |
java.lang.String |
toString(QTime time,
QLocale.FormatType format)
Returns a localized string representation of the given time in the specified format. |
java.lang.String |
toString(QTime time,
java.lang.String formatStr)
Returns a localized string representation of the given time according to the specified formatStr. |
void |
writeTo(QDataStream arg__1)
Writes thisQLocale to arg__1. |
char |
zeroDigit()
Returns the zero digit character of this locale. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QLocale()
Constructs a QLocale object initialized with the default locale. If no default locale was set using setDefaultLocale(), this locale will be the same as the one returned by system.
public QLocale(QLocale.Language language)
Equivalent to QLocale(language, AnyCountry).
public QLocale(QLocale.Language language, QLocale.Country country)
Constructs a QLocale object with the specified language and country.
The language and country that are actually used can be queried using language and country.
public QLocale(java.lang.String name)
Constructs a QLocale object with the specified name, which has the format "language[_country][.codeset][@modifier]" or "C", where:
If the string violates the locale format, or language is not a valid ISO 369 code, the "C" locale is used instead. If country is not present, or is not a valid ISO 3166 code, the most appropriate country is chosen for the specified language.
The language and country codes are converted to their respective Language and Country enums. After this conversion is performed the constructor behaves exactly like QLocale(Country, Language).
This constructor is much slower than QLocale(Country, Language).
public QLocale(QLocale other)
Constructs a QLocale object as a copy of other.
Method Detail |
---|
public final QLocale.Country country()
Returns the country of this locale.
public final java.lang.String dateFormat()
Equivalent to dateFormat(LongFormat).
public final java.lang.String dateFormat(QLocale.FormatType format)
Returns the date format used for the current locale.
If format is ShortFormat the format will be a short version. Otherwise it uses a longer version.
public final java.lang.String dayName(int arg__1)
Equivalent to dayName(arg__1, LongFormat).
public final java.lang.String dayName(int arg__1, QLocale.FormatType format)
Returns the localized name of arg__1, in the format specified by format.
public final char decimalPoint()
Returns the decimal point character of this locale.
public final char exponential()
Returns the exponential character of this locale.
public final char groupSeparator()
Returns the group separator character of this locale.
public final QLocale.Language language()
Returns the language of this locale.
public final java.lang.String monthName(int arg__1)
Equivalent to monthName(arg__1, LongFormat).
public final java.lang.String monthName(int arg__1, QLocale.FormatType format)
Returns the localized name of arg__1, in the format specified by format.
public final java.lang.String name()
Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two-letter ISO 3166 country code.
public final char negativeSign()
Returns the negative sign character of this locale.
public final QLocale.NumberOptions numberOptions()
Returns the options related to number conversions for this QLocale instance.
By default, no options are set for the standard locales.
public final void writeTo(QDataStream arg__1)
public final void readFrom(QDataStream arg__1)
public final char percent()
Returns the percent character of this locale.
public final void setNumberOptions(QLocale.NumberOption... options)
Sets the options related to number conversions for this QLocale instance.
public final void setNumberOptions(QLocale.NumberOptions options)
Sets the options related to number conversions for this QLocale instance.
public final java.lang.String timeFormat()
Equivalent to timeFormat(LongFormat).
public final java.lang.String timeFormat(QLocale.FormatType format)
Returns the time format used for the current locale.
If format is ShortFormat the format will be a short version. Otherwise it uses a longer version.
public final java.lang.String toString(int i)
public final java.lang.String toString(long i)
Returns a localized string representation of i.
public final java.lang.String toString(QTime time, java.lang.String formatStr)
Returns a localized string representation of the given time according to the specified formatStr. If formatStr is an empty string, an empty string is returned.
public final java.lang.String toString(QDate date, java.lang.String formatStr)
Returns a localized string representation of the given date in the specified formatStr. If formatStr is an empty string, an empty string is returned.
public final java.lang.String toString(float i, byte f)
Equivalent to toString(i, f, 6).
public final java.lang.String toString(float i)
Equivalent to toString(i, 'g', 6).
public final java.lang.String toString(float i, byte f, int prec)
f and prec have the same meaning as in QString::number(double, char, int).
public final java.lang.String toString(char i)
public final java.lang.String toString(QDate date)
Equivalent to toString(date, LongFormat).
public final java.lang.String toString(QDate date, QLocale.FormatType format)
Returns a localized string representation of the given date according to the specified format.
public final java.lang.String toString(QTime time)
Equivalent to toString(time, LongFormat).
public final java.lang.String toString(QTime time, QLocale.FormatType format)
Returns a localized string representation of the given time in the specified format.
public final java.lang.String toString(double i, byte f)
Equivalent to toString(i, f, 6).
public final java.lang.String toString(double i)
Equivalent to toString(i, 'g', 6).
public final java.lang.String toString(double i, byte f, int prec)
f and prec have the same meaning as in QString::number(double, char, int).
public final char zeroDigit()
Returns the zero digit character of this locale.
public static QLocale c()
Returns a QLocale object initialized to the "C" locale.
public static java.util.List<QLocale.Country> countriesForLanguage(QLocale.Language lang)
Returns the list of countries that have entires for lang in Qt's locale database. If the result is an empty list, then lang is not represented in Qt's locale database.
public static java.lang.String countryToString(QLocale.Country country)
Returns a QString containing the name of country.
public static java.lang.String languageToString(QLocale.Language language)
Returns a QString containing the name of language.
public static void setDefault(QLocale locale)
Sets the global default locale to locale. These values are used when a QLocale object is constructed with no arguments. If this function is not called, the system's locale is used.
Warning: In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.
public static QLocale system()
Returns a QLocale object initialized to the system locale.
On Windows and Mac, this locale will use the decimal/grouping characters and date/time formats specified in the system configuration panel.
public static QLocale fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public static QNativePointer nativePointerArray(QLocale[] array)
array
- the array that the returned pointer will point to.
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public final double toDouble(java.lang.String s)
public final float toFloat(java.lang.String s)
public final int toInt(java.lang.String s, int base)
public final int toInt(java.lang.String s)
public final long toLong(java.lang.String s, int base)
public final long toLong(java.lang.String s)
public final short toShort(java.lang.String s, int base)
public final short toShort(java.lang.String s)
public final char toChar(java.lang.String s, int base)
public final char toChar(java.lang.String s)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |