Qt 4.8
Public Functions | Private Types | Private Functions | Static Private Functions | Properties | List of all members
QSystemLocalePrivate Struct Reference

Public Functions

QVariant amText ()
 
QVariant currencySymbol (QLocale::CurrencySymbolFormat)
 
QVariant dateFormat (QLocale::FormatType)
 
QVariant dateTimeFormat (QLocale::FormatType)
 
QVariant dayName (int, QLocale::FormatType)
 
QChar decimalPoint ()
 
QVariant firstDayOfWeek ()
 
QChar groupSeparator ()
 
QVariant measurementSystem ()
 
QVariant monthName (int, QLocale::FormatType)
 
QVariant nativeCountryName ()
 
QVariant nativeLanguageName ()
 
QChar negativeSign ()
 
QVariant pmText ()
 
QChar positiveSign ()
 
 QSystemLocalePrivate ()
 
QVariant timeFormat (QLocale::FormatType)
 
QVariant toCurrencyString (const QSystemLocale::CurrencyToStringArgument &)
 
QVariant toString (const QDate &, QLocale::FormatType)
 
QVariant toString (const QTime &, QLocale::FormatType)
 
QVariant toString (const QDateTime &, QLocale::FormatType)
 
QVariant uiLanguages ()
 
void update ()
 
QChar zeroDigit ()
 

Private Types

enum  SubstitutionType { SUnknown, SContext, SAlways, SNever }
 

Private Functions

QString getLocaleInfo (LCTYPE type, int maxlen=0)
 
int getLocaleInfo_int (LCTYPE type, int maxlen=0)
 
QChar getLocaleInfo_qchar (LCTYPE type)
 
QStringsubstituteDigits (QString &string)
 
SubstitutionType substitution ()
 

Static Private Functions

static QString winToQtFormat (const QString &sys_fmt)
 

Properties

QByteArray langEnvVar
 
LCID lcid
 
SubstitutionType substitutionType
 
QChar zero
 

Detailed Description

Definition at line 86 of file qlocale_win.cpp.

Enumerations

◆ SubstitutionType

Enumerator
SUnknown 
SContext 
SAlways 
SNever 

Definition at line 118 of file qlocale_win.cpp.

Constructors and Destructors

◆ QSystemLocalePrivate()

QSystemLocalePrivate::QSystemLocalePrivate ( )

Definition at line 142 of file qlocale_win.cpp.

144 {
145  langEnvVar = qgetenv("LANG");
146  lcid = GetUserDefaultLCID();
147 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
SubstitutionType substitutionType

Functions

◆ amText()

QVariant QSystemLocalePrivate::amText ( )

Definition at line 387 of file qlocale_win.cpp.

Referenced by winToQtFormat().

388 {
389  wchar_t output[15]; // maximum length including terminating zero character for Win2003+
390 
391  if (GetLocaleInfo(lcid, LOCALE_S1159, output, 15)) {
392  return QString::fromWCharArray(output);
393  }
394 
395  return QVariant();
396 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019

◆ currencySymbol()

QVariant QSystemLocalePrivate::currencySymbol ( QLocale::CurrencySymbolFormat  format)

Definition at line 419 of file qlocale_win.cpp.

Referenced by winToQtFormat().

420 {
421  wchar_t buf[13];
422  switch (format) {
424  if (GetLocaleInfo(lcid, LOCALE_SCURRENCY, buf, 13))
425  return QString::fromWCharArray(buf);
426  break;
428  if (GetLocaleInfo(lcid, LOCALE_SINTLSYMBOL, buf, 9))
429  return QString::fromWCharArray(buf);
430  break;
433  if (!GetLocaleInfo(lcid, LOCALE_SNATIVECURRNAME, buf.data(), buf.size())) {
434  if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
435  break;
436  buf.resize(255); // should be large enough, right?
437  if (!GetLocaleInfo(lcid, LOCALE_SNATIVECURRNAME, buf.data(), buf.size()))
438  break;
439  }
440  return QString::fromWCharArray(buf.data());
441  }
442  default:
443  break;
444  }
445  return QVariant();
446 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019

◆ dateFormat()

QVariant QSystemLocalePrivate::dateFormat ( QLocale::FormatType  type)

Definition at line 247 of file qlocale_win.cpp.

Referenced by dateTimeFormat(), and winToQtFormat().

248 {
249  switch (type) {
251  return winToQtFormat(getLocaleInfo(LOCALE_SSHORTDATE));
252  case QLocale::LongFormat:
253  return winToQtFormat(getLocaleInfo(LOCALE_SLONGDATE));
255  break;
256  }
257  return QVariant();
258 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int type
Definition: qmetatype.cpp:239
QString getLocaleInfo(LCTYPE type, int maxlen=0)
static QString winToQtFormat(const QString &sys_fmt)

◆ dateTimeFormat()

QVariant QSystemLocalePrivate::dateTimeFormat ( QLocale::FormatType  type)

Definition at line 273 of file qlocale_win.cpp.

Referenced by winToQtFormat().

274 {
276 }
int type
Definition: qmetatype.cpp:239
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVariant dateFormat(QLocale::FormatType)
QVariant timeFormat(QLocale::FormatType)
QVariant toString(const QDate &, QLocale::FormatType)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ dayName()

QVariant QSystemLocalePrivate::dayName ( int  day,
QLocale::FormatType  type 
)

Definition at line 278 of file qlocale_win.cpp.

Referenced by winToQtFormat().

279 {
280  static const LCTYPE short_day_map[]
281  = { LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2,
282  LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4, LOCALE_SABBREVDAYNAME5,
283  LOCALE_SABBREVDAYNAME6, LOCALE_SABBREVDAYNAME7 };
284 
285  static const LCTYPE long_day_map[]
286  = { LOCALE_SDAYNAME1, LOCALE_SDAYNAME2,
287  LOCALE_SDAYNAME3, LOCALE_SDAYNAME4, LOCALE_SDAYNAME5,
288  LOCALE_SDAYNAME6, LOCALE_SDAYNAME7 };
289 
290  static const LCTYPE narrow_day_map[]
295 
296  day -= 1;
297 
298  if (type == QLocale::LongFormat)
299  return getLocaleInfo(long_day_map[day]);
301  return getLocaleInfo(narrow_day_map[day]);
302  return getLocaleInfo(short_day_map[day]);
303 }
int type
Definition: qmetatype.cpp:239
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
#define LOCALE_SSHORTESTDAYNAME7
Definition: qlocale_win.cpp:77
#define LOCALE_SSHORTESTDAYNAME5
Definition: qlocale_win.cpp:75
QString getLocaleInfo(LCTYPE type, int maxlen=0)
#define LOCALE_SSHORTESTDAYNAME1
Definition: qlocale_win.cpp:71
#define LOCALE_SSHORTESTDAYNAME4
Definition: qlocale_win.cpp:74
#define LOCALE_SSHORTESTDAYNAME2
Definition: qlocale_win.cpp:72
#define LOCALE_SSHORTESTDAYNAME3
Definition: qlocale_win.cpp:73
#define LOCALE_SSHORTESTDAYNAME6
Definition: qlocale_win.cpp:76

◆ decimalPoint()

QChar QSystemLocalePrivate::decimalPoint ( )

Definition at line 227 of file qlocale_win.cpp.

Referenced by winToQtFormat().

228 {
229  return getLocaleInfo_qchar(LOCALE_SDECIMAL);
230 }
QChar getLocaleInfo_qchar(LCTYPE type)

◆ firstDayOfWeek()

QVariant QSystemLocalePrivate::firstDayOfWeek ( )

Definition at line 409 of file qlocale_win.cpp.

Referenced by winToQtFormat().

410 {
411  wchar_t output[4]; // maximum length including terminating zero character for Win2003+
412 
413  if (GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, output, 4))
414  return QString::fromWCharArray(output).toUInt()+1;
415 
416  return 1;
417 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
Definition: qstring.cpp:6120

◆ getLocaleInfo()

QString QSystemLocalePrivate::getLocaleInfo ( LCTYPE  type,
int  maxlen = 0 
)
private

Definition at line 149 of file qlocale_win.cpp.

Referenced by dateFormat(), dayName(), getLocaleInfo_int(), getLocaleInfo_qchar(), monthName(), nativeCountryName(), nativeLanguageName(), timeFormat(), and toCurrencyString().

150 {
151  QVarLengthArray<wchar_t, 64> buf(maxlen ? maxlen : 64);
152  if (!GetLocaleInfo(lcid, type, buf.data(), buf.size()))
153  return QString();
154  if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
155  int cnt = GetLocaleInfo(lcid, type, 0, 0);
156  if (cnt == 0)
157  return QString();
158  buf.resize(cnt);
159  if (!GetLocaleInfo(lcid, type, buf.data(), buf.size()))
160  return QString();
161  }
162  return QString::fromWCharArray(buf.data());
163 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
int type
Definition: qmetatype.cpp:239
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ getLocaleInfo_int()

int QSystemLocalePrivate::getLocaleInfo_int ( LCTYPE  type,
int  maxlen = 0 
)
private

Definition at line 165 of file qlocale_win.cpp.

Referenced by toCurrencyString().

166 {
167  QString str = getLocaleInfo(type, maxlen);
168  bool ok = false;
169  int v = str.toInt(&ok);
170  return ok ? v : 0;
171 }
int type
Definition: qmetatype.cpp:239
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString getLocaleInfo(LCTYPE type, int maxlen=0)

◆ getLocaleInfo_qchar()

QChar QSystemLocalePrivate::getLocaleInfo_qchar ( LCTYPE  type)
private

Definition at line 173 of file qlocale_win.cpp.

Referenced by decimalPoint(), groupSeparator(), negativeSign(), positiveSign(), and zeroDigit().

174 {
175  QString str = getLocaleInfo(type);
176  return str.isEmpty() ? QChar() : str.at(0);
177 }
int type
Definition: qmetatype.cpp:239
#define at(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString getLocaleInfo(LCTYPE type, int maxlen=0)

◆ groupSeparator()

QChar QSystemLocalePrivate::groupSeparator ( )

Definition at line 232 of file qlocale_win.cpp.

Referenced by winToQtFormat().

233 {
234  return getLocaleInfo_qchar(LOCALE_STHOUSAND);
235 }
QChar getLocaleInfo_qchar(LCTYPE type)

◆ measurementSystem()

QVariant QSystemLocalePrivate::measurementSystem ( )

Definition at line 373 of file qlocale_win.cpp.

Referenced by winToQtFormat().

374 {
375  wchar_t output[2];
376 
377  if (GetLocaleInfo(lcid, LOCALE_IMEASURE, output, 2)) {
378  QString iMeasure = QString::fromWCharArray(output);
379  if (iMeasure == QLatin1String("1")) {
381  }
382  }
383 
384  return QLocale::MetricSystem;
385 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ monthName()

QVariant QSystemLocalePrivate::monthName ( int  month,
QLocale::FormatType  type 
)

Definition at line 305 of file qlocale_win.cpp.

Referenced by winToQtFormat().

306 {
307  static const LCTYPE short_month_map[]
308  = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2, LOCALE_SABBREVMONTHNAME3,
309  LOCALE_SABBREVMONTHNAME4, LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
310  LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8, LOCALE_SABBREVMONTHNAME9,
311  LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
312 
313  static const LCTYPE long_month_map[]
314  = { LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,
315  LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,
316  LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
317  LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12 };
318 
319  month -= 1;
320  if (month < 0 || month > 11)
321  return QString();
322 
323  LCTYPE lctype = (type == QLocale::ShortFormat || type == QLocale::NarrowFormat)
324  ? short_month_map[month] : long_month_map[month];
325  return getLocaleInfo(lctype);
326 }
int type
Definition: qmetatype.cpp:239
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString getLocaleInfo(LCTYPE type, int maxlen=0)

◆ nativeCountryName()

QVariant QSystemLocalePrivate::nativeCountryName ( )

Definition at line 577 of file qlocale_win.cpp.

Referenced by winToQtFormat().

578 {
580  return getLocaleInfo(LOCALE_SNATIVECTRYNAME);
582 }
#define LOCALE_SNATIVECOUNTRYNAME
Definition: qlocale_win.cpp:83
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
QString getLocaleInfo(LCTYPE type, int maxlen=0)

◆ nativeLanguageName()

QVariant QSystemLocalePrivate::nativeLanguageName ( )

Definition at line 570 of file qlocale_win.cpp.

Referenced by winToQtFormat().

571 {
573  return getLocaleInfo(LOCALE_SNATIVELANGNAME);
575 }
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
#define LOCALE_SNATIVELANGUAGENAME
Definition: qlocale_win.cpp:80
QString getLocaleInfo(LCTYPE type, int maxlen=0)

◆ negativeSign()

QChar QSystemLocalePrivate::negativeSign ( )

Definition at line 237 of file qlocale_win.cpp.

Referenced by winToQtFormat().

238 {
239  return getLocaleInfo_qchar(LOCALE_SNEGATIVESIGN);
240 }
QChar getLocaleInfo_qchar(LCTYPE type)

◆ pmText()

QVariant QSystemLocalePrivate::pmText ( )

Definition at line 398 of file qlocale_win.cpp.

Referenced by winToQtFormat().

399 {
400  wchar_t output[15]; // maximum length including terminating zero character for Win2003+
401 
402  if (GetLocaleInfo(lcid, LOCALE_S2359, output, 15)) {
403  return QString::fromWCharArray(output);
404  }
405 
406  return QVariant();
407 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019

◆ positiveSign()

QChar QSystemLocalePrivate::positiveSign ( )

Definition at line 242 of file qlocale_win.cpp.

Referenced by winToQtFormat().

243 {
244  return getLocaleInfo_qchar(LOCALE_SPOSITIVESIGN);
245 }
QChar getLocaleInfo_qchar(LCTYPE type)

◆ substituteDigits()

QString & QSystemLocalePrivate::substituteDigits ( QString string)
private

Definition at line 209 of file qlocale_win.cpp.

Referenced by toCurrencyString(), and toString().

210 {
212  ushort *qch = (ushort *)string.data();
213  for (ushort *end = qch + string.size(); qch != end; ++qch) {
214  if (*qch >= '0' && *qch <= '9')
215  *qch = zero + (*qch - '0');
216  }
217  return string;
218 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static const char * data(const QByteArray &arr)
unsigned short ushort
Definition: qglobal.h:995
static const KeyPair *const end

◆ substitution()

QSystemLocalePrivate::SubstitutionType QSystemLocalePrivate::substitution ( )
private

Definition at line 179 of file qlocale_win.cpp.

Referenced by toCurrencyString(), and toString().

180 {
181  if (substitutionType == SUnknown) {
182  wchar_t buf[8];
183  if (!GetLocaleInfo(lcid, LOCALE_IDIGITSUBSTITUTION, buf, 8)) {
185  return substitutionType;
186  }
187  if (buf[0] == '1')
189  else if (buf[0] == '0')
191  else if (buf[0] == '2')
193  else {
194  wchar_t digits[11];
195  if (!GetLocaleInfo(lcid, LOCALE_SNATIVEDIGITS, digits, 11)) {
197  return substitutionType;
198  }
199  const wchar_t zero = digits[0];
200  if (buf[0] == zero + 2)
202  else
204  }
205  }
206  return substitutionType;
207 }
SubstitutionType substitutionType

◆ timeFormat()

QVariant QSystemLocalePrivate::timeFormat ( QLocale::FormatType  type)

Definition at line 260 of file qlocale_win.cpp.

Referenced by dateTimeFormat(), and winToQtFormat().

261 {
262  switch (type) {
264  return winToQtFormat(getLocaleInfo(LOCALE_STIMEFORMAT)); //###
265  case QLocale::LongFormat:
266  return winToQtFormat(getLocaleInfo(LOCALE_STIMEFORMAT));
268  break;
269  }
270  return QVariant();
271 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int type
Definition: qmetatype.cpp:239
QString getLocaleInfo(LCTYPE type, int maxlen=0)
static QString winToQtFormat(const QString &sys_fmt)

◆ toCurrencyString()

QVariant QSystemLocalePrivate::toCurrencyString ( const QSystemLocale::CurrencyToStringArgument arg)

Definition at line 448 of file qlocale_win.cpp.

Referenced by winToQtFormat().

449 {
450  QString value;
451  switch (arg.value.type()) {
452  case QVariant::Int:
454  arg.value.toInt(), -1, 10, -1, QLocale::OmitGroupSeparator);
455  break;
456  case QVariant::UInt:
458  arg.value.toUInt(), -1, 10, -1, QLocale::OmitGroupSeparator);
459  break;
460  case QVariant::Double:
462  QLatin1Char(' '), QLatin1Char(','), QLatin1Char('.'),
464  break;
465  case QVariant::LongLong:
467  arg.value.toLongLong(), -1, 10, -1, QLocale::OmitGroupSeparator);
468  break;
469  case QVariant::ULongLong:
471  arg.value.toULongLong(), -1, 10, -1, QLocale::OmitGroupSeparator);
472  break;
473  default:
474  return QVariant();
475  }
476 
478 
479  QString decimalSep;
480  QString thousandSep;
481  CURRENCYFMT format;
482  CURRENCYFMT *pformat = NULL;
483  if (!arg.symbol.isEmpty()) {
484  format.NumDigits = getLocaleInfo_int(lcid, LOCALE_ICURRDIGITS);
485  format.LeadingZero = getLocaleInfo_int(lcid, LOCALE_ILZERO);
486  decimalSep = getLocaleInfo(lcid, LOCALE_SMONDECIMALSEP);
487  format.lpDecimalSep = (wchar_t *)decimalSep.utf16();
488  thousandSep = getLocaleInfo(lcid, LOCALE_SMONTHOUSANDSEP);
489  format.lpThousandSep = (wchar_t *)thousandSep.utf16();
490  format.NegativeOrder = getLocaleInfo_int(lcid, LOCALE_INEGCURR);
491  format.PositiveOrder = getLocaleInfo_int(lcid, LOCALE_ICURRENCY);
492  format.lpCurrencySymbol = (wchar_t *)arg.symbol.utf16();
493 
494  // grouping is complicated and ugly:
495  // int(0) == "123456789.00" == string("0")
496  // int(3) == "123,456,789.00" == string("3;0")
497  // int(30) == "123456,789.00" == string("3;0;0")
498  // int(32) == "12,34,56,789.00" == string("3;2;0")
499  // int(320)== "1234,56,789.00" == string("3;2")
500  QString groupingStr = getLocaleInfo(lcid, LOCALE_SMONGROUPING);
501  format.Grouping = groupingStr.remove(QLatin1Char(';')).toInt();
502  if (format.Grouping % 10 == 0) // magic
503  format.Grouping /= 10;
504  else
505  format.Grouping *= 10;
506  pformat = &format;
507  }
508 
509  int ret = ::GetCurrencyFormat(lcid, 0, reinterpret_cast<const wchar_t *>(value.utf16()),
510  pformat, out.data(), out.size());
511  if (ret == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
512  ret = ::GetCurrencyFormat(lcid, 0, reinterpret_cast<const wchar_t *>(value.utf16()),
513  pformat, out.data(), 0);
514  out.resize(ret);
515  ::GetCurrencyFormat(lcid, 0, reinterpret_cast<const wchar_t *>(value.utf16()),
516  pformat, out.data(), out.size());
517  }
518 
519  value = QString::fromWCharArray(out.data());
520  if (substitution() == SAlways)
521  substituteDigits( value);
522  return value;
523 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
int getLocaleInfo_int(LCTYPE type, int maxlen=0)
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString doubleToString(const QChar zero, const QChar plus, const QChar minus, const QChar exponent, const QChar group, const QChar decimal, double d, int precision, DoubleForm form, int width, unsigned flags)
Definition: qlocale.cpp:2613
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
static QString unsLongLongToString(const QChar zero, const QChar group, const QChar plus, quint64 l, int precision, int base, int width, unsigned flags)
Definition: qlocale.cpp:2870
static QString longLongToString(const QChar zero, const QChar group, const QChar plus, const QChar minus, qint64 l, int precision, int base, int width, unsigned flags)
Definition: qlocale.cpp:2775
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Definition: qvariant.cpp:2675
QString getLocaleInfo(LCTYPE type, int maxlen=0)
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QString & substituteDigits(QString &string)
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
SubstitutionType substitution()
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ toString() [1/3]

QVariant QSystemLocalePrivate::toString ( const QDate date,
QLocale::FormatType  type 
)

Definition at line 328 of file qlocale_win.cpp.

Referenced by dateTimeFormat(), toString(), and winToQtFormat().

329 {
330  SYSTEMTIME st;
331  memset(&st, 0, sizeof(SYSTEMTIME));
332  st.wYear = date.year();
333  st.wMonth = date.month();
334  st.wDay = date.day();
335 
336  DWORD flags = (type == QLocale::LongFormat ? DATE_LONGDATE : DATE_SHORTDATE);
337  wchar_t buf[255];
338  if (GetDateFormat(lcid, flags, &st, NULL, buf, 255)) {
340  if (substitution() == SAlways)
341  substituteDigits(format);
342  return format;
343  }
344  return QString();
345 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
int type
Definition: qmetatype.cpp:239
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define st(var, type, card)
QString & substituteDigits(QString &string)
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
SubstitutionType substitution()

◆ toString() [2/3]

QVariant QSystemLocalePrivate::toString ( const QTime time,
QLocale::FormatType   
)

Definition at line 347 of file qlocale_win.cpp.

348 {
349  SYSTEMTIME st;
350  memset(&st, 0, sizeof(SYSTEMTIME));
351  st.wHour = time.hour();
352  st.wMinute = time.minute();
353  st.wSecond = time.second();
354  st.wMilliseconds = 0;
355 
356  DWORD flags = 0;
357 
358  wchar_t buf[255];
359  if (GetTimeFormat(lcid, flags, &st, NULL, buf, 255)) {
361  if (substitution() == SAlways)
362  substituteDigits(format);
363  return format;
364  }
365  return QString();
366 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QString class provides a Unicode character string.
Definition: qstring.h:83
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
#define st(var, type, card)
QString & substituteDigits(QString &string)
SubstitutionType substitution()
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ toString() [3/3]

QVariant QSystemLocalePrivate::toString ( const QDateTime dt,
QLocale::FormatType  type 
)

Definition at line 368 of file qlocale_win.cpp.

369 {
370  return QString(toString(dt.date(), type).toString() + QLatin1Char(' ') + toString(dt.time(), type).toString());
371 }
int type
Definition: qmetatype.cpp:239
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
QVariant toString(const QDate &, QLocale::FormatType)
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ uiLanguages()

QVariant QSystemLocalePrivate::uiLanguages ( )

Definition at line 525 of file qlocale_win.cpp.

Referenced by winToQtFormat().

526 {
528  typedef BOOL (WINAPI *GetUserPreferredUILanguagesFunc) (
529  DWORD dwFlags,
530  PULONG pulNumLanguages,
531  PWSTR pwszLanguagesBuffer,
532  PULONG pcchLanguagesBuffer);
533  static GetUserPreferredUILanguagesFunc GetUserPreferredUILanguages_ptr = 0;
534  if (!GetUserPreferredUILanguages_ptr) {
535  QSystemLibrary lib(QLatin1String("kernel32"));
536  if (lib.load())
537  GetUserPreferredUILanguages_ptr = (GetUserPreferredUILanguagesFunc)lib.resolve("GetUserPreferredUILanguages");
538  }
539  if (GetUserPreferredUILanguages_ptr) {
540  unsigned long cnt = 0;
542  unsigned long size = buf.size();
543  if (!GetUserPreferredUILanguages_ptr(MUI_LANGUAGE_NAME, &cnt, buf.data(), &size)) {
544  size = 0;
545  if (GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
546  GetUserPreferredUILanguages_ptr(MUI_LANGUAGE_NAME, &cnt, NULL, &size)) {
547  buf.resize(size);
548  if (!GetUserPreferredUILanguages_ptr(MUI_LANGUAGE_NAME, &cnt, buf.data(), &size))
549  return QStringList();
550  }
551  }
552  QStringList result;
553  result.reserve(cnt);
554  const wchar_t *str = buf.constData();
555  for (; cnt > 0; --cnt) {
557  if (s.isEmpty())
558  break; // something is wrong
559  result.append(s);
560  str += s.size()+1;
561  }
562  return result;
563  }
564  }
565 
566  // old Windows before Vista
567  return QStringList(QString::fromLatin1(winLangCodeToIsoName(GetUserDefaultUILanguage())));
568 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static const char * winLangCodeToIsoName(int code)
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define MUI_LANGUAGE_NAME
Definition: qlocale_win.cpp:68
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496

◆ update()

void QSystemLocalePrivate::update ( )

Definition at line 585 of file qlocale_win.cpp.

Referenced by winToQtFormat().

586 {
587  lcid = GetUserDefaultLCID();
589  zero = QChar();
590 }
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
SubstitutionType substitutionType

◆ winToQtFormat()

QString QSystemLocalePrivate::winToQtFormat ( const QString sys_fmt)
staticprivate

Definition at line 592 of file qlocale_win.cpp.

Referenced by dateFormat(), and timeFormat().

593 {
594  QString result;
595  int i = 0;
596 
597  while (i < sys_fmt.size()) {
598  if (sys_fmt.at(i).unicode() == QLatin1Char('\'')) {
599  QString text = qt_readEscapedFormatString(sys_fmt, &i);
600  if (text == QLatin1String("'"))
601  result += QLatin1String("''");
602  else
603  result += QString(QLatin1Char('\'') + text + QLatin1Char('\''));
604  continue;
605  }
606 
607  QChar c = sys_fmt.at(i);
608  int repeat = qt_repeatCount(sys_fmt, i);
609 
610  switch (c.unicode()) {
611  // Date
612  case 'y':
613  if (repeat > 5)
614  repeat = 5;
615  else if (repeat == 3)
616  repeat = 2;
617  switch (repeat) {
618  case 1:
619  result += QLatin1String("yy"); // "y" unsupported by Qt, use "yy"
620  break;
621  case 5:
622  result += QLatin1String("yyyy"); // "yyyyy" same as "yyyy" on Windows
623  break;
624  default:
625  result += QString(repeat, QLatin1Char('y'));
626  break;
627  }
628  break;
629  case 'g':
630  if (repeat > 2)
631  repeat = 2;
632  switch (repeat) {
633  case 2:
634  break; // no equivalent of "gg" in Qt
635  default:
636  result += QLatin1Char('g');
637  break;
638  }
639  break;
640  case 't':
641  if (repeat > 2)
642  repeat = 2;
643  result += QLatin1String("AP"); // "t" unsupported, use "AP"
644  break;
645  default:
646  result += QString(repeat, c);
647  break;
648  }
649 
650  i += repeat;
651  }
652 
653  return result;
654 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int qt_repeatCount(const QString &s, int i)
Definition: qlocale.cpp:421
QString qt_readEscapedFormatString(const QString &format, int *idx)
Definition: qlocale.cpp:387
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define text
Definition: qobjectdefs.h:80

◆ zeroDigit()

QChar QSystemLocalePrivate::zeroDigit ( )

Definition at line 220 of file qlocale_win.cpp.

Referenced by substituteDigits(), and winToQtFormat().

221 {
222  if (zero.isNull())
223  zero = getLocaleInfo_qchar(LOCALE_SNATIVEDIGITS);
224  return zero;
225 }
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
QChar getLocaleInfo_qchar(LCTYPE type)

Properties

◆ langEnvVar

QByteArray QSystemLocalePrivate::langEnvVar
private

Definition at line 116 of file qlocale_win.cpp.

Referenced by getWinLocaleName(), and QSystemLocalePrivate().

◆ lcid

LCID QSystemLocalePrivate::lcid
private

◆ substitutionType

SubstitutionType QSystemLocalePrivate::substitutionType
private

Definition at line 127 of file qlocale_win.cpp.

Referenced by substitution(), and update().

◆ zero

QChar QSystemLocalePrivate::zero
private

Definition at line 128 of file qlocale_win.cpp.

Referenced by substituteDigits(), substitution(), update(), and zeroDigit().


The documentation for this struct was generated from the following file: