Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcollator_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:trivial-impl-only
5
6#ifndef QCOLLATOR_P_H
7#define QCOLLATOR_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtCore/private/qglobal_p.h>
21#include "qcollator.h"
22#include "qlocale_p.h"
23#include <QList>
24#include <QtCore/qloggingcategory.h>
25#if QT_CONFIG(icu) || defined(Q_OS_ANDROID)
26#include <unicode/ucol.h>
27#elif defined(Q_OS_MACOS)
28#include <CoreServices/CoreServices.h>
29#elif defined(Q_OS_WIN)
30#include <qt_windows.h>
31#elif defined(Q_OS_WASM)
32#include <emscripten/val.h>
33#endif
34#ifdef Q_OS_ANDROID
35#include "qjniobject.h"
36#include "qjnitypes.h"
37#endif
38
39QT_BEGIN_NAMESPACE
40
41Q_DECLARE_LOGGING_CATEGORY(lcQCollator)
42
43#if QT_CONFIG(icu) || defined(Q_OS_ANDROID)
44typedef UCollator *CollatorType;
45typedef QByteArray CollatorKeyType;
46const CollatorType NoCollator = nullptr;
47
48#elif defined(Q_OS_MACOS)
49typedef CollatorRef CollatorType;
50typedef QList<UCCollationValue> CollatorKeyType;
51const CollatorType NoCollator = 0;
52
53#elif defined(Q_OS_WIN)
54typedef QByteArray CollatorKeyType;
55typedef int CollatorType;
56const CollatorType NoCollator = 0;
57
58#elif defined(Q_OS_WASM)
59typedef emscripten::val *CollatorType;
60struct QCollatorSortKeyWasm
61{
62 QString string;
63 emscripten::val collator = emscripten::val::undefined();
64};
65typedef QCollatorSortKeyWasm CollatorKeyType;
66const CollatorType NoCollator = nullptr;
67
68#else // posix - ignores CollatorType collator, only handles system locale
69typedef QList<wchar_t> CollatorKeyType;
70typedef bool CollatorType;
72#endif
73
74#ifdef Q_OS_ANDROID
75Q_DECLARE_JNI_CLASS(QtCollator, "org/qtproject/qt/android/QtCollator")
76Q_DECLARE_JNI_CLASS(Collator, "android/icu/text/Collator")
77#endif
78
79
81{
82public:
83 using Opt = QCollator::CollationOption;
84
86 QLocale locale;
88 bool dirty = true;
89
91#ifdef Q_OS_ANDROID
92 QtJniTypes::Collator fallbackCollator = QJniObject(); // needs to be null rather than default-constructed
93#endif
94
95 QCollatorPrivate(const QLocale &locale) : locale(locale) {}
97 bool isC() const { return locale.language() == QLocale::C; }
98
99 void clear() {
100 cleanup();
102 }
103
105 {
106 if (dirty)
107 init();
108 }
109
110 // Implemented by each back-end, in its own way:
111 void init();
112 void cleanup();
113
114 static QCollatorSortKey sortKeyFromData(CollatorKeyType &&data);
115
116private:
118};
119
121{
122public:
123 explicit QCollatorSortKeyPrivate(CollatorKeyType &&list)
125 {
126 }
127
129
130private:
132};
133
134inline QCollatorSortKey QCollatorPrivate::sortKeyFromData(CollatorKeyType &&data)
135{
136 return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(data)));
137}
138
139QT_END_NAMESPACE
140
141#endif // QCOLLATOR_P_H
QAtomicInt ref
Definition qcollator_p.h:85
bool isC() const
Definition qcollator_p.h:97
void ensureInitialized()
QCollatorPrivate(const QLocale &locale)
Definition qcollator_p.h:95
CollatorType collator
Definition qcollator_p.h:90
static QCollatorSortKey sortKeyFromData(CollatorKeyType &&data)
CollatorKeyType m_key
QCollatorSortKeyPrivate(CollatorKeyType &&list)
\inmodule QtCore
Combined button and popup list for selecting options.
const CollatorType NoCollator
Definition qcollator_p.h:71
bool CollatorType
Definition qcollator_p.h:70
GenerationalCollator(const QCollator &copy)
Definition qcollator.cpp:25