forked from qt-creator/qt-creator
ProjectExplorer: Order projects in session alphabetically again
Task-number: QTCREATORBUG-18337 Change-Id: I716369a1012f93c6c676e89c3b32cd1a406996a5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -689,6 +689,13 @@ void TreeItem::insertChild(int pos, TreeItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
void TreeItem::insertOrderedChild(TreeItem *item,
|
||||
const std::function<bool (const TreeItem *, const TreeItem *)> &cmp)
|
||||
{
|
||||
auto where = std::lower_bound(begin(), end(), item, cmp);
|
||||
insertChild(int(where - begin()), item);
|
||||
}
|
||||
|
||||
void TreeItem::removeChildAt(int pos)
|
||||
{
|
||||
QTC_ASSERT(0 <= pos && pos < m_children.count(), return);
|
||||
|
||||
@@ -54,6 +54,9 @@ public:
|
||||
void prependChild(TreeItem *item);
|
||||
void appendChild(TreeItem *item);
|
||||
void insertChild(int pos, TreeItem *item);
|
||||
void insertOrderedChild(TreeItem *item,
|
||||
const std::function<bool(const TreeItem *, const TreeItem *)> &cmp);
|
||||
|
||||
void removeChildAt(int pos);
|
||||
void removeChildren();
|
||||
void sortChildren(const std::function<bool(const TreeItem *, const TreeItem *)> &cmp);
|
||||
@@ -135,6 +138,14 @@ public:
|
||||
ParentType *parent() const {
|
||||
return static_cast<ParentType *>(TreeItem::parent());
|
||||
}
|
||||
|
||||
void insertOrderedChild(ChildType *item, const std::function<bool(const ChildType *, const ChildType *)> &cmp)
|
||||
{
|
||||
const auto cmp0 = [cmp](const TreeItem *lhs, const TreeItem *rhs) {
|
||||
return cmp(static_cast<const ChildType *>(lhs), static_cast<const ChildType *>(rhs));
|
||||
};
|
||||
TreeItem::insertOrderedChild(item, cmp0);
|
||||
}
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT StaticTreeItem : public TreeItem
|
||||
|
||||
@@ -175,6 +175,16 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool compareProjectNames(const WrapperNode *lhs, const WrapperNode *rhs)
|
||||
{
|
||||
Node *p1 = lhs->m_node;
|
||||
Node *p2 = rhs->m_node;
|
||||
const int displayNameResult = caseFriendlyCompare(p1->displayName(), p2->displayName());
|
||||
if (displayNameResult != 0)
|
||||
return displayNameResult < 0;
|
||||
return p1 < p2; // sort by pointer value
|
||||
}
|
||||
|
||||
void FlatModel::addOrRebuildProjectModel(Project *project)
|
||||
{
|
||||
WrapperNode *container = nodeForProject(project);
|
||||
@@ -182,7 +192,7 @@ void FlatModel::addOrRebuildProjectModel(Project *project)
|
||||
container->removeChildren();
|
||||
} else {
|
||||
container = new WrapperNode(project->containerNode());
|
||||
rootItem()->appendChild(container);
|
||||
rootItem()->insertOrderedChild(container, &compareProjectNames);
|
||||
}
|
||||
|
||||
QSet<Node *> seen;
|
||||
@@ -230,16 +240,7 @@ void FlatModel::updateSubtree(FolderNode *node)
|
||||
|
||||
void FlatModel::rebuildModel()
|
||||
{
|
||||
QList<Project *> projects = SessionManager::projects();
|
||||
QTC_CHECK(projects.size() == rootItem()->childCount());
|
||||
|
||||
Utils::sort(projects, [](Project *p1, Project *p2) {
|
||||
const int displayNameResult = caseFriendlyCompare(p1->displayName(), p2->displayName());
|
||||
if (displayNameResult != 0)
|
||||
return displayNameResult < 0;
|
||||
return p1 < p2; // sort by pointer value
|
||||
});
|
||||
|
||||
const QList<Project *> projects = SessionManager::projects();
|
||||
for (Project *project : projects)
|
||||
addOrRebuildProjectModel(project);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user