summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcollator_p.h
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2013-09-10 03:54:54 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-13 05:48:10 +0200
commit1864b485e4c37db2ef09b8a47a5bf3cc570cc222 (patch)
treea48bb10d17385b44a9af77d3e44444d28bae6c17 /src/corelib/tools/qcollator_p.h
parentc517a6d6ff70235ed3a3b93a87948add1de743ed (diff)
Make QCollator more flexible to use in different platforms
So far we've known that we want QCollator as public API. It hasn't been possible yet due to the strong dependency that QCollator used to have on ICU. This patch adds collation support for the platforms where ICU is not the best option by using native collation API. Namely Windows and Mac OS X. Additionally a fallback POSIX back-end is added, so that we can make sure it will work on any posix-compliant platform. Change-Id: Ia1734acbf5f596698a81f2af927cc15636e4c908 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qcollator_p.h')
-rw-r--r--src/corelib/tools/qcollator_p.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/corelib/tools/qcollator_p.h b/src/corelib/tools/qcollator_p.h
new file mode 100644
index 0000000000..7c5f18c5b2
--- /dev/null
+++ b/src/corelib/tools/qcollator_p.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOLLATOR_P_H
+#define QCOLLATOR_P_H
+
+#include "qcollator.h"
+#include <QVector>
+#ifdef QT_USE_ICU
+#include <unicode/ucol.h>
+#elif defined(Q_OS_DARWIN)
+#include <CoreServices/CoreServices.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#ifdef QT_USE_ICU
+typedef UCollator *CollatorType;
+typedef QByteArray CollatorKeyType;
+
+#elif defined(Q_OS_DARWIN)
+typedef QVector<UCCollationValue> CollatorKeyType;
+
+struct CollatorType {
+ CollatorType(int opt) : collator(NULL), options(opt) {}
+
+ CollatorRef collator;
+ UInt32 options;
+};
+#elif defined(Q_OS_WIN)
+typedef QString CollatorKeyType;
+typedef int CollatorType;
+#else //posix
+typedef QVector<wchar_t> CollatorKeyType;
+typedef int CollatorType;
+#endif
+
+class Q_CORE_EXPORT QCollatorPrivate
+{
+public:
+ QAtomicInt ref;
+ QLocale locale;
+
+ CollatorType collator;
+
+ void clear() {
+ cleanup();
+ collator = 0;
+ }
+
+ void init();
+ void cleanup();
+
+ QCollatorPrivate()
+ : ref(1), collator(0)
+ { cleanup(); }
+
+ ~QCollatorPrivate() { cleanup(); }
+
+private:
+ Q_DISABLE_COPY(QCollatorPrivate)
+};
+
+class Q_CORE_EXPORT QCollatorSortKeyPrivate : public QSharedData
+{
+ friend class QCollator;
+public:
+ QCollatorSortKeyPrivate(const CollatorKeyType &key)
+ : QSharedData()
+ , m_key(key)
+ {
+ }
+
+ CollatorKeyType m_key;
+
+private:
+ Q_DISABLE_COPY(QCollatorSortKeyPrivate)
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QCOLLATOR_P_H