Commit 12103e0f authored by Nikita Baryshnikov's avatar Nikita Baryshnikov Committed by hjk

Reinvent deprecated qSort as Utils::sort

Change-Id: I4f6011cc2b6127037249aabc2426a88ad7108ebf
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent eefd0f43
......@@ -113,6 +113,18 @@ auto transform(const QList<T> &container, F function) -> QList<decltype(function
return result;
}
template <typename Container>
inline void sort(Container &c)
{
std::sort(c.begin(), c.end());
}
template <typename Container, typename Predicate>
inline void sort(Container &c, Predicate p)
{
std::sort(c.begin(), c.end(), p);
}
}
#endif // ALGORITHM_H
......@@ -50,6 +50,7 @@
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtversionmanager.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/sleep.h>
......@@ -248,7 +249,7 @@ void AndroidConfig::updateNdkInformation() const
const QString &fileName = it.next();
m_availableNdkPlatforms.push_back(fileName.mid(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
}
qSort(m_availableNdkPlatforms.begin(), m_availableNdkPlatforms.end(), qGreater<int>());
Utils::sort(m_availableNdkPlatforms, std::greater<int>());
// detect toolchain host
QStringList hostPatterns;
......@@ -494,7 +495,7 @@ QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(QString *error) const
devices.push_back(dev);
}
qSort(devices.begin(), devices.end(), androidDevicesLessThan);
Utils::sort(devices, androidDevicesLessThan);
if (devices.isEmpty() && error)
*error = QApplication::translate("AndroidConfiguration",
"No devices found in output of: %1")
......@@ -631,7 +632,7 @@ QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevices() const
dev.type = AndroidDeviceInfo::Emulator;
devices.push_back(dev);
}
qSort(devices.begin(), devices.end(), androidDevicesLessThan);
Utils::sort(devices, androidDevicesLessThan);
return devices;
}
......
......@@ -50,6 +50,7 @@
#include <qtsupport/customexecutablerunconfiguration.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtsupportconstants.h>
#include <utils/algorithm.h>
#include <QDir>
#include <QFileSystemWatcher>
......@@ -868,7 +869,11 @@ QVector<AndroidManager::Library> AndroidManager::availableQtLibsWithDependencies
}
qtLibraries.push_back(library);
}
qSort(qtLibraries.begin(), qtLibraries.end(), qtLibrariesLessThan);
Utils::sort(qtLibraries, [](const Library &a, const Library &b) -> bool {
if (a.level == b.level)
return a.name < b.name;
return a.level < b.level;
});
return qtLibraries;
......@@ -1171,13 +1176,6 @@ int AndroidManager::setLibraryLevel(const QString &library, LibrariesMap &mapLib
return maxlevel + 1;
}
bool AndroidManager::qtLibrariesLessThan(const Library &a, const Library &b)
{
if (a.level == b.level)
return a.name < b.name;
return a.level < b.level;
}
QString AndroidManager::libGnuStl(const QString &arch, const QString &ndkToolChainVersion)
{
return AndroidConfigurations::currentConfig().ndkLocation().toString()
......
......@@ -158,7 +158,7 @@ private:
static QStringList dependencies(const Utils::FileName &readelfPath, const QString &lib);
static int setLibraryLevel(const QString &library, LibrariesMap &mapLibs);
static bool qtLibrariesLessThan(const Library &a, const Library &b);
};
} // namespace Internal
......
......@@ -48,6 +48,7 @@
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
#include <qmakeprojectmanager/qmakeproject.h>
#include <utils/algorithm.h>
#include <QLineEdit>
#include <QFileInfo>
......@@ -1348,7 +1349,7 @@ void PermissionsModel::setPermissions(const QStringList &permissions)
{
beginResetModel();
m_permissions = permissions;
qSort(m_permissions);
Utils::sort(m_permissions);
endResetModel();
}
......
......@@ -173,7 +173,7 @@ static QList<CodeCompletionResult> unfilteredCompletion(const ClangCompletionAss
}
QList<CodeCompletionResult> result = wrapper->codeCompleteAt(line, column + 1, unsavedFiles);
qSort(result);
std::sort(result);
if (DebugTiming)
qDebug() << "... Completion done in" << t.elapsed() << "ms, with" << result.count() << "items.";
......
......@@ -56,6 +56,7 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <projectexplorer/iprojectmanager.h>
#include <utils/algorithm.h>
#include <utils/synchronousprocess.h>
#include <utils/parameteraction.h>
#include <utils/fileutils.h>
......@@ -1906,7 +1907,7 @@ QList<QStringPair> ClearCasePlugin::ccGetActivities() const
result.append(QStringPair(actName, act.at(1).trimmed()));
}
}
qSort(result);
Utils::sort(result);
if (!rebaseAct.first.isEmpty())
result.append(rebaseAct);
if (!deliverAct.first.isEmpty())
......
......@@ -55,6 +55,7 @@
#include <qtsupport/uicodemodelsupport.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/hostosinfo.h>
......@@ -432,8 +433,8 @@ void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::
// Gather old list
QList<ProjectExplorer::FileNode *> oldList;
gatherFileNodes(rootNode, oldList);
qSort(oldList.begin(), oldList.end(), sortNodesByPath);
qSort(newList.begin(), newList.end(), sortNodesByPath);
Utils::sort(oldList, sortNodesByPath);
Utils::sort(newList, sortNodesByPath);
QList<ProjectExplorer::FileNode *> added;
QList<ProjectExplorer::FileNode *> deleted;
......
......@@ -30,6 +30,7 @@
#include "externaltoolconfig.h"
#include "ui_externaltoolconfig.h"
#include <utils/algorithm.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
......@@ -257,7 +258,7 @@ bool ExternalToolModel::setData(const QModelIndex &modelIndex, const QVariant &v
int previousIndex = categories.indexOf(category);
categories.removeAt(previousIndex);
categories.append(string);
qSort(categories);
Utils::sort(categories);
int newIndex = categories.indexOf(string);
if (newIndex != previousIndex) {
// we have same parent so we have to do special stuff for beginMoveRows...
......@@ -327,7 +328,7 @@ QModelIndex ExternalToolModel::addCategory()
}
QList<QString> categories = m_tools.keys();
categories.append(category);
qSort(categories);
Utils::sort(categories);
int pos = categories.indexOf(category);
beginInsertRows(QModelIndex(), pos, pos);
......
......@@ -30,6 +30,7 @@
#include "helpmanager.h"
#include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <utils/filesystemwatcher.h>
#include <QDateTime>
......@@ -263,7 +264,7 @@ QStringList HelpManager::findKeywords(const QString &key, Qt::CaseSensitivity ca
}
QStringList keywordsSorted = keywordsToSort.toList();
qSort(keywordsSorted.begin(), keywordsSorted.end());
Utils::sort(keywordsSorted);
return keywordsSorted + keywords.toList();
}
......
......@@ -46,6 +46,7 @@
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/progressmanager/futureprogress.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/QtConcurrentTools>
#include <utils/qtcassert.h>
......@@ -57,17 +58,6 @@
namespace Core {
namespace Internal {
namespace {
static bool filterLessThan(const ILocatorFilter *first, const ILocatorFilter *second)
{
if (first->priority() < second->priority())
return true;
if (first->priority() > second->priority())
return false;
return first->id().alphabeticallyBefore(second->id());
}
}
Locator::Locator()
: m_settingsInitialized(false)
{
......@@ -151,7 +141,11 @@ void Locator::openLocator()
void Locator::extensionsInitialized()
{
m_filters = ExtensionSystem::PluginManager::getObjects<ILocatorFilter>();
qSort(m_filters.begin(), m_filters.end(), filterLessThan);
Utils::sort(m_filters, [](const ILocatorFilter *first, const ILocatorFilter *second) -> bool {
if (first->priority() != second->priority())
return first->priority() < second->priority();
return first->id().alphabeticallyBefore(second->id());
});
setFilters(m_filters);
}
......
......@@ -36,6 +36,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <coreplugin/editormanager/iexternaleditor.h>
#include <utils/algorithm.h>
#include <utils/headerviewstretcher.h>
#include <QAbstractTableModel>
......@@ -47,19 +48,10 @@
#include <QSet>
#include <QStringList>
#include <QSortFilterProxyModel>
#include <QtAlgorithms>
#include <algorithm>
namespace Core {
namespace Internal {
struct MimeTypeComp
{
bool operator()(const MimeType &a, const MimeType &b)
{ return a.type().compare(b.type(), Qt::CaseInsensitive) < 0; }
};
// MimeTypeSettingsModel
class MimeTypeSettingsModel : public QAbstractTableModel
{
......@@ -125,7 +117,9 @@ QVariant MimeTypeSettingsModel::data(const QModelIndex &modelIndex, int role) co
void MimeTypeSettingsModel::load()
{
m_mimeTypes = MimeDatabase::mimeTypes();
qSort(m_mimeTypes.begin(), m_mimeTypes.end(), MimeTypeComp());
Utils::sort(m_mimeTypes, [](const MimeType &a, const MimeType &b) {
return a.type().compare(b.type(), Qt::CaseInsensitive) < 0;
});
m_knownPatterns = QSet<QString>::fromList(
MimeDatabase::fromGlobPatterns(MimeDatabase::globPatterns()));
......@@ -498,7 +492,7 @@ void MimeTypeSettingsPrivate::updateMimeDatabase()
// For this case it is a better approach to simply use a list and to remove duplicates
// afterwards than to keep a more complex data structure like a hash table.
qSort(m_modifiedMimeTypes.begin(), m_modifiedMimeTypes.end());
Utils::sort(m_modifiedMimeTypes);
m_modifiedMimeTypes.erase(std::unique(m_modifiedMimeTypes.begin(), m_modifiedMimeTypes.end()),
m_modifiedMimeTypes.end());
......
......@@ -43,6 +43,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/hostosinfo.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
......@@ -75,11 +76,6 @@ static char outputPaneVisibleKeyC[] = "visible";
static OutputPaneManager *m_instance = 0;
bool comparePanes(IOutputPane *p1, IOutputPane *p2)
{
return p1->priorityInStatusBar() > p2->priorityInStatusBar();
}
void OutputPaneManager::create()
{
m_instance = new OutputPaneManager;
......@@ -239,7 +235,9 @@ void OutputPaneManager::init()
int minTitleWidth = 0;
m_panes = ExtensionSystem::PluginManager::getObjects<IOutputPane>();
qSort(m_panes.begin(), m_panes.end(), &comparePanes);
Utils::sort(m_panes, [](IOutputPane *p1, IOutputPane *p2) {
return p1->priorityInStatusBar() > p2->priorityInStatusBar();
});
const int n = m_panes.size();
int shortcutNumber = 1;
......
......@@ -31,6 +31,7 @@
#include "sidebarwidget.h"
#include "actionmanager/command.h"
#include <utils/algorithm.h>
#include <QSettings>
#include <QPointer>
......@@ -152,7 +153,7 @@ void SideBar::makeItemAvailable(SideBarItem *item)
d->m_availableItemIds.append(it.key());
d->m_availableItemTitles.append(it.value().data()->title());
d->m_unavailableItemIds.removeAll(it.key());
qSort(d->m_availableItemTitles);
Utils::sort(d->m_availableItemTitles);
emit availableItemsChanged();
//updateWidgets();
break;
......@@ -178,7 +179,7 @@ void SideBar::setUnavailableItemIds(const QStringList &itemIds)
d->m_availableItemIds.removeAll(id);
d->m_availableItemTitles.removeAll(d->m_itemMap.value(id).data()->title());
}
qSort(d->m_availableItemTitles);
Utils::sort(d->m_availableItemTitles);
updateWidgets();
}
......
......@@ -32,6 +32,7 @@
#include "navigationsubwidget.h"
#include <coreplugin/coreconstants.h>
#include <utils/algorithm.h>
#include <QToolBar>
#include <QToolButton>
......@@ -91,7 +92,7 @@ SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &id)
lay->addWidget(m_toolbar);
QStringList titleList = m_sideBar->availableItemTitles();
qSort(titleList);
Utils::sort(titleList);
QString t = id;
if (titleList.count()) {
foreach (const QString &itemTitle, titleList)
......@@ -158,7 +159,7 @@ void SideBarWidget::updateAvailableItems()
QStringList titleList = m_sideBar->availableItemTitles();
if (!currentTitle.isEmpty() && !titleList.contains(currentTitle))
titleList.append(currentTitle);
qSort(titleList);
Utils::sort(titleList);
foreach (const QString &itemTitle, titleList)
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
......
......@@ -40,6 +40,7 @@
#include <vcsbase/vcsbaseconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QDir>
......@@ -221,11 +222,6 @@ void VcsManager::extensionsInitialized()
}
}
static bool longerThanPath(QPair<QString, IVersionControl *> &pair1, QPair<QString, IVersionControl *> &pair2)
{
return pair1.first.size() > pair2.first.size();
}
void VcsManager::resetVersionControlForDirectory(const QString &inputDirectory)
{
if (inputDirectory.isEmpty())
......@@ -273,7 +269,10 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
// To properly find a nested repository (say, git checkout inside SVN),
// we need to select the version control with the longest toplevel pathname.
qSort(allThatCanManage.begin(), allThatCanManage.end(), longerThanPath);
Utils::sort(allThatCanManage, [](const StringVersionControlPair &l,
const StringVersionControlPair &r) {
return l.first.size() > r.first.size();
});
if (allThatCanManage.isEmpty()) {
d->cache(0, QString(), directory); // register that nothing was found!
......
......@@ -35,6 +35,7 @@
#include "cppeditorplugin.h"
#include <coreplugin/find/treeviewfind.h>
#include <utils/algorithm.h>
#include <utils/navigationtreeview.h>
#include <utils/annotateditemdelegate.h>
......@@ -69,17 +70,14 @@ QStandardItem *itemForClass(const CppClass &cppClass)
return item;
}
bool compareCppClassNames(const CppClass &c1, const CppClass &c2)
{
const QString key1 = c1.name + QLatin1String("::") + c1.qualifiedName;
const QString key2 = c2.name + QLatin1String("::") + c2.qualifiedName;
return key1 < key2;
}
QList<CppClass> sortClasses(const QList<CppClass> &cppClasses)
{
QList<CppClass> sorted = cppClasses;
qSort(sorted.begin(), sorted.end(), compareCppClassNames);
Utils::sort(sorted, [](const CppClass &c1, const CppClass &c2) {
const QString key1 = c1.name + QLatin1String("::") + c1.qualifiedName;
const QString key2 = c2.name + QLatin1String("::") + c2.qualifiedName;
return key1 < key2;
});
return sorted;
}
......
......@@ -42,13 +42,13 @@
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <texteditor/basetextdocument.h>
#include <utils/algorithm.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/TranslationUnit.h>
#include <QDebug>
#include <QTextDocument>
#include <QtAlgorithms>
#include <QtTest>
#if QT_VERSION >= 0x050000
......@@ -168,7 +168,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
TestActionsTestCase::allProjectsConfigured = true;
}
qSort(filesToOpen);
Utils::sort(filesToOpen);
// Process all files from the projects
foreach (const QString filePath, filesToOpen) {
......
......@@ -31,6 +31,7 @@
#include "cpplocalsymbols.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
......@@ -330,7 +331,7 @@ void CheckSymbols::run()
_potentialFunctions = collectTypes.functions();
_potentialStatics = collectTypes.statics();
qSort(_macroUses.begin(), _macroUses.end(), sortByLinePredicate);
Utils::sort(_macroUses, sortByLinePredicate);
_doc->clearDiagnosticMessages();
if (!isCanceled()) {
......@@ -1415,7 +1416,7 @@ void CheckSymbols::flush()
if (_usages.isEmpty())
return;
qSort(_usages.begin(), _usages.end(), sortByLinePredicate);
Utils::sort(_usages, sortByLinePredicate);
reportResults(_usages);
int cap = _usages.capacity();
_usages.clear();
......
......@@ -33,6 +33,7 @@
#include <coreplugin/icore.h>
#include <cpptools/cppprojectfile.h>
#include <projectexplorer/project.h>
#include <utils/algorithm.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/Token.h>
......@@ -149,7 +150,7 @@ QString Utils::toString(const QList<ProjectFile> &projectFiles)
QStringList filesList;
foreach (const ProjectFile &projectFile, projectFiles)
filesList << QDir::toNativeSeparators(projectFile.path);
qSort(filesList);
::Utils::sort(filesList);
return filesList.join(QLatin1String("\n"));
}
......
......@@ -32,6 +32,7 @@
#include "ui_cppcodemodelsettingspage.h"
#include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <QTextStream>
......@@ -70,7 +71,7 @@ void CppCodeModelSettingsWidget::applyToWidget(QComboBox *chooser, const QString
chooser->clear();
QStringList names = m_settings->availableModelManagerSupportersByName().keys();
qSort(names);
Utils::sort(names);
foreach (const QString &name, names) {
const QString &id = m_settings->availableModelManagerSupportersByName()[name];
chooser->addItem(name, id);
......
......@@ -34,6 +34,7 @@
#include <cplusplus/PreprocessorClient.h>
#include <cplusplus/PreprocessorEnvironment.h>
#include <utils/algorithm.h>
#include <utils/stringutils.h>
#include <QDir>
......@@ -51,9 +52,6 @@ using namespace Utils;
namespace {
bool includeLineLessThan(const Include &left, const Include &right)
{ return left.line() < right.line(); }
bool includeFileNamelessThen(const Include & left, const Include & right)
{ return left.unresolvedFileName() < right.unresolvedFileName(); }
......@@ -293,7 +291,9 @@ QList<IncludeGroup> LineForNewIncludeDirective::getGroupsByIncludeType(
QList<IncludeGroup> IncludeGroup::detectIncludeGroupsByNewLines(QList<Document::Include> &includes)
{
// Sort by line
qSort(includes.begin(), includes.end(), includeLineLessThan);
Utils::sort(includes, [](const Include &left, const Include &right) {
return left.line() < right.line();
});
// Create groups
QList<IncludeGroup> result;
......
......@@ -35,6 +35,7 @@
#include <cplusplus/Overview.h>
#include <cplusplus/SymbolVisitor.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <QDir>
......@@ -48,12 +49,6 @@ Q_DECLARE_METATYPE(QList<Tests::TestDocument>)
namespace {
bool hierarchySorter(const TypeHierarchy &h1, const TypeHierarchy &h2)
{
Overview oo;
return oo.prettyName(h1.symbol()->name()) < oo.prettyName(h2.symbol()->name());
}
QString toString(const TypeHierarchy &hierarchy, int indent = 0)
{
Symbol *symbol = hierarchy.symbol();
......@@ -61,7 +56,10 @@ QString toString(const TypeHierarchy &hierarchy, int indent = 0)
+ Overview().prettyName(symbol->name()) + QLatin1Char('\n');
QList<TypeHierarchy> sortedHierarchy = hierarchy.hierarchy();
qSort(sortedHierarchy.begin(), sortedHierarchy.end(), hierarchySorter);
Overview oo;
Utils::sort(sortedHierarchy, [&oo](const TypeHierarchy &h1, const TypeHierarchy &h2) -> bool {
return oo.prettyName(h1.symbol()->name()) < oo.prettyName(h2.symbol()->name());
});
foreach (TypeHierarchy childHierarchy, sortedHierarchy)
result += toString(childHierarchy, indent + 2);
return result;
......
......@@ -31,6 +31,7 @@
#include "debuggercore.h"
#include "debuggerrunconfigurationaspect.h"
#include <utils/algorithm.h>
#include <utils/appmainwindow.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
......@@ -440,14 +441,11 @@ QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &langua
return dockWidget;
}
static bool sortCommands(Command *cmd1, Command *cmd2)
{
return cmd1->action()->text() < cmd2->action()->text();
}
void DebuggerMainWindow::addStagedMenuEntries()
{
qSort(d->m_menuCommandsToAdd.begin(), d->m_menuCommandsToAdd.end(), &sortCommands);
Utils::sort(d->m_menuCommandsToAdd, [](Command *cmd1, Command *cmd2) {
return cmd1->action()->text() < cmd2->action()->text();
});
foreach (Command *cmd, d->m_menuCommandsToAdd)
d->m_viewsMenu->addAction(cmd);
d->m_menuCommandsToAdd.clear();
......