From 08868df5e94a5b89d9f8ce904e97b43a48313fc1 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Fri, 25 Feb 2011 15:42:51 +0100 Subject: fixed QLocale::quoteString() to allow for QSystemLocale implementation Reviewed-by: Denis Dzyubenko Task-number: QTBUG-17096 --- src/corelib/tools/qlocale.cpp | 15 +++++++++------ src/corelib/tools/qlocale.h | 4 ++-- src/corelib/tools/qlocale.qdoc | 4 ++-- src/corelib/tools/qlocale_mac.mm | 29 +++++++++++++---------------- src/corelib/tools/qlocale_p.h | 3 +++ src/corelib/tools/qlocale_unix.cpp | 8 +++++--- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index e10ca8a..5027d00 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -651,7 +651,6 @@ QLocale::NumberOptions QLocale::numberOptions() const */ QString QLocale::quoteString(const QString &str, QuotationStyle qs) const { - return quoteString(&str, qs); } @@ -664,14 +663,18 @@ QString QLocale::quoteString(const QStringRef &str, QuotationStyle qs) const { #ifndef QT_NO_SYSTEMLOCALE if (d() == systemPrivate()) { - QVariant quotationBegin = systemLocale()->query(QSystemLocale::QuotationBegin, QVariant(qs)); - QVariant quotationEnd = systemLocale()->query(QSystemLocale::QuotationEnd, QVariant(qs)); - if (!quotationBegin.isNull() && !quotationEnd.isNull()) - return quotationBegin.toString() % str % quotationEnd.toString(); + QVariant res; + if (qs == QLocale::StandardQuotation) + res = systemLocale()->query(QSystemLocale::StringToStandardQuotation, QVariant::fromValue(str)); + else + res = systemLocale()->query(QSystemLocale::StringToAlternateQuotation, QVariant::fromValue(str)); + + if (!res.isNull()) + return res.toString(); } #endif - if (qs == StandardQuotation) + if (qs == QLocale::StandardQuotation) return QChar(d()->m_quotation_start) % str % QChar(d()->m_quotation_end); else return QChar(d()->m_alternate_quotation_start) % str % QChar(d()->m_alternate_quotation_end); diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index a733732..7900c57 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -101,8 +101,8 @@ public: CurrencySymbol, // QString in: format CurrencyToString, // QString in: qlonglong, qulonglong or double UILanguages, // QStringList - QuotationBegin, // QString in: StandardQuotation or AlternateQuotation - QuotationEnd // QString in: StandardQuotation or AlternateQuotation + StringToStandardQuotation, // QString in: QStringRef to quote + StringToAlternateQuotation // QString in: QStringRef to quote }; virtual QVariant query(QueryType type, QVariant in) const; virtual QLocale fallbackLocale() const; diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index 5154324..20f546d 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -710,8 +710,8 @@ \value CurrencySymbol a string that represents a currency in a format QLocale::CurrencyFormat. \value CurrencyToString a localized string representation of a number with a currency symbol. \value UILanguages a list of strings representing locale names that could be used for UI translation. - \value QuotationBegin a QString specifying the start of a quotation. the in variant contains a QLocale::QuotationStyle - \value QuotationEnd a QString specifying the end of a quotation. the in variant contains a QLocale::QuotationStyle + \value StringToStandardQuotation a QString containing a quoted version of the string ref stored in the in variant using standard quotes. + \value StringToAlternateQuotation a QString containing a quoted version of the string ref stored in the in variant using alternate quotes. \value WeekendStart a Qt::DayOfWeek enum specifying the first day of the weekend \value WeekendEnd a Qt::DayOfWeek enum specifying the last day of the weekend */ diff --git a/src/corelib/tools/qlocale_mac.mm b/src/corelib/tools/qlocale_mac.mm index b8420e0..6c4829b 100644 --- a/src/corelib/tools/qlocale_mac.mm +++ b/src/corelib/tools/qlocale_mac.mm @@ -340,26 +340,23 @@ static QString macFormatCurrency(const QVariant &in) } #ifndef QT_NO_SYSTEMLOCALE -static QVariant macQuotationSymbol(QSystemLocale::QueryType type, const QVariant &in) +static QVariant macQuoteString(QSystemLocale::QueryType type, const QStringRef &str) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6) return QVariant(); + QString begin, end; QCFType locale = CFLocaleCopyCurrent(); switch (type) { - case QSystemLocale::QuotationBegin: - if (in.toInt() == QLocale::StandardQuotation) - return QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey))); - else - return QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey))); - break; - case QSystemLocale::QuotationEnd: - if (in.toInt() == QLocale::StandardQuotation) - return QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey))); - else - return QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey))); - break; + case QSystemLocale::StringToStandardQuotation: + begin = QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey))); + end = QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey))); + return QString(begin % str % end); + case QSystemLocale::StringToAlternateQuotation: + begin = QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey))); + end = QCFString::toQString(static_cast(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey))); + return QString(begin % str % end); default: break; } @@ -478,9 +475,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const } return QVariant(result); } - case QuotationBegin: - case QuotationEnd: - return macQuotationSymbol(type,in); + case StringToStandardQuotation: + case StringToAlternateQuotation: + return macQuoteString(type, in.value()); default: break; } diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index 68c66c1..636cc1d 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -55,6 +55,7 @@ #include "QtCore/qstring.h" #include "QtCore/qvarlengtharray.h" +#include "QtCore/qmetatype.h" #include "qlocale.h" @@ -64,6 +65,8 @@ class CEnvironmentChangeNotifier; QT_BEGIN_NAMESPACE +Q_DECLARE_METATYPE(QStringRef) + struct Q_CORE_EXPORT QLocalePrivate { public: diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp index 6faaf19..74c8c85 100644 --- a/src/corelib/tools/qlocale_unix.cpp +++ b/src/corelib/tools/qlocale_unix.cpp @@ -113,6 +113,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const const QLocale &lc_numeric = d->lc_numeric; const QLocale &lc_time = d->lc_time; const QLocale &lc_monetary = d->lc_monetary; + const QLocale &lc_messages = d->lc_messages; switch (type) { case DecimalPoint: @@ -215,9 +216,10 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const } return QVariant(); } - case QuotationBegin: - case QuotationEnd: - break; // TODO + case StringToStandardQuotation: + return lc_messages.quoteString(in.value()); + case StringToAlternateQuotation: + return lc_messages.quoteString(in.value(), QLocale::AlternateQuotation); default: break; } -- cgit v0.12