forked from qt-creator/qt-creator
Utils: Add sorted() function
For simpler calling code. Change-Id: Ia0a16a28770fd172f74d06a626148248bf5d3c0c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -296,8 +296,7 @@ const Style *DefaultStyleEngine::applyObjectStyle(const Style *baseStyle, const
|
||||
}
|
||||
int depth = 0;
|
||||
if (!depths.isEmpty()) {
|
||||
QList<int> keys = depths.keys();
|
||||
Utils::sort(keys);
|
||||
const QList<int> keys = Utils::sorted(depths.keys());
|
||||
foreach (int d, keys) {
|
||||
DepthProperties properties = depths.value(d);
|
||||
if (properties.m_elementType == elementType
|
||||
|
@@ -1005,6 +1005,48 @@ inline void sort(Container &container, Predicate p)
|
||||
std::stable_sort(std::begin(container), std::end(container), p);
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
inline Container sorted(const Container &container)
|
||||
{
|
||||
Container c = container;
|
||||
sort(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
inline Container sorted(Container &&container)
|
||||
{
|
||||
sort(container);
|
||||
return container;
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
inline Container sorted(const Container &&container)
|
||||
{
|
||||
return sorted(container);
|
||||
}
|
||||
|
||||
template <typename Container, typename Predicate>
|
||||
inline Container sorted(const Container &container, Predicate p)
|
||||
{
|
||||
Container c = container;
|
||||
sort(c, p);
|
||||
return c;
|
||||
}
|
||||
|
||||
template <typename Container, typename Predicate>
|
||||
inline Container sorted(Container &&container, Predicate p)
|
||||
{
|
||||
sort(container, p);
|
||||
return container;
|
||||
}
|
||||
|
||||
template <typename Container, typename Predicate>
|
||||
inline Container sorted(const Container &&container, Predicate p)
|
||||
{
|
||||
return sorted(container, p);
|
||||
}
|
||||
|
||||
// pointer to member
|
||||
template <typename Container, typename R, typename S>
|
||||
inline void sort(Container &container, R S::*member)
|
||||
@@ -1017,6 +1059,27 @@ inline void sort(Container &container, R S::*member)
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Container, typename R, typename S>
|
||||
inline Container sorted(const Container &container, R S::*member)
|
||||
{
|
||||
Container c = container;
|
||||
sort(c, member);
|
||||
return c;
|
||||
}
|
||||
|
||||
template <typename Container, typename R, typename S>
|
||||
inline Container sorted(Container &&container, R S::*member)
|
||||
{
|
||||
sort(container, member);
|
||||
return container;
|
||||
}
|
||||
|
||||
template <typename Container, typename R, typename S>
|
||||
inline Container sorted(const Container &&container, R S::*member)
|
||||
{
|
||||
return sorted(container, member);
|
||||
}
|
||||
|
||||
// pointer to member function
|
||||
template <typename Container, typename R, typename S>
|
||||
inline void sort(Container &container, R (S::*function)() const)
|
||||
@@ -1029,6 +1092,27 @@ inline void sort(Container &container, R (S::*function)() const)
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Container, typename R, typename S>
|
||||
inline Container sorted(const Container &container, R (S::*function)() const)
|
||||
{
|
||||
Container c = container;
|
||||
sort(c, function);
|
||||
return c;
|
||||
}
|
||||
|
||||
template <typename Container, typename R, typename S>
|
||||
inline Container sorted(Container &&container, R (S::*function)() const)
|
||||
{
|
||||
sort(container, function);
|
||||
return container;
|
||||
}
|
||||
|
||||
template <typename Container, typename R, typename S>
|
||||
inline Container sorted(const Container &&container, R (S::*function)() const)
|
||||
{
|
||||
return sorted(container, function);
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// reverseForeach
|
||||
/////////////////
|
||||
|
@@ -62,9 +62,8 @@ QTCREATOR_UTILS_EXPORT void writeBeginQtVersionCheck(QTextStream &str)
|
||||
|
||||
static void qtSection(const QStringList &qtIncludes, QTextStream &str)
|
||||
{
|
||||
QStringList sorted = qtIncludes;
|
||||
sort(sorted);
|
||||
for (const QString &inc : std::as_const(sorted)) {
|
||||
const QStringList sorted = Utils::sorted(qtIncludes);
|
||||
for (const QString &inc : sorted) {
|
||||
if (!inc.isEmpty())
|
||||
str << QStringLiteral("#include <%1>\n").arg(inc);
|
||||
}
|
||||
|
@@ -224,9 +224,7 @@ QSet<Id> Id::fromStringList(const QStringList &list)
|
||||
|
||||
QStringList Id::toStringList(const QSet<Id> &ids)
|
||||
{
|
||||
QList<Id> idList = toList(ids);
|
||||
sort(idList);
|
||||
return transform(idList, &Id::toString);
|
||||
return transform(sorted(toList(ids)), &Id::toString);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@@ -110,8 +110,7 @@ bool MultiTextCursor::hasSelection() const
|
||||
QString MultiTextCursor::selectedText() const
|
||||
{
|
||||
QString text;
|
||||
QList<QTextCursor> cursors = m_cursors;
|
||||
Utils::sort(cursors);
|
||||
const QList<QTextCursor> cursors = Utils::sorted(m_cursors);
|
||||
for (const QTextCursor &cursor : cursors) {
|
||||
const QString &cursorText = cursor.selectedText();
|
||||
if (cursorText.isEmpty())
|
||||
@@ -159,8 +158,7 @@ void MultiTextCursor::insertText(const QString &text, bool selectNewText)
|
||||
lines.pop_back();
|
||||
int index = 0;
|
||||
if (lines.count() == m_cursors.count()) {
|
||||
QList<QTextCursor> cursors = m_cursors;
|
||||
Utils::sort(cursors);
|
||||
QList<QTextCursor> cursors = Utils::sorted(m_cursors);
|
||||
for (QTextCursor &cursor : cursors)
|
||||
insertAndSelect(cursor, lines.at(index++), selectNewText);
|
||||
m_cursors.last().endEditBlock();
|
||||
|
@@ -386,9 +386,8 @@ void Wizard::showVariables()
|
||||
{
|
||||
QString result = QLatin1String("<table>\n <tr><td>Key</td><td>Type</td><td>Value</td><td>Eval</td></tr>\n");
|
||||
QHash<QString, QVariant> vars = variables();
|
||||
QList<QString> keys = vars.keys();
|
||||
sort(keys);
|
||||
for (const QString &key : std::as_const(keys)) {
|
||||
const QList<QString> keys = sorted(vars.keys());
|
||||
for (const QString &key : keys) {
|
||||
const QVariant &v = vars.value(key);
|
||||
result += QLatin1String(" <tr><td>")
|
||||
+ key + QLatin1String("</td><td>")
|
||||
|
@@ -395,8 +395,7 @@ static QList<int> availableNdkPlatformsImpl(const FilePath &ndkLocation, const A
|
||||
if (result.isEmpty())
|
||||
result = availableNdkPlatformsV21Plus(ndkLocation, abis, hostOs);
|
||||
|
||||
Utils::sort(result, std::greater<>());
|
||||
return result;
|
||||
return Utils::sorted(std::move(result), std::greater<>());
|
||||
}
|
||||
|
||||
QList<int> AndroidConfig::availableNdkPlatforms(const QtVersion *qtVersion) const
|
||||
|
@@ -1553,8 +1553,7 @@ PermissionsModel::PermissionsModel(QObject *parent)
|
||||
void PermissionsModel::setPermissions(const QStringList &permissions)
|
||||
{
|
||||
beginResetModel();
|
||||
m_permissions = permissions;
|
||||
Utils::sort(m_permissions);
|
||||
m_permissions = Utils::sorted(permissions);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
@@ -127,9 +127,7 @@ AndroidDeviceInfoList parseAvdList(const QString &output, QStringList *avdErrorP
|
||||
}
|
||||
}
|
||||
|
||||
Utils::sort(avdList);
|
||||
|
||||
return avdList;
|
||||
return Utils::sorted(std::move(avdList));
|
||||
}
|
||||
|
||||
int platformNameToApiLevel(const QString &platformName)
|
||||
|
@@ -100,8 +100,8 @@ ProjectTestSettingsWidget::ProjectTestSettingsWidget(ProjectExplorer::Project *p
|
||||
void ProjectTestSettingsWidget::populateFrameworks(const QHash<ITestFramework *, bool> &frameworks,
|
||||
const QHash<ITestTool *, bool> &testTools)
|
||||
{
|
||||
TestFrameworks sortedFrameworks = frameworks.keys();
|
||||
Utils::sort(sortedFrameworks, &ITestFramework::priority);
|
||||
const TestFrameworks sortedFrameworks = Utils::sorted(frameworks.keys(),
|
||||
&ITestFramework::priority);
|
||||
|
||||
auto generateItem = [this](ITestBase *frameworkOrTestTool, bool checked) {
|
||||
auto item = new QTreeWidgetItem(m_activeFrameworks, {frameworkOrTestTool->displayName()});
|
||||
@@ -111,7 +111,7 @@ void ProjectTestSettingsWidget::populateFrameworks(const QHash<ITestFramework *,
|
||||
item->setData(0, BaseTypeRole, frameworkOrTestTool->type());
|
||||
};
|
||||
|
||||
for (ITestFramework *framework : std::as_const(sortedFrameworks))
|
||||
for (ITestFramework *framework : sortedFrameworks)
|
||||
generateItem(framework, frameworks.value(framework));
|
||||
|
||||
// FIXME: testTools aren't sorted and we cannot use priority here
|
||||
|
@@ -135,8 +135,8 @@ void TestCodeParser::updateTestTree(const QSet<ITestParser *> &parsers)
|
||||
|
||||
m_postponedUpdateType = UpdateType::NoUpdate;
|
||||
qCDebug(LOG) << "calling scanForTests (updateTestTree)";
|
||||
QList<ITestParser *> sortedParsers = Utils::toList(parsers);
|
||||
Utils::sort(sortedParsers, [](const ITestParser *lhs, const ITestParser *rhs) {
|
||||
const QList<ITestParser *> sortedParsers = Utils::sorted(Utils::toList(parsers),
|
||||
[](const ITestParser *lhs, const ITestParser *rhs) {
|
||||
return lhs->framework()->priority() < rhs->framework()->priority();
|
||||
});
|
||||
scanForTests(Utils::FilePaths(), sortedParsers);
|
||||
|
@@ -110,10 +110,9 @@ void PreconfiguredSessionTests::testPreconfiguredSession()
|
||||
|
||||
static const QList<Project *> validProjects(const QList<Project *> projectsOfSession)
|
||||
{
|
||||
QList<Project *> sortedProjects = projectsOfSession;
|
||||
Utils::sort(sortedProjects, [](Project *lhs, Project *rhs){
|
||||
return lhs->displayName() < rhs->displayName();
|
||||
});
|
||||
const QList<Project *> sortedProjects = Utils::sorted(projectsOfSession,
|
||||
[](Project *lhs, Project *rhs) { return lhs->displayName() < rhs->displayName(); }
|
||||
);
|
||||
|
||||
const auto isValidProject = [](Project *project) {
|
||||
const QList <Target *> targets = project->targets();
|
||||
@@ -129,10 +128,9 @@ static const QList<Project *> validProjects(const QList<Project *> projectsOfSes
|
||||
|
||||
static QList<Target *> validTargets(Project *project)
|
||||
{
|
||||
QList<Target *> sortedTargets = project->targets();
|
||||
Utils::sort(sortedTargets, [](Target *lhs, Target *rhs){
|
||||
return lhs->displayName() < rhs->displayName();
|
||||
});
|
||||
const QList<Target *> sortedTargets = Utils::sorted(project->targets(),
|
||||
[](Target *lhs, Target *rhs) { return lhs->displayName() < rhs->displayName(); }
|
||||
);
|
||||
|
||||
const QString projectFileName = project->projectFilePath().fileName();
|
||||
const auto isValidTarget = [projectFileName](Target *target) {
|
||||
|
@@ -50,14 +50,13 @@ class FilterChecksModel : public Utils::TreeModel<Utils::TreeItem, CheckItem>
|
||||
public:
|
||||
FilterChecksModel(const Checks &checks)
|
||||
{
|
||||
Checks sortedChecks = checks;
|
||||
Utils::sort(sortedChecks, [](const Check &lhs, const Check &rhs) {
|
||||
const Checks sortedChecks = Utils::sorted(checks, [](const Check &lhs, const Check &rhs) {
|
||||
return lhs.displayName < rhs.displayName;
|
||||
});
|
||||
|
||||
setHeader({tr("Check"), "#"});
|
||||
setRootItem(new Utils::StaticTreeItem(QString()));
|
||||
for (const Check &check : std::as_const(sortedChecks))
|
||||
for (const Check &check : sortedChecks)
|
||||
m_root->appendChild(new CheckItem(check));
|
||||
}
|
||||
};
|
||||
|
@@ -389,9 +389,7 @@ CMakeConfig CMakeConfig::fromFile(const Utils::FilePath &cacheFile, QString *err
|
||||
}
|
||||
}
|
||||
|
||||
Utils::sort(result, &CMakeConfigItem::less);
|
||||
|
||||
return result;
|
||||
return Utils::sorted(std::move(result), &CMakeConfigItem::less);
|
||||
}
|
||||
|
||||
QString CMakeConfigItem::toString(const Utils::MacroExpander *expander) const
|
||||
|
@@ -433,8 +433,8 @@ private:
|
||||
|
||||
cmakeLabel->setText(m_currentTool->cmakeExecutable().toUserOutput());
|
||||
|
||||
QList<CMakeTool::Generator> generatorList = m_currentTool->supportedGenerators();
|
||||
Utils::sort(generatorList, &CMakeTool::Generator::name);
|
||||
const QList<CMakeTool::Generator> generatorList = Utils::sorted(
|
||||
m_currentTool->supportedGenerators(), &CMakeTool::Generator::name);
|
||||
|
||||
for (auto it = generatorList.constBegin(); it != generatorList.constEnd(); ++it)
|
||||
generatorCombo->addItem(it->name);
|
||||
|
@@ -459,8 +459,8 @@ void CMakeTool::parseFunctionDetailsOutput(const QString &output)
|
||||
if (!words.isEmpty()) {
|
||||
const QString command = words.takeFirst();
|
||||
if (functionSet.contains(command)) {
|
||||
QStringList tmp = words + m_introspection->m_functionArgs[command];
|
||||
Utils::sort(tmp);
|
||||
const QStringList tmp = Utils::sorted(
|
||||
words + m_introspection->m_functionArgs[command]);
|
||||
m_introspection->m_functionArgs[command] = Utils::filteredUnique(tmp);
|
||||
}
|
||||
}
|
||||
|
@@ -52,13 +52,12 @@ CodecSelector::CodecSelector(QWidget *parent, Core::BaseTextDocument *doc)
|
||||
|
||||
QStringList encodings;
|
||||
|
||||
QList<int> mibs = QTextCodec::availableMibs();
|
||||
Utils::sort(mibs);
|
||||
const QList<int> mibs = Utils::sorted(QTextCodec::availableMibs());
|
||||
QList<int> sortedMibs;
|
||||
for (const int mib : std::as_const(mibs))
|
||||
for (const int mib : mibs)
|
||||
if (mib >= 0)
|
||||
sortedMibs += mib;
|
||||
for (const int mib : std::as_const(mibs))
|
||||
for (const int mib : mibs)
|
||||
if (mib < 0)
|
||||
sortedMibs += mib;
|
||||
|
||||
|
@@ -1709,8 +1709,8 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
|
||||
// When handling the last view in the list we handle the case where all
|
||||
// visible editors are closed, and we need to e.g. revive an invisible or
|
||||
// a suspended editor
|
||||
QList<EditorView *> views = editorsPerView.keys();
|
||||
Utils::sort(views, [editorsPerView, currentView](EditorView *a, EditorView *b) {
|
||||
const QList<EditorView *> views = Utils::sorted(editorsPerView.keys(),
|
||||
[editorsPerView, currentView](EditorView *a, EditorView *b) {
|
||||
if (a == b)
|
||||
return false;
|
||||
const bool aHasCurrent = editorsPerView.values(a).contains(a->currentEditor());
|
||||
@@ -1723,7 +1723,7 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
for (EditorView *view : std::as_const(views)) {
|
||||
for (EditorView *view : views) {
|
||||
QList<IEditor *> editors = editorsPerView.values(view);
|
||||
// handle current editor in view last
|
||||
IEditor *viewCurrentEditor = view->currentEditor();
|
||||
|
@@ -438,8 +438,7 @@ void BaseTextFind::defineFindScope()
|
||||
for (const QTextCursor &c : multiCursor) {
|
||||
if (c.hasSelection()) {
|
||||
if (foundSelection || c.block() != c.document()->findBlock(c.anchor())) {
|
||||
QList<QTextCursor> sortedCursors = multiCursor.cursors();
|
||||
Utils::sort(sortedCursors);
|
||||
const QList<QTextCursor> sortedCursors = Utils::sorted(multiCursor.cursors());
|
||||
d->m_scope = Utils::MultiTextCursor(sortedCursors);
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.clearSelection();
|
||||
|
@@ -299,9 +299,9 @@ void FindPrivate::setupFilterMenuItems()
|
||||
ActionContainer *mfindadvanced = ActionManager::actionContainer(Constants::M_FIND_ADVANCED);
|
||||
bool haveEnabledFilters = false;
|
||||
const Id base("FindFilter.");
|
||||
QList<IFindFilter *> sortedFilters = IFindFilter::allFindFilters();
|
||||
Utils::sort(sortedFilters, &IFindFilter::displayName);
|
||||
for (IFindFilter *filter : std::as_const(sortedFilters)) {
|
||||
const QList<IFindFilter *> sortedFilters = Utils::sorted(IFindFilter::allFindFilters(),
|
||||
&IFindFilter::displayName);
|
||||
for (IFindFilter *filter : sortedFilters) {
|
||||
QAction *action = new QAction(filterActionName(filter), this);
|
||||
bool isEnabled = filter->isEnabled();
|
||||
if (isEnabled)
|
||||
|
@@ -244,9 +244,8 @@ void GeneralSettingsWidget::fillCodecBox() const
|
||||
{
|
||||
const QByteArray currentCodec = codecForLocale();
|
||||
|
||||
QByteArrayList codecs = QTextCodec::availableCodecs();
|
||||
Utils::sort(codecs);
|
||||
for (const QByteArray &codec : std::as_const(codecs)) {
|
||||
const QByteArrayList codecs = Utils::sorted(QTextCodec::availableCodecs());
|
||||
for (const QByteArray &codec : codecs) {
|
||||
m_codecBox->addItem(QString::fromLocal8Bit(codec));
|
||||
if (codec == currentCodec)
|
||||
m_codecBox->setCurrentIndex(m_codecBox->count() - 1);
|
||||
|
@@ -126,8 +126,8 @@ void Locator::initialize()
|
||||
|
||||
void Locator::extensionsInitialized()
|
||||
{
|
||||
m_filters = ILocatorFilter::allLocatorFilters();
|
||||
Utils::sort(m_filters, [](const ILocatorFilter *first, const ILocatorFilter *second) -> bool {
|
||||
m_filters = Utils::sorted(ILocatorFilter::allLocatorFilters(),
|
||||
[](const ILocatorFilter *first, const ILocatorFilter *second) -> bool {
|
||||
if (first->priority() != second->priority())
|
||||
return first->priority() < second->priority();
|
||||
return first->id().alphabeticallyBefore(second->id());
|
||||
|
@@ -196,9 +196,9 @@ Qt::ItemFlags MimeTypeSettingsModel::flags(const QModelIndex &index) const
|
||||
void MimeTypeSettingsModel::load()
|
||||
{
|
||||
beginResetModel();
|
||||
m_mimeTypes = Utils::allMimeTypes();
|
||||
m_userDefault = Core::Internal::userPreferredEditorTypes();
|
||||
Utils::sort(m_mimeTypes, [](const Utils::MimeType &a, const Utils::MimeType &b) {
|
||||
m_mimeTypes = Utils::sorted(Utils::allMimeTypes(),
|
||||
[](const Utils::MimeType &a, const Utils::MimeType &b) {
|
||||
return a.name().compare(b.name(), Qt::CaseInsensitive) < 0;
|
||||
});
|
||||
m_handlersByMimeType.clear();
|
||||
|
@@ -64,11 +64,10 @@ SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &id)
|
||||
setLayout(lay);
|
||||
lay->addWidget(m_toolbar);
|
||||
|
||||
QStringList titleList = m_sideBar->availableItemTitles();
|
||||
Utils::sort(titleList);
|
||||
const QStringList titleList = Utils::sorted(m_sideBar->availableItemTitles());
|
||||
QString t = id;
|
||||
if (!titleList.isEmpty()) {
|
||||
for (const QString &itemTitle : std::as_const(titleList))
|
||||
for (const QString &itemTitle : titleList)
|
||||
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
|
||||
|
||||
m_comboBox->setCurrentIndex(0);
|
||||
|
@@ -60,8 +60,7 @@ void ParseContextModel::reset(const ProjectPartInfo &projectPartInfo)
|
||||
{
|
||||
// Sort
|
||||
m_hints = projectPartInfo.hints;
|
||||
m_projectParts = projectPartInfo.projectParts;
|
||||
Utils::sort(m_projectParts, &ProjectPart::displayName);
|
||||
m_projectParts = Utils::sorted(projectPartInfo.projectParts, &ProjectPart::displayName);
|
||||
|
||||
// Determine index for current
|
||||
const QString id = projectPartInfo.projectPart->id();
|
||||
|
@@ -53,13 +53,11 @@ QStandardItem *itemForClass(const CppClass &cppClass)
|
||||
|
||||
QList<CppClass> sortClasses(const QList<CppClass> &cppClasses)
|
||||
{
|
||||
QList<CppClass> sorted = cppClasses;
|
||||
sort(sorted, [](const CppClass &c1, const CppClass &c2) -> bool {
|
||||
return sorted(cppClasses, [](const CppClass &c1, const CppClass &c2) -> bool {
|
||||
const QString key1 = c1.name + QLatin1String("::") + c1.qualifiedName;
|
||||
const QString key2 = c2.name + QLatin1String("::") + c2.qualifiedName;
|
||||
return key1 < key2;
|
||||
});
|
||||
return sorted;
|
||||
}
|
||||
|
||||
} // Anonymous
|
||||
|
@@ -111,13 +111,13 @@ LineForNewIncludeDirective::LineForNewIncludeDirective(const QTextDocument *text
|
||||
, m_cppDocument(cppDocument)
|
||||
, m_includeStyle(includeStyle)
|
||||
{
|
||||
QList<Document::Include> includes
|
||||
= cppDocument->resolvedIncludes() + cppDocument->unresolvedIncludes();
|
||||
Utils::sort(includes, &Include::line);
|
||||
const QList<Document::Include> includes = Utils::sorted(
|
||||
cppDocument->resolvedIncludes() + cppDocument->unresolvedIncludes(),
|
||||
&Include::line);
|
||||
|
||||
// Ignore *.moc includes if requested
|
||||
if (mocIncludeMode == IgnoreMocIncludes) {
|
||||
for (const Document::Include &include : std::as_const(includes)) {
|
||||
for (const Document::Include &include : includes) {
|
||||
if (!include.unresolvedFileName().endsWith(QLatin1String(".moc")))
|
||||
m_includes << include;
|
||||
}
|
||||
|
@@ -29,9 +29,9 @@ QString toString(const TypeHierarchy &hierarchy, int indent = 0)
|
||||
QString result = QString(indent, QLatin1Char(' '))
|
||||
+ Overview().prettyName(symbol->name()) + QLatin1Char('\n');
|
||||
|
||||
QList<TypeHierarchy> sortedHierarchy = hierarchy.hierarchy();
|
||||
Overview oo;
|
||||
Utils::sort(sortedHierarchy, [&oo](const TypeHierarchy &h1, const TypeHierarchy &h2) -> bool {
|
||||
const QList<TypeHierarchy> sortedHierarchy = Utils::sorted(hierarchy.hierarchy(),
|
||||
[&oo](const TypeHierarchy &h1, const TypeHierarchy &h2) -> bool {
|
||||
return oo.prettyName(h1.symbol()->name()) < oo.prettyName(h2.symbol()->name());
|
||||
});
|
||||
for (const TypeHierarchy &childHierarchy : std::as_const(sortedHierarchy))
|
||||
|
@@ -794,10 +794,9 @@ int GdbEngine::commandTimeoutTime() const
|
||||
|
||||
void GdbEngine::commandTimeout()
|
||||
{
|
||||
QList<int> keys = m_commandForToken.keys();
|
||||
Utils::sort(keys);
|
||||
const QList<int> keys = Utils::sorted(m_commandForToken.keys());
|
||||
bool killIt = false;
|
||||
for (int key : std::as_const(keys)) {
|
||||
for (int key : keys) {
|
||||
const DebuggerCommand &cmd = m_commandForToken.value(key);
|
||||
killIt = true;
|
||||
showMessage(QString::number(key) + ": " + cmd.function);
|
||||
|
@@ -372,8 +372,7 @@ QList<int> StashDialog::selectedRows() const
|
||||
if (index.isValid())
|
||||
rc.push_back(index.row());
|
||||
}
|
||||
Utils::sort(rc);
|
||||
return rc;
|
||||
return Utils::sorted(std::move(rc));
|
||||
}
|
||||
|
||||
void StashDialog::forceRefresh()
|
||||
|
@@ -326,11 +326,9 @@ void DocSettingsPageWidget::removeDocumentation(const QList<QModelIndex> &items)
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
|
||||
QList<QModelIndex> itemsByDecreasingRow = items;
|
||||
Utils::sort(itemsByDecreasingRow, [](const QModelIndex &i1, const QModelIndex &i2) {
|
||||
return i1.row() > i2.row();
|
||||
});
|
||||
for (const QModelIndex &item : std::as_const(itemsByDecreasingRow)) {
|
||||
const QList<QModelIndex> itemsByDecreasingRow = Utils::sorted(items,
|
||||
[](const QModelIndex &i1, const QModelIndex &i2) { return i1.row() > i2.row(); });
|
||||
for (const QModelIndex &item : itemsByDecreasingRow) {
|
||||
const int row = item.row();
|
||||
const QString nameSpace = m_model.entryAt(row).nameSpace;
|
||||
|
||||
|
@@ -30,19 +30,15 @@ namespace LanguageClient {
|
||||
|
||||
const QList<SymbolInformation> sortedSymbols(const QList<SymbolInformation> &symbols)
|
||||
{
|
||||
auto result = symbols;
|
||||
Utils::sort(result, [](const SymbolInformation &a, const SymbolInformation &b){
|
||||
return Utils::sorted(symbols, [](const SymbolInformation &a, const SymbolInformation &b){
|
||||
return a.location().range().start() < b.location().range().start();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
const QList<DocumentSymbol> sortedSymbols(const QList<DocumentSymbol> &symbols)
|
||||
{
|
||||
auto result = symbols;
|
||||
Utils::sort(result, [](const DocumentSymbol &a, const DocumentSymbol &b){
|
||||
return Utils::sorted(symbols, [](const DocumentSymbol &a, const DocumentSymbol &b){
|
||||
return a.range().start() < b.range().start();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
class LanguageClientOutlineItem : public Utils::TypedTreeItem<LanguageClientOutlineItem>
|
||||
|
@@ -352,14 +352,13 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
|
||||
qCDebug(LOGLSPHIGHLIGHT) << "New Data " << tokens->data();
|
||||
} else if (auto tokensDelta = std::get_if<SemanticTokensDelta>(&result)) {
|
||||
m_tokens[filePath].version = documentVersion;
|
||||
QList<SemanticTokensEdit> edits = tokensDelta->edits();
|
||||
const QList<SemanticTokensEdit> edits = Utils::sorted(tokensDelta->edits(),
|
||||
&SemanticTokensEdit::start);
|
||||
if (edits.isEmpty()) {
|
||||
highlight(filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::sort(edits, &SemanticTokensEdit::start);
|
||||
|
||||
SemanticTokens &tokens = m_tokens[filePath].tokens;
|
||||
const QList<int> &data = tokens.data();
|
||||
|
||||
|
@@ -256,9 +256,8 @@ Tasks Kit::validate() const
|
||||
d->m_hasError = containsType(result, Task::TaskType::Error);
|
||||
d->m_hasWarning = containsType(result, Task::TaskType::Warning);
|
||||
|
||||
Utils::sort(result);
|
||||
d->m_hasValidityInfo = true;
|
||||
return result;
|
||||
return Utils::sorted(std::move(result));
|
||||
}
|
||||
|
||||
void Kit::fix()
|
||||
|
@@ -200,8 +200,7 @@ public:
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setColumnStretch(1, 2);
|
||||
|
||||
QList<Id> languageList = ToolChainManager::allLanguages();
|
||||
sort(languageList, [](Id l1, Id l2) {
|
||||
const QList<Id> languageList = sorted(ToolChainManager::allLanguages(), [](Id l1, Id l2) {
|
||||
return ToolChainManager::displayNameOfLanguageId(l1)
|
||||
< ToolChainManager::displayNameOfLanguageId(l2);
|
||||
});
|
||||
@@ -1449,9 +1448,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
sort(changes, [](const EnvironmentItem &lhs, const EnvironmentItem &rhs)
|
||||
return sorted(std::move(changes), [](const EnvironmentItem &lhs, const EnvironmentItem &rhs)
|
||||
{ return QString::localeAwareCompare(lhs.name, rhs.name) < 0; });
|
||||
return changes;
|
||||
}
|
||||
|
||||
void initMSVCOutputSwitch(QVBoxLayout *layout)
|
||||
|
@@ -144,9 +144,8 @@ QString MakeStep::defaultDisplayName()
|
||||
|
||||
static const QList<ToolChain *> preferredToolChains(const Kit *kit)
|
||||
{
|
||||
QList<ToolChain *> tcs = ToolChainKitAspect::toolChains(kit);
|
||||
// prefer CXX, then C, then others
|
||||
Utils::sort(tcs, [](ToolChain *tcA, ToolChain *tcB) {
|
||||
return Utils::sorted(ToolChainKitAspect::toolChains(kit), [](ToolChain *tcA, ToolChain *tcB) {
|
||||
if (tcA->language() == tcB->language())
|
||||
return false;
|
||||
if (tcA->language() == Constants::CXX_LANGUAGE_ID)
|
||||
@@ -157,7 +156,6 @@ static const QList<ToolChain *> preferredToolChains(const Kit *kit)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
return tcs;
|
||||
}
|
||||
|
||||
FilePath MakeStep::defaultMakeCommand() const
|
||||
|
@@ -723,8 +723,7 @@ void FolderNode::setIcon(const IconCreator &iconCreator)
|
||||
|
||||
void FolderNode::setLocationInfo(const QVector<FolderNode::LocationInfo> &info)
|
||||
{
|
||||
m_locations = info;
|
||||
Utils::sort(m_locations, &LocationInfo::priority);
|
||||
m_locations = Utils::sorted(info, &LocationInfo::priority);
|
||||
}
|
||||
|
||||
const QVector<FolderNode::LocationInfo> FolderNode::locationInfo() const
|
||||
|
@@ -463,11 +463,9 @@ bool TargetSetupPage::compareKits(const Kit *k1, const Kit *k2)
|
||||
|
||||
std::vector<TargetSetupWidget *> TargetSetupPage::sortedWidgetList() const
|
||||
{
|
||||
std::vector<TargetSetupWidget *> list = m_widgets;
|
||||
sort(list, [](const TargetSetupWidget *w1, const TargetSetupWidget *w2) {
|
||||
return sorted(m_widgets, [](const TargetSetupWidget *w1, const TargetSetupWidget *w2) {
|
||||
return compareKits(w1->kit(), w2->kit());
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
void TargetSetupPage::openOptions()
|
||||
|
@@ -271,12 +271,11 @@ void QmakeBuildConfiguration::updateProblemLabel()
|
||||
allGood = false;
|
||||
|
||||
if (allGood) {
|
||||
Tasks issues = version->reportIssues(proFileName, buildDirectory().toString());
|
||||
Utils::sort(issues);
|
||||
|
||||
const Tasks issues = Utils::sorted(
|
||||
version->reportIssues(proFileName, buildDirectory().toString()));
|
||||
if (!issues.isEmpty()) {
|
||||
QString text = QLatin1String("<nobr>");
|
||||
for (const ProjectExplorer::Task &task : std::as_const(issues)) {
|
||||
for (const ProjectExplorer::Task &task : issues) {
|
||||
QString type;
|
||||
switch (task.type) {
|
||||
case ProjectExplorer::Task::Error:
|
||||
|
@@ -243,12 +243,11 @@ bool QMakeStep::init()
|
||||
QTC_ASSERT(node, return false);
|
||||
QString proFile = node->filePath().toString();
|
||||
|
||||
Tasks tasks = qtVersion->reportIssues(proFile, workingDirectory.toString());
|
||||
Utils::sort(tasks);
|
||||
|
||||
const Tasks tasks = Utils::sorted(
|
||||
qtVersion->reportIssues(proFile, workingDirectory.toString()));
|
||||
if (!tasks.isEmpty()) {
|
||||
bool canContinue = true;
|
||||
for (const Task &t : std::as_const(tasks)) {
|
||||
for (const Task &t : tasks) {
|
||||
emit addTask(t);
|
||||
if (t.type == Task::Error)
|
||||
canContinue = false;
|
||||
|
@@ -351,13 +351,14 @@ void QmlJSEditorWidget::updateUses()
|
||||
return;
|
||||
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
QList<SourceLocation> locations
|
||||
= m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor());
|
||||
|
||||
// code model may present the locations not in a document order
|
||||
Utils::sort(locations, [](const SourceLocation &lhs, const SourceLocation &rhs) {
|
||||
const QList<SourceLocation> locations = Utils::sorted(
|
||||
m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor()),
|
||||
[](const SourceLocation &lhs, const SourceLocation &rhs) {
|
||||
return lhs.begin() < rhs.begin();
|
||||
});
|
||||
for (const SourceLocation &loc : std::as_const(locations)) {
|
||||
for (const SourceLocation &loc : locations) {
|
||||
if (! loc.isValid())
|
||||
continue;
|
||||
|
||||
|
@@ -53,8 +53,7 @@ QList<ProcessInfo> QnxDeviceProcessList::buildProcessList(const QString &listPro
|
||||
}
|
||||
}
|
||||
|
||||
Utils::sort(processes);
|
||||
return processes;
|
||||
return Utils::sorted(std::move(processes));
|
||||
}
|
||||
|
||||
} // Qnx::Internal
|
||||
|
@@ -67,10 +67,8 @@ static Abis detectTargetAbis(const FilePath &sdpPath)
|
||||
result.append(target.m_abi);
|
||||
}
|
||||
|
||||
Utils::sort(result,
|
||||
return Utils::sorted(std::move(result),
|
||||
[](const Abi &arg1, const Abi &arg2) { return arg1.toString() < arg2.toString(); });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void setQnxEnvironment(Environment &env, const EnvironmentItems &qnxEnv)
|
||||
|
@@ -874,8 +874,7 @@ QString QtVersion::toHtml(bool verbose) const
|
||||
if (verbose) {
|
||||
const QHash<ProKey, ProString> vInfo = d->versionInfo();
|
||||
if (!vInfo.isEmpty()) {
|
||||
QList<ProKey> keys = vInfo.keys();
|
||||
Utils::sort(keys);
|
||||
const QList<ProKey> keys = Utils::sorted(vInfo.keys());
|
||||
foreach (const ProKey &key, keys) {
|
||||
const QString &value = vInfo.value(key).toQString();
|
||||
QString variableName = key.toQString();
|
||||
@@ -1685,9 +1684,7 @@ bool QtVersion::supportsMultipleQtAbis() const
|
||||
|
||||
Tasks QtVersion::reportIssues(const QString &proFile, const QString &buildDir) const
|
||||
{
|
||||
Tasks results = reportIssuesImpl(proFile, buildDir);
|
||||
Utils::sort(results);
|
||||
return results;
|
||||
return Utils::sorted(reportIssuesImpl(proFile, buildDir));
|
||||
}
|
||||
|
||||
QtConfigWidget *QtVersion::createConfigurationWidget() const
|
||||
@@ -2274,8 +2271,8 @@ QtVersion *QtVersionFactory::createQtVersionFromQMakePath
|
||||
ProFileEvaluator evaluator(&globals, &parser, &vfs, &msgHandler);
|
||||
evaluator.loadNamedSpec(mkspec.path(), false);
|
||||
|
||||
QList<QtVersionFactory *> factories = g_qtVersionFactories;
|
||||
Utils::sort(factories, [](const QtVersionFactory *l, const QtVersionFactory *r) {
|
||||
const QList<QtVersionFactory *> factories = Utils::sorted(g_qtVersionFactories,
|
||||
[](const QtVersionFactory *l, const QtVersionFactory *r) {
|
||||
return l->m_priority > r->m_priority;
|
||||
});
|
||||
|
||||
|
@@ -537,9 +537,7 @@ QtVersions QtVersionManager::versions(const QtVersion::Predicate &predicate)
|
||||
|
||||
QtVersions QtVersionManager::sortVersions(const QtVersions &input)
|
||||
{
|
||||
QtVersions result = input;
|
||||
Utils::sort(result, qtVersionNumberCompare);
|
||||
return result;
|
||||
return Utils::sorted(input, qtVersionNumberCompare);
|
||||
}
|
||||
|
||||
QtVersion *QtVersionManager::version(int id)
|
||||
@@ -566,8 +564,7 @@ void QtVersionManager::setNewQtVersions(const QtVersions &newVersions)
|
||||
{
|
||||
// We want to preserve the same order as in the settings dialog
|
||||
// so we sort a copy
|
||||
QtVersions sortedNewVersions = newVersions;
|
||||
Utils::sort(sortedNewVersions, &QtVersion::uniqueId);
|
||||
const QtVersions sortedNewVersions = Utils::sorted(newVersions, &QtVersion::uniqueId);
|
||||
|
||||
QtVersions addedVersions;
|
||||
QtVersions removedVersions;
|
||||
|
@@ -340,8 +340,7 @@ private:
|
||||
processes.append(process);
|
||||
}
|
||||
|
||||
Utils::sort(processes);
|
||||
return processes;
|
||||
return Utils::sorted(std::move(processes));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1150,8 +1149,7 @@ static FilePaths dirsToCreate(const FilesToTransfer &files)
|
||||
parentDir = parentDir.parentDir();
|
||||
}
|
||||
}
|
||||
sort(dirs);
|
||||
return dirs;
|
||||
return sorted(std::move(dirs));
|
||||
}
|
||||
|
||||
static QByteArray transferCommand(const FileTransferDirection direction, bool link)
|
||||
|
@@ -85,12 +85,11 @@ QByteArray ObjectsMapTreeItem::propertiesToByteArray() const
|
||||
return propertiesContent();
|
||||
|
||||
QByteArray result;
|
||||
PropertyList properties = this->properties();
|
||||
sort(properties,
|
||||
const PropertyList properties = sorted(this->properties(),
|
||||
[](const Property &lhs, const Property &rhs) { return lhs.m_name < rhs.m_name; });
|
||||
|
||||
result.append('{');
|
||||
for (const Property &property : std::as_const(properties))
|
||||
for (const Property &property : properties)
|
||||
result.append(property.toString().toUtf8()).append(' ');
|
||||
if (result.at(result.size() - 1) == ' ')
|
||||
result.chop(1);
|
||||
|
@@ -26,10 +26,10 @@ namespace TextEditor {
|
||||
// --------------------------
|
||||
// Note: variables and functions must be sorted
|
||||
Keywords::Keywords(const QStringList &variables, const QStringList &functions, const QMap<QString, QStringList> &functionArgs)
|
||||
: m_variables(variables), m_functions(functions), m_functionArgs(functionArgs)
|
||||
: m_variables(Utils::sorted(variables)),
|
||||
m_functions(Utils::sorted(functions)),
|
||||
m_functionArgs(functionArgs)
|
||||
{
|
||||
Utils::sort(m_variables);
|
||||
Utils::sort(m_functions);
|
||||
}
|
||||
|
||||
bool Keywords::isVariable(const QString &word) const
|
||||
|
@@ -22,8 +22,7 @@ namespace TextEditor {
|
||||
|
||||
CodecChooser::CodecChooser(Filter filter)
|
||||
{
|
||||
QList<int> mibs = QTextCodec::availableMibs();
|
||||
Utils::sort(mibs);
|
||||
QList<int> mibs = Utils::sorted(QTextCodec::availableMibs());
|
||||
QList<int>::iterator firstNonNegative =
|
||||
std::find_if(mibs.begin(), mibs.end(), [](int n) { return n >=0; });
|
||||
if (firstNonNegative != mibs.end())
|
||||
|
@@ -7229,8 +7229,8 @@ void TextEditorWidget::autoIndent()
|
||||
MultiTextCursor cursor = multiTextCursor();
|
||||
cursor.beginEditBlock();
|
||||
// The order is important, since some indenter refer to previous indent positions.
|
||||
QList<QTextCursor> cursors = cursor.cursors();
|
||||
Utils::sort(cursors, [](const QTextCursor &lhs, const QTextCursor &rhs) {
|
||||
const QList<QTextCursor> cursors = Utils::sorted(cursor.cursors(),
|
||||
[](const QTextCursor &lhs, const QTextCursor &rhs) {
|
||||
return lhs.selectionStart() < rhs.selectionStart();
|
||||
});
|
||||
for (const QTextCursor &c : cursors)
|
||||
|
@@ -193,12 +193,12 @@ void SuppressionDialog::accept()
|
||||
|
||||
m_settings->suppressions.addSuppressionFile(path);
|
||||
|
||||
QModelIndexList indices = m_view->selectionModel()->selectedRows();
|
||||
Utils::sort(indices, [](const QModelIndex &l, const QModelIndex &r) {
|
||||
const QModelIndexList indices = Utils::sorted(m_view->selectionModel()->selectedRows(),
|
||||
[](const QModelIndex &l, const QModelIndex &r) {
|
||||
return l.row() > r.row();
|
||||
});
|
||||
QAbstractItemModel *model = m_view->model();
|
||||
for (const QModelIndex &index : std::as_const(indices)) {
|
||||
for (const QModelIndex &index : indices) {
|
||||
bool removed = model->removeRow(index.row());
|
||||
QTC_ASSERT(removed, qt_noop());
|
||||
Q_UNUSED(removed)
|
||||
|
@@ -145,8 +145,7 @@ void tst_Algorithm::transform()
|
||||
Utils::sort(i2);
|
||||
QCOMPARE(i2, QList<int>({1, 3, 132}));
|
||||
QList<qsizetype> i3 = Utils::transform<QList>(strings, &QString::size);
|
||||
Utils::sort(i3);
|
||||
QCOMPARE(i3, QList<qsizetype>({1, 1, 3}));
|
||||
QCOMPARE(Utils::sorted(i3), QList<qsizetype>({1, 1, 3}));
|
||||
}
|
||||
{
|
||||
const QList<Struct> list({4, 3, 2, 1, 2});
|
||||
@@ -421,13 +420,11 @@ void tst_Algorithm::sort()
|
||||
// member function with pointers
|
||||
QList<QString> arr1({"12345", "3333", "22"});
|
||||
QList<QString *> s5({&arr1[0], &arr1[1], &arr1[2]});
|
||||
Utils::sort(s5, &QString::size);
|
||||
QCOMPARE(s5, QList<QString *>({&arr1[2], &arr1[1], &arr1[0]}));
|
||||
QCOMPARE(Utils::sorted(s5, &QString::size), QList<QString *>({&arr1[2], &arr1[1], &arr1[0]}));
|
||||
// member with pointers
|
||||
QList<Struct> arr2({4, 1, 3});
|
||||
QList<Struct *> s6({&arr2[0], &arr2[1], &arr2[2]});
|
||||
Utils::sort(s6, &Struct::member);
|
||||
QCOMPARE(s6, QList<Struct *>({&arr2[1], &arr2[2], &arr2[0]}));
|
||||
QCOMPARE(Utils::sorted(s6, &Struct::member), QList<Struct *>({&arr2[1], &arr2[2], &arr2[0]}));
|
||||
// std::array:
|
||||
std::array<int, 4> array = {{4, 10, 8, 1}};
|
||||
Utils::sort(array);
|
||||
|
Reference in New Issue
Block a user