com.trolltech.qt.core
Class QLocale

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QLocale
All Implemented Interfaces:
QtJambiInterface

public class QLocale
extends QtJambiObject

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.

See Also:
QString::arg, QString::toInt, QString::toDouble

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.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:
 
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

QLocale

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.

See Also:
setDefault

QLocale

public QLocale(QLocale.Language language)

Equivalent to QLocale(language, AnyCountry).


QLocale

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.

See Also:
setDefault, language, country

QLocale

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).

See Also:
name

QLocale

public QLocale(QLocale other)

Constructs a QLocale object as a copy of other.

Method Detail

country

public final QLocale.Country country()

Returns the country of this locale.

See Also:
language, countryToString, name

dateFormat

public final java.lang.String dateFormat()

Equivalent to dateFormat(LongFormat).


dateFormat

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.

See Also:
QDate::toString, QDate::fromString

dayName

public final java.lang.String dayName(int arg__1)

Equivalent to dayName(arg__1, LongFormat).


dayName

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.

See Also:
monthName

decimalPoint

public final char decimalPoint()

Returns the decimal point character of this locale.


exponential

public final char exponential()

Returns the exponential character of this locale.


groupSeparator

public final char groupSeparator()

Returns the group separator character of this locale.


language

public final QLocale.Language language()

Returns the language of this locale.

See Also:
country, languageToString, name

monthName

public final java.lang.String monthName(int arg__1)

Equivalent to monthName(arg__1, LongFormat).


monthName

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.

See Also:
dayName

name

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.

See Also:
language, country

negativeSign

public final char negativeSign()

Returns the negative sign character of this locale.


numberOptions

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.

See Also:
setNumberOptions

writeTo

public final void writeTo(QDataStream arg__1)
Writes thisQLocale to arg__1.


readFrom

public final void readFrom(QDataStream arg__1)
Reads a QLocale from arg__1.


percent

public final char percent()

Returns the percent character of this locale.


setNumberOptions

public final void setNumberOptions(QLocale.NumberOption... options)

Sets the options related to number conversions for this QLocale instance.

See Also:
numberOptions

setNumberOptions

public final void setNumberOptions(QLocale.NumberOptions options)

Sets the options related to number conversions for this QLocale instance.

See Also:
numberOptions

timeFormat

public final java.lang.String timeFormat()

Equivalent to timeFormat(LongFormat).


timeFormat

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.

See Also:
QTime::toString, QTime::fromString

toString

public final java.lang.String toString(int i)
Returns a string representation of i.


toString

public final java.lang.String toString(long i)

Returns a localized string representation of i.

See Also:
toLongLong

toString

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.


toString

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.


toString

public final java.lang.String toString(float i,
                                       byte f)

Equivalent to toString(i, f, 6).


toString

public final java.lang.String toString(float i)

Equivalent to toString(i, 'g', 6).


toString

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).

See Also:
toDouble

toString

public final java.lang.String toString(char i)
Returns a string representation of i.


toString

public final java.lang.String toString(QDate date)

Equivalent to toString(date, LongFormat).


toString

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.


toString

public final java.lang.String toString(QTime time)

Equivalent to toString(time, LongFormat).


toString

public final java.lang.String toString(QTime time,
                                       QLocale.FormatType format)

Returns a localized string representation of the given time in the specified format.


toString

public final java.lang.String toString(double i,
                                       byte f)

Equivalent to toString(i, f, 6).


toString

public final java.lang.String toString(double i)

Equivalent to toString(i, 'g', 6).


toString

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).

See Also:
toDouble

zeroDigit

public final char zeroDigit()

Returns the zero digit character of this locale.


c

public static QLocale c()

Returns a QLocale object initialized to the "C" locale.

See Also:
system

countriesForLanguage

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.


countryToString

public static java.lang.String countryToString(QLocale.Country country)

Returns a QString containing the name of country.

See Also:
country, name

languageToString

public static java.lang.String languageToString(QLocale.Language language)

Returns a QString containing the name of language.

See Also:
countryToString, name

setDefault

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.

See Also:
system, c

system

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.

See Also:
QTextCodec::locale, c

fromNativePointer

public static QLocale fromNativePointer(QNativePointer nativePointer)
This function returns the QLocale instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

nativePointerArray

public static QNativePointer nativePointerArray(QLocale[] array)
This function returns a QNativePointer that is pointing to the specified QLocale array.

Parameters:
array - the array that the returned pointer will point to.
Returns:
a QNativePointer that is pointing to the specified array.

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object

toDouble

public final double toDouble(java.lang.String s)
Returns the double represented by the localized string s, or 0.0 if the conversion failed. This function ignores leading and trailing whitespace.


toFloat

public final float toFloat(java.lang.String s)
Returns the float represented by the localized string s, or 0.0 if the conversion failed. This function ignores leading and trailing whitespace.


toInt

public final int toInt(java.lang.String s,
                       int base)
Returns the int represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. This function ignores leading and trailing whitespace.


toInt

public final int toInt(java.lang.String s)
Returns the int represented by the localized string s, using base 10.


toLong

public final long toLong(java.lang.String s,
                         int base)
Returns the long represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. This function ignores leading and trailing whitespace.


toLong

public final long toLong(java.lang.String s)
Returns the long represented by the localized string s, using base 10.


toShort

public final short toShort(java.lang.String s,
                           int base)
Returns the short represented by the localized string s, using base base. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. This function ignores leading and trailing whitespace.


toShort

public final short toShort(java.lang.String s)
Returns the short represented by the localized string s. The string is interpreted as a decimal number.


toChar

public final 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. If base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. This function ignores leading and trailing whitespace.


toChar

public final 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. The number is assumed to be decimal.