Skip to content

Commit

Permalink
Replace deprecated Qt functions for std equivalents
Browse files Browse the repository at this point in the history
qSort and qGreater have been deprecated since Qt 5.0. Instead std::sort
and std::greater should be used
  • Loading branch information
PureTryOut committed Mar 25, 2020
1 parent 3ce0748 commit 81ec339
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions benchmarks/pt_mlocale/pt_mlocale.cpp
Expand Up @@ -249,8 +249,8 @@ void Pt_MLocale::benchmarkChineseSorting()
QString str("居 于 中 国 疆 域 内 的 各 个 民 族 统 称 为 中 华 民 族 亦 称 中 国 人 或 华 人 华 族 移 居 境 外 的 华 人 多 被 称 为 海 外 华 人 汉 族 是 中 国 人 口 最 多 地 域 分 布 最 广 的 民 族 在 少 数 民 族 当 中 人 过 年 口 查 有 满 苗 吾 彝 家 古 藏 9 民 通 汉 少 民 地 往 使 各 族 己 语 中 的 统 术 式 国 戏 书 和 画 传 娱 活 有 棋 棋 麻 等 国 格 术 术 世 名 酒 和 子 为 国 特 饮 文 春 中 新 元 清 端 七 中 重 冬 等 传 节 中 传 上 一 儒 思 国 中 人 强 的 庭 念 此 代 家 的 氏 于 名 前 国 还 视 育 对 才 选 春 时 孔 有 无 因 施 开 办 塾 养 才 朝 采 察 推 政 官 隋 起 行 举 平 中 拔 才 古 来 文 科 技 等 面 成 浩 烟 明 以 西 的 代 技 民 政 思 传 中 中 歷 重 編 历 历 历 都 有 官 此 存 十 详 的 史 料 二 四 资 通 等 今 4 0 多 前 中 地 为 心 始 现 落 织 而 国 和 代 历 多 演 和 代 迭 续 间 长 朝 有 商 汉 宋 和 等 朝 代 出 过 平 世 汉 文 之 和 武 兴 朝 观 治 开 盛 明 万 中 清 康 盛 等 學 究 示 國 代 更 常 氣 與 食 產 影 会 致 在 乱 分 时 中 王 历 上 断 北 游 民 交 征 如 奴 厥 卑 古 女 满 等 中 晋 代 经 五 乱 而 古 女 甚 入 中 改 了 国 世 的 史 展 程 多 族 入 华 族 大 庭 亥 命 中 的 王 体 1 1 年 出 史 台 而 之 是 和 体 中 民 後 国 内 時 民 府 臺 形 中 民 實 統 台 地 與 生 權 华 民 和 實 統 大 地 分 的 面 居 于 中 国 疆 域 内 的 各 个 民 族 统 称 为 中 华 民 族 亦 称 中 国 人 或 华 人 华 族 移 居 境 外 的 华 人 多 被 称 为 海 外 华 人 汉 族 是 中 国 人 口 最 多 地 域 分 布 最 广 的 民 族 在 少 数 民 族 当 中 人 过 年 口 查 有 满 苗 吾 彝 家 古 藏 9 民 通 汉 少 民 地 往 使 各 族 己 语 中 的 统 术 式 国 戏 书 和 画 传 娱 活 有 棋 棋 麻 等 国 格 术 术 世 名 酒 和 子 为 国 特 饮 文 春 中 新 元 清 端 七 中 重 冬 等 传 节 中 传 上 一 儒 思 国 中 人 强 的 庭 念 此 代 家 的 氏 于 名 前 国 还 视 育 对 才 选 春 时 孔 有 无 因 施 开 办 塾 养 才 朝 采 察 推 政 官 隋 起 行 举 平 中 拔 才 古 来 文 科 技 等 面 成 浩 烟 明 以 西 的 代 技 民 政 思 传 中 中 歷 重 編 历 历 历 都 有 官 此 存 十 详 的 史 料 二 四 资 通 等 今 4 0 多 前 中 地 为 心 始 现 落 织 而 国 和 代 历 多 演 和 代 迭 续 间 长 朝 有 商 汉 宋 和 等 朝 代 出 过 平 世 汉 文 之 和 武 兴 朝 观 治 开 盛 明 万 中 清 康 盛 等 學 究 示 國 代 更 常 氣 與 食 產 影 会 致 在 乱 分 时 中 王 历 上 断 北 游 民 交 征 如 奴 厥 卑 古 女 满 等 中 晋 代 经 五 乱 而 古 女 甚 入 中 改 了 国 世 的 史 展 程 多 族 入 华 族 大 庭 亥 命 中 的 王 体 1 1 年 出 史 台 而 之 是 和 体 中 民 後 国 内 時 民 府 臺 形 中 民 實 統 台 地 與 生 權 华 民 和 實 統 大 地 分 的 面");
QStringList list = str.split(QLatin1String(" "),QString::SkipEmptyParts);
QBENCHMARK {
qSort (list.begin(), list.end(), localeEn.collator());
qSort (list.begin(), list.end(), localeZh.collator());
std::sort (list.begin(), list.end(), localeEn.collator());
std::sort (list.begin(), list.end(), localeZh.collator());
}
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions doc/src/i18n.dox
Expand Up @@ -157,10 +157,10 @@ MLocale locale ("fi_FI");
where "fi" and "FI" define that the Finnish language in used in Finland.

\subsection Collator Collator
To collate, get the comparator with \c MLocale::collator() method or create it MCollator() for default locale collator. This object acts as a functor and can be passed to Qt's \c qSort() or any other sorting methods.
To collate, get the comparator with \c MLocale::collator() method or create it MCollator() for default locale collator. This object acts as a functor and can be passed to std::sort() or any other sorting methods.
The comparator basically compares two items as "lessThan" function and returns true if the first parameter should come before the second one.

If some other collation system than the locale's default is needed, use \c setCollation() method before getting the comparator. To start sorting, use Qt's \c qSort() function.
If some other collation system than the locale's default is needed, use \c setCollation() method before getting the comparator. To start sorting, use std::sort() function.

To use the default collation system:
\code
Expand All @@ -169,7 +169,7 @@ QStringList sl; // This contains the strings which need to be sorted
MLocale myLocale; // get the current locale
MCollator c = myLocale.collator(); // getting the comparator
...
qSort(sl.begin, sl.end, c); // start to sort!
std::sort(sl.begin, sl.end, c); // start to sort!
...
\endcode

Expand All @@ -190,7 +190,7 @@ MLocale myLocale("de_DE@collation=phonebook");

MCollator c = myLocale.collator(); // getting the comparator
...
qSort(sl.begin, sl.end, c); // start to sort!
std::sort(sl.begin, sl.end, c); // start to sort!
...
\endcode

Expand Down
6 changes: 3 additions & 3 deletions src/mcharsetdetector.cpp
Expand Up @@ -484,8 +484,8 @@ QList<MCharsetMatch> MCharsetDetector::detectAll()
}
// sort the list of matches again if confidences have been changed:
if(sortNeeded)
qSort(mCharsetMatchList.begin(), mCharsetMatchList.end(),
qGreater<MCharsetMatch>());
std::sort(mCharsetMatchList.begin(), mCharsetMatchList.end(),
std::greater<MCharsetMatch>());
if(mCharsetMatchList.isEmpty()) {
// is there any better status to describe this case?
d->_status = U_CE_NOT_FOUND_ERROR;
Expand Down Expand Up @@ -677,7 +677,7 @@ QStringList MCharsetDetector::getAllDetectableCharsets()
d->_allDetectableCharsets << cs;
}

qSort(d->_allDetectableCharsets);
std::sort(d->_allDetectableCharsets.begin(), d->_allDetectableCharsets.end());

return d->_allDetectableCharsets;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mcollator.cpp
Expand Up @@ -79,7 +79,7 @@ void MCollatorPrivate::initCollator(const icu::Locale &locale)
QStringList stringList;
stringList << "bb" << "da" << "aa" << "ab";
qSort(stringList.begin(), stringList.end(), comp); // sorts the list
std::sort(stringList.begin(), stringList.end(), comp); // sorts the list
\endverbatim
*/
Expand Down
2 changes: 1 addition & 1 deletion src/mlocalebuckets.cpp
Expand Up @@ -43,7 +43,7 @@ void MLocaleBucketsPrivate::setItems(const QStringList &unsortedItems, Qt::SortO
for (int i=0; i < unsortedItems.size(); ++i) {
items.append(MLocaleBucketItem(unsortedItems.at(i), i));
}
qStableSort(items.begin(), items.end(), MLocaleBucketItemComparator(sortOrder));
std::stable_sort(items.begin(), items.end(), MLocaleBucketItemComparator(sortOrder));

QString lastBucket;
QStringList lastBucketItems;
Expand Down
2 changes: 1 addition & 1 deletion src/mlocalebuckets_p.h
Expand Up @@ -75,7 +75,7 @@ struct MLocaleBucketItem



// Functor for qStableSort() comparison
// Functor for std::stable_sort() comparison
class MLocaleBucketItemComparator
{
public:
Expand Down
8 changes: 4 additions & 4 deletions tests/ft_locales/ft_locales.cpp
Expand Up @@ -3902,9 +3902,9 @@ void Ft_Locales::testMLocaleIndexBucket()
MLocale localeEn("en_US");
locale.setCategoryLocale(MLocale::MLcCollate, lcCollate);
QStringList stringsSortedCopy = stringsSorted;
qSort (stringsSortedCopy.begin(), stringsSortedCopy.end(),
std::sort (stringsSortedCopy.begin(), stringsSortedCopy.end(),
localeEn.collator());
qSort (stringsSortedCopy.begin(), stringsSortedCopy.end(),
std::sort (stringsSortedCopy.begin(), stringsSortedCopy.end(),
locale.collator());
#if defined(VERBOSE_OUTPUT)
QTextStream debugStream(stdout);
Expand Down Expand Up @@ -4407,7 +4407,7 @@ void Ft_Locales::checkAvailableLocales()
supportedLocaleNames.append(numberSystemTestLocales);
// sort the list for easier comparison in the output
// (i.e. es_419 should be near es, not at the end of the list):
qSort(supportedLocaleNames.begin(), supportedLocaleNames.end());
std::sort(supportedLocaleNames.begin(), supportedLocaleNames.end());
MCalendar::setSystemTimeZone("GMT+0");
QDateTime dateTime(QDate(2008, 7, 21), QTime(14, 31, 0, 0), Qt::LocalTime);
MCalendar gregorianCalendar(MLocale::GregorianCalendar);
Expand Down Expand Up @@ -4471,7 +4471,7 @@ void Ft_Locales::checkAvailableLocales()
QCOMPARE(MLocale::dataPaths(), (QStringList() << "/usr/share/mlocale5/icu"));
locale.setTimeFormat24h(MLocale::LocaleDefaultTimeFormat24h);
QCOMPARE(locale.timeFormat24h(), MLocale::LocaleDefaultTimeFormat24h);
qSort(sortingTestList.begin(), sortingTestList.end(), locale.collator());
std::sort(sortingTestList.begin(), sortingTestList.end(), locale.collator());
QString newLinePlusSupportedLocaleName('\n' + supportedLocaleName);
ft_localesTestOutput
+= supportedLocaleName + "\tLanguage endonym\t"
Expand Down
4 changes: 2 additions & 2 deletions tests/ft_mcharsetdetector/ft_mcharsetdetector.cpp
Expand Up @@ -90,8 +90,8 @@ void Ft_MCharsetDetector::testMCharsetMatch()
match.setConfidence(confidencesSorted[i].toInt());
mCharsetMatchListSorted << match;
}
qSort(mCharsetMatchList.begin(), mCharsetMatchList.end(),
qGreater<MCharsetMatch>());
std::sort(mCharsetMatchList.begin(), mCharsetMatchList.end(),
std::greater<MCharsetMatch>());
#if defined(VERBOSE_OUTPUT)
for(int i = 0; i < names.size(); ++i) {
qDebug() << mCharsetMatchList[i].name()
Expand Down
8 changes: 4 additions & 4 deletions tests/ft_sorting/ft_sorting.cpp
Expand Up @@ -412,7 +412,7 @@ void Ft_Sorting::testMLocaleSorting()
#if defined(VERBOSE_OUTPUT)
printf("%s %s %s %s %s\n", sl[0].toUtf8().data(), sl[1].toUtf8().data(), sl[2].toUtf8().data(), sl[3].toUtf8().data(), sl[4].toUtf8().data());
#endif
qSort(sl.begin(), sl.end(), mCollator);
std::sort(sl.begin(), sl.end(), mCollator);
#if defined(VERBOSE_OUTPUT)
printf("%s %s %s %s %s\n", sl[0].toUtf8().data(), sl[1].toUtf8().data(), sl[2].toUtf8().data(), sl[3].toUtf8().data(), sl[4].toUtf8().data());
#endif
Expand All @@ -424,18 +424,18 @@ void Ft_Sorting::testMLocaleSorting()

MCollator mCollatorDefaultLocale;
QStringList sl2 = stringListOrig;
qSort(sl2.begin(), sl2.end(), mCollatorDefaultLocale);
std::sort(sl2.begin(), sl2.end(), mCollatorDefaultLocale);
QCOMPARE(sl2, sl);

TestCollator *testCollator = new TestCollator(locale);
sl2 = stringListOrig;
qSort(sl2.begin(), sl2.end(), *testCollator);
std::sort(sl2.begin(), sl2.end(), *testCollator);
QCOMPARE(sl2, sl);
delete testCollator;

TestCollator *testCollatorDefaultLocale = new TestCollator();
sl2 = stringListOrig;
qSort(sl2.begin(), sl2.end(), *testCollatorDefaultLocale);
std::sort(sl2.begin(), sl2.end(), *testCollatorDefaultLocale);
QCOMPARE(sl2, sl);
delete testCollatorDefaultLocale;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ut_mlocationdatabase/ut_mlocationdatabase.cpp
Expand Up @@ -723,7 +723,7 @@ void Ut_MLocationDatabase::testCitiesDumpInfo()
+ gmtTotalOffsetSummer
+ ")\"\n";
}
qSort(ut_mlocationdatabaseTestOutput2Lines.begin(), ut_mlocationdatabaseTestOutput2Lines.end());
std::sort(ut_mlocationdatabaseTestOutput2Lines.begin(), ut_mlocationdatabaseTestOutput2Lines.end());
QString ut_mlocationdatabaseTestOutput2 = "";
foreach (QString line, ut_mlocationdatabaseTestOutput2Lines) {
ut_mlocationdatabaseTestOutput2 += line;
Expand Down

0 comments on commit 81ec339

Please sign in to comment.