The QCollator class compares strings according to a localized collation algorithm. More...
Header: | #include <QCollator> |
qmake: | QT += core |
Since: | Qt 5.2 |
Note: All functions in this class are reentrant.
QCollator(const QLocale &locale = QLocale()) | |
QCollator(const QCollator &other) | |
QCollator(QCollator &&other) | |
~QCollator() | |
Qt::CaseSensitivity | caseSensitivity() const |
int | compare(const QString &s1, const QString &s2) const |
int | compare(const QStringRef &s1, const QStringRef &s2) const |
int | compare(const QChar *s1, int len1, const QChar *s2, int len2) const |
bool | ignorePunctuation() const |
QLocale | locale() const |
bool | numericMode() const |
void | setCaseSensitivity(Qt::CaseSensitivity sensitivity) |
void | setIgnorePunctuation(bool on) |
void | setLocale(const QLocale &locale) |
void | setNumericMode(bool on) |
QCollatorSortKey | sortKey(const QString &string) const |
void | swap(QCollator &other) |
QCollator & | operator=(const QCollator &other) |
QCollator & | operator=(QCollator &&other) |
The QCollator class compares strings according to a localized collation algorithm.
QCollator is initialized with a QLocale and an optional collation strategy. It tries to initialize the collator with the specified values. The collator can then be used to compare and sort strings in a locale dependent fashion.
A QCollator object can be used together with template based sorting algorithms such as std::sort to sort a list of QStrings.
In addition to the locale and collation strategy, several optional flags can be set that influence the result of the collation.
Constructs a QCollator from locale. If locale is not specified the system's default locale is used.
See also setLocale().
Creates a copy of other.
Move constructor. Moves from other into this collator.
Note that a moved-from QCollator can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.
Destroys the collator.
Returns case sensitivity of the collator.
See also setCaseSensitivity().
Compares s1 with s2. Returns an integer less than, equal to, or greater than zero depending on whether s1 is smaller, equal or larger than s2.
This is an overloaded function.
Compares s1 with s2. Returns an integer less than, equal to, or greater than zero depending on whether s1 is smaller, equal or larger than s2.
This is an overloaded function.
Compares s1 with s2. len1 and len2 specify the length of the QChar arrays pointer to by s1 and s2.
Returns an integer less than, equal to, or greater than zero depending on whether s1 is smaller, equal or larger than s2.
Returns true
if punctuation characters and symbols are ignored when determining sort order.
See also setIgnorePunctuation().
Returns the locale of the collator.
See also setLocale().
Returns true
if numeric sorting is enabled, false otherwise.
See also setNumericMode().
Sets the case sensitivity of the collator.
See also caseSensitivity().
If on is set to true, punctuation characters and symbols are ignored when determining sort order.
The default is locale dependent.
Note: This method is not currently supported if Qt is configured to not use ICU on Linux.
See also ignorePunctuation().
Sets the locale of the collator to locale.
See also locale().
Enables numeric sorting mode when on is set to true.
This will enable proper sorting of numeric digits, so that e.g. 100 sorts after 99.
By default this mode is off.
Note: On Windows, this functionality makes use of the ICU library. If Qt was compiled without ICU support, it falls back to code using native Windows API, which only works from Windows 7 onwards. On older versions of Windows, it will not work and a warning will be emitted at runtime.
See also numericMode().
Returns a sortKey for string.
Creating the sort key is usually somewhat slower, than using the compare() methods directly. But if the string is compared repeatedly (e.g. when sorting a whole list of strings), it's usually faster to create the sort keys for each string and then sort using the keys.
Swaps this collator with other. This function is very fast and never fails.
Assigns other to this collator.
Move-assigns from other to this collator.
Note that a moved-from QCollator can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.