From c17563eca879845deef542173f5fb479c9aa2d0e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 27 Aug 2014 12:57:14 +0200 Subject: Fix several issues in QCollator Refactor the code and move more things into the cross platform code path. Make sure the flags survive changing the locale of QCollator. Use the correct locale on Windows, WinRT and OS X. We now pass all QCollator autotests on these platforms. Task-number: QTBUG-40778 Change-Id: Ic2d3334b5018c323a35a3ea8fc1d7ab5f99b4e62 Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.cpp | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qcollator.cpp') diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index f7dfaa7d33..8cdcb2a947 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -166,10 +166,12 @@ void QCollator::detach() */ void QCollator::setLocale(const QLocale &locale) { + if (locale == d->locale) + return; + detach(); - d->clear(); d->locale = locale; - d->init(); + d->dirty = true; } /*! @@ -187,6 +189,15 @@ QLocale QCollator::locale() const \sa caseSensitivity() */ +void QCollator::setCaseSensitivity(Qt::CaseSensitivity cs) +{ + if (d->caseSensitivity == cs) + return; + + detach(); + d->caseSensitivity = cs; + d->dirty = true; +} /*! \fn Qt::CaseSensitivity QCollator::caseSensitivity() const @@ -195,6 +206,10 @@ QLocale QCollator::locale() const \sa setCaseSensitivity() */ +Qt::CaseSensitivity QCollator::caseSensitivity() const +{ + return d->caseSensitivity; +} /*! \fn void QCollator::setNumericMode(bool on) @@ -212,6 +227,15 @@ QLocale QCollator::locale() const \sa numericMode() */ +void QCollator::setNumericMode(bool on) +{ + if (d->numericMode == on) + return; + + detach(); + d->numericMode = on; + d->dirty = true; +} /*! \fn bool QCollator::numericMode() const @@ -220,6 +244,10 @@ QLocale QCollator::locale() const \sa setNumericMode() */ +bool QCollator::numericMode() const +{ + return d->numericMode; +} /*! \fn void QCollator::setIgnorePunctuation(bool on) @@ -230,6 +258,15 @@ QLocale QCollator::locale() const \sa ignorePunctuation() */ +void QCollator::setIgnorePunctuation(bool on) +{ + if (d->ignorePunctuation == on) + return; + + detach(); + d->ignorePunctuation = on; + d->dirty = true; +} /*! \fn bool QCollator::ignorePunctuation() const @@ -238,6 +275,10 @@ QLocale QCollator::locale() const \sa setIgnorePunctuation() */ +bool QCollator::ignorePunctuation() const +{ + return d->ignorePunctuation; +} /*! \fn int QCollator::compare(const QString &s1, const QString &s2) const -- cgit v1.2.3