QCollator 类

QCollator 类根据本地整理算法比较字符串。 更多...

头: #include <QCollator>
qmake: QT += core
Since: Qt 5.2

该类在 Qt 5.2 引入。

注意: 此类的所有函数 可重入 .

公共函数

QCollator (QCollator && other )
QCollator (const QCollator & other )
QCollator (const QLocale & locale )
QCollator ()
QCollator & operator= (QCollator && other )
QCollator & operator= (const QCollator & other )
~QCollator ()
Qt::CaseSensitivity caseSensitivity () const
int compare (QStringView s1 , QStringView s2 ) 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 被初始化采用 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.

成员函数文档编制

QCollator:: QCollator ( QCollator && 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.

QCollator:: QCollator (const QCollator & other )

创建副本为 other .

QCollator:: QCollator (const QLocale & locale )

构造 QCollator 从 locale .

另请参阅 setLocale ().

QCollator:: QCollator ()

Constructs a QCollator using the default locale's collation locale.

The system locale, when used as default locale, may have a collation locale other than itself (e.g. on Unix, if LC_COLLATE is set differently to LANG in the environment). All other locales are their own collation locales.

该函数在 Qt 5.13 引入。

另请参阅 setLocale (), QLocale::collation (),和 QLocale::setDefault ().

QCollator &QCollator:: operator= ( QCollator && other )

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.

QCollator &QCollator:: operator= (const QCollator & other )

赋值 other to this collator.

QCollator:: ~QCollator ()

Destroys the collator.

Qt::CaseSensitivity QCollator:: caseSensitivity () const

Returns case sensitivity of the collator.

另请参阅 setCaseSensitivity ().

int QCollator:: compare ( QStringView s1 , QStringView s2 ) const

比较 s1 with s2 .

Returns an integer less than, equal to, or greater than zero depending on whether s1 sorts before, with or after s2 .

该函数在 Qt 5.13 引入。

int QCollator:: compare (const QString & s1 , const QString & s2 ) const

这是重载函数。

比较 s1 with s2 .

Returns an integer less than, equal to, or greater than zero depending on whether s1 sorts before, with or after s2 .

int QCollator:: compare (const QStringRef & s1 , const QStringRef & s2 ) const

这是重载函数。

比较 s1 with s2 .

Returns an integer less than, equal to, or greater than zero depending on whether s1 sorts before, with or after s2 .

int QCollator:: compare (const QChar * s1 , int len1 , const QChar * s2 , int len2 ) const

这是重载函数。

比较 s1 with s2 . len1 and len2 specify the lengths of the QChar arrays pointed to by s1 and s2 .

Returns an integer less than, equal to, or greater than zero depending on whether s1 sorts before, with or after s2 .

bool QCollator:: ignorePunctuation () const

返回 true if punctuation characters and symbols are ignored when determining sort order.

另请参阅 setIgnorePunctuation ().

QLocale QCollator:: locale () const

Returns the locale of the collator.

另请参阅 setLocale ().

bool QCollator:: numericMode () const

返回 true if numeric sorting is enabled, false otherwise.

另请参阅 setNumericMode ().

void QCollator:: setCaseSensitivity ( Qt::CaseSensitivity sensitivity )

Sets the case sensitivity of the collator.

另请参阅 caseSensitivity ().

void QCollator:: setIgnorePunctuation ( bool on )

on is set to true, punctuation characters and symbols are ignored when determining sort order.

The default is locale dependent.

注意: This method is not currently supported if Qt is configured to not use ICU on Linux.

另请参阅 ignorePunctuation ().

void QCollator:: setLocale (const QLocale & locale )

Sets the locale of the collator to locale .

另请参阅 locale ().

void QCollator:: setNumericMode ( bool on )

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.

另请参阅 numericMode ().

QCollatorSortKey QCollator:: sortKey (const QString & string ) const

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.

注意: Not supported with the C (a.k.a. POSIX) locale on Darwin.

void QCollator:: swap ( QCollator & other )

Swaps this collator with other 。此函数非常快且从不失败。