forked from qt-creator/qt-creator
ProjectExplorer: Use visitor-by-lambda for project tree
And inline it into user code. Less code in total and no intermediate node lists. Change-Id: I3724883408bfaa868266110aee27bbffd4d96bd8 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -272,29 +272,27 @@ void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int e
|
||||
|
||||
Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
|
||||
{
|
||||
return mostExpandedNode(SessionManager::nodesForFile(fileName));
|
||||
}
|
||||
|
||||
Node *ProjectTreeWidget::mostExpandedNode(const QList<Node *> &nodes)
|
||||
{
|
||||
Node *bestNode = 0;
|
||||
Node *bestNode = nullptr;
|
||||
int bestNodeExpandCount = INT_MAX;
|
||||
|
||||
foreach (Node *node, nodes) {
|
||||
if (!bestNode) {
|
||||
bestNode = node;
|
||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
} else if (node->nodeType() < bestNode->nodeType()) {
|
||||
bestNode = node;
|
||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
} else if (node->nodeType() == bestNode->nodeType()) {
|
||||
int nodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
if (nodeExpandCount < bestNodeExpandCount) {
|
||||
SessionManager::sessionNode()->forEachGenericNode([&](Node *node) {
|
||||
if (node->filePath() == fileName) {
|
||||
if (!bestNode) {
|
||||
bestNode = node;
|
||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
} else if (node->nodeType() < bestNode->nodeType()) {
|
||||
bestNode = node;
|
||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
} else if (node->nodeType() == bestNode->nodeType()) {
|
||||
int nodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
if (nodeExpandCount < bestNodeExpandCount) {
|
||||
bestNode = node;
|
||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return bestNode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user