Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.28 KB | None | 0 0
  1. From 0314542545c510025849223a700080a5cadb8dd4 Mon Sep 17 00:00:00 2001
  2. From: Denis Dzyubenko <denis.dzyubenko@nokia.com>
  3. Date: Mon, 21 Feb 2011 18:35:07 +0100
  4. Subject: [PATCH] WIP: Supporting multiple locale categories on Unix.
  5.  
  6. This patch adds support for LC_* environment variables on Unix.
  7.  
  8. Reviewed-by: pending
  9. ---
  10. src/corelib/tools/qlocale.cpp |  118 +++++++++++++++++++++++++++++++++++++----
  11.  src/corelib/tools/qlocale.h   |    2 +-
  12.  2 files changed, 108 insertions(+), 12 deletions(-)
  13.  
  14. diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
  15. index 46fef5b..7782989 100644
  16. --- a/src/corelib/tools/qlocale.cpp
  17. +++ b/src/corelib/tools/qlocale.cpp
  18. @@ -43,8 +43,8 @@
  19.  
  20.  #ifndef QT_NO_SYSTEMLOCALE
  21.  QT_BEGIN_NAMESPACE
  22. -class QSystemLocale;
  23. -static QSystemLocale *QSystemLocale_globalSystemLocale();
  24. +class QSystemLocaleData;
  25. +static QSystemLocaleData *QSystemLocale_globalSystemLocale();
  26.  QT_END_NAMESPACE
  27.  #endif
  28.  
  29. @@ -135,6 +135,33 @@ void qt_symbianUpdateSystemPrivate();
  30.  void qt_symbianInitSystemLocale();
  31.  #endif
  32.  
  33. +#ifndef QT_NO_SYSTEMLOCALE
  34. +static QSystemLocale *_systemLocale = 0;
  35. +
  36. +struct QSystemLocaleData
  37. +{
  38. +    QSystemLocaleData()
  39. +        : locale(true)
  40. +    #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
  41. +        ,lc_numeric(QLocale(QLatin1String(qgetenv("LC_NUMERIC"))))
  42. +        ,lc_time(QLocale(QLatin1String(qgetenv("LC_TIME"))))
  43. +        ,lc_monetary(QLocale(QLatin1String(qgetenv("LC_MONETARY"))))
  44. +    #endif
  45. +    {
  46. +    }
  47. +    QSystemLocale locale;
  48. +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
  49. +    QLocale lc_numeric;
  50. +    QLocale lc_time;
  51. +    QLocale lc_monetary;
  52. +#endif
  53. +};
  54. +
  55. +Q_GLOBAL_STATIC(QSystemLocaleData, QSystemLocale_globalSystemLocale)
  56. +static QLocalePrivate *system_lp = 0;
  57. +Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate)
  58. +#endif
  59. +
  60.  /******************************************************************************
  61.  ** Helpers for accessing Qt locale database
  62.  */
  63. @@ -1515,8 +1542,84 @@ QLocale QSystemLocale::fallbackLocale() const
  64.  /*!
  65.      \internal
  66.  */
  67. -QVariant QSystemLocale::query(QueryType type, QVariant /* in */) const
  68. +QVariant QSystemLocale::query(QueryType type, QVariant in) const
  69.  {
  70. +    QSystemLocaleData *d = QSystemLocale_globalSystemLocale();
  71. +    const QLocale &lc_numeric = d->lc_numeric;
  72. +    const QLocale &lc_time = d->lc_time;
  73. +    const QLocale &lc_monetary = d->lc_monetary;
  74. +
  75. +    switch (type) {
  76. +    case DecimalPoint:
  77. +        return lc_numeric.decimalPoint();
  78. +    case GroupSeparator:
  79. +        return lc_numeric.groupSeparator();
  80. +    case ZeroDigit:
  81. +        return lc_numeric.zeroDigit();
  82. +    case NegativeSign:
  83. +        return lc_numeric.negativeSign();
  84. +    case DateFormatLong:
  85. +        return lc_time.dateFormat(QLocale::LongFormat);
  86. +    case DateFormatShort:
  87. +        return lc_time.dateFormat(QLocale::ShortFormat);
  88. +    case TimeFormatLong:
  89. +        return lc_time.timeFormat(QLocale::LongFormat);
  90. +    case TimeFormatShort:
  91. +        return lc_time.timeFormat(QLocale::ShortFormat);
  92. +    case DayNameLong:
  93. +        return lc_time.dayName(in.toInt(), QLocale::LongFormat);
  94. +    case DayNameShort:
  95. +        return lc_time.dayName(in.toInt(), QLocale::ShortFormat);
  96. +    case MonthNameLong:
  97. +        return lc_time.monthName(in.toInt(), QLocale::LongFormat);
  98. +    case MonthNameShort:
  99. +        return lc_time.monthName(in.toInt(), QLocale::ShortFormat);
  100. +    case DateToStringLong:
  101. +        return lc_time.toString(in.toDate(), QLocale::LongFormat);
  102. +    case DateToStringShort:
  103. +        return lc_time.toString(in.toDate(), QLocale::ShortFormat);
  104. +    case TimeToStringLong:
  105. +        return lc_time.toString(in.toTime(), QLocale::LongFormat);
  106. +    case TimeToStringShort:
  107. +        return lc_time.toString(in.toTime(), QLocale::ShortFormat);
  108. +    case DateTimeFormatLong:
  109. +        return lc_time.dateTimeFormat(QLocale::LongFormat);
  110. +    case DateTimeFormatShort:
  111. +        return lc_time.dateTimeFormat(QLocale::ShortFormat);
  112. +    case DateTimeToStringLong:
  113. +        return lc_time.toString(in.toDateTime(), QLocale::LongFormat);
  114. +    case DateTimeToStringShort:
  115. +        return lc_time.toString(in.toDateTime(), QLocale::ShortFormat);
  116. +    case PositiveSign:
  117. +        return lc_numeric.positiveSign();
  118. +    case AMText:
  119. +        return lc_time.amText();
  120. +    case PMText:
  121. +        return lc_time.pmText();
  122. +    case FirstDayOfWeek:
  123. +        return lc_time.firstDayOfWeek();
  124. +    case CurrencySymbol:
  125. +        return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt()));
  126. +    case FormatCurrency: {
  127. +        switch (in.type()) {
  128. +        case QVariant::Int:
  129. +            return lc_monetary.toCurrencyString(in.toInt());
  130. +        case QVariant::UInt:
  131. +            return lc_monetary.toCurrencyString(in.toUInt());
  132. +        case QVariant::Double:
  133. +            return lc_monetary.toCurrencyString(in.toDouble());
  134. +        case QVariant::LongLong:
  135. +            return lc_monetary.toCurrencyString(in.toLongLong());
  136. +        case QVariant::ULongLong:
  137. +            return lc_monetary.toCurrencyString(in.toULongLong());
  138. +        default:
  139. +            return QString();
  140. +        }
  141. +    }
  142. +    default:
  143. +        break;
  144. +    }
  145. +
  146.      if (type == MeasurementSystem) {
  147.          return QVariant(unixGetSystemMeasurementSystem());
  148.      } else if (type == UILanguages) {
  149. @@ -1581,13 +1684,6 @@ QVariant QSystemLocale::query(QueryType /* type */, QVariant /* in */) const
  150.  
  151.  #endif
  152.  
  153. -#ifndef QT_NO_SYSTEMLOCALE
  154. -static QSystemLocale *_systemLocale = 0;
  155. -Q_GLOBAL_STATIC_WITH_ARGS(QSystemLocale, QSystemLocale_globalSystemLocale, (true))
  156. -static QLocalePrivate *system_lp = 0;
  157. -Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate)
  158. -#endif
  159. -
  160.  /******************************************************************************
  161.  ** Default system locale behavior
  162.  */
  163. @@ -1683,7 +1779,7 @@ static const QSystemLocale *systemLocale()
  164.  #if defined(Q_OS_SYMBIAN)
  165.      qt_symbianInitSystemLocale();
  166.  #endif
  167. -    return QSystemLocale_globalSystemLocale();
  168. +    return &QSystemLocale_globalSystemLocale()->locale;
  169.  }
  170.  
  171.  void QLocalePrivate::updateSystemPrivate()
  172. diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
  173. index 7a6591c..79866be 100644
  174. --- a/src/corelib/tools/qlocale.h
  175. +++ b/src/corelib/tools/qlocale.h
  176. @@ -105,7 +105,7 @@ public:
  177.  
  178.  private:
  179.      QSystemLocale(bool);
  180. -    friend QSystemLocale *QSystemLocale_globalSystemLocale();
  181. +    friend class QSystemLocaleData;
  182.  };
  183.  #endif
  184.  
  185. --
  186. 1.7.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement