forked from qt-creator/qt-creator
ProjectExplorer: Move Node::nodeType implementation
... to the only remaining user, and rename it there. Change-Id: I0bdb3179282e323f5ad7b41d034bb5f3db8f6ffc Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -163,20 +163,6 @@ void Node::setAbsoluteFilePathAndLine(const Utils::FileName &path, int line)
|
|||||||
|
|
||||||
Node::~Node() = default;
|
Node::~Node() = default;
|
||||||
|
|
||||||
NodeType Node::nodeType() const
|
|
||||||
{
|
|
||||||
if (asFileNode())
|
|
||||||
return NodeType::File;
|
|
||||||
if (isFolderNodeType())
|
|
||||||
return NodeType::Folder;
|
|
||||||
if (isProjectNodeType())
|
|
||||||
return NodeType::Project;
|
|
||||||
if (isVirtualFolderType())
|
|
||||||
return NodeType::VirtualFolder;
|
|
||||||
QTC_CHECK(false);
|
|
||||||
return NodeType::File;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Node::priority() const
|
int Node::priority() const
|
||||||
{
|
{
|
||||||
return m_priority;
|
return m_priority;
|
||||||
|
@@ -44,13 +44,6 @@ namespace ProjectExplorer {
|
|||||||
|
|
||||||
class Project;
|
class Project;
|
||||||
|
|
||||||
enum class NodeType : quint16 {
|
|
||||||
File = 1,
|
|
||||||
Folder,
|
|
||||||
VirtualFolder,
|
|
||||||
Project
|
|
||||||
};
|
|
||||||
|
|
||||||
// File types common for qt projects
|
// File types common for qt projects
|
||||||
enum class FileType : quint16 {
|
enum class FileType : quint16 {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
@@ -116,7 +109,6 @@ public:
|
|||||||
virtual bool isProjectNodeType() const { return false; }
|
virtual bool isProjectNodeType() const { return false; }
|
||||||
virtual bool isVirtualFolderType() const { return false; }
|
virtual bool isVirtualFolderType() const { return false; }
|
||||||
|
|
||||||
NodeType nodeType() const;
|
|
||||||
int priority() const;
|
int priority() const;
|
||||||
|
|
||||||
ProjectNode *parentProjectNode() const; // parent project, will be nullptr for the top-level project
|
ProjectNode *parentProjectNode() const; // parent project, will be nullptr for the top-level project
|
||||||
|
@@ -355,6 +355,21 @@ Node *ProjectTreeWidget::nodeForFile(const FileName &fileName)
|
|||||||
Node *bestNode = nullptr;
|
Node *bestNode = nullptr;
|
||||||
int bestNodeExpandCount = INT_MAX;
|
int bestNodeExpandCount = INT_MAX;
|
||||||
|
|
||||||
|
// FIXME: Check that the values used make sense in the context.
|
||||||
|
auto priority = [](Node *node) {
|
||||||
|
if (node->asFileNode())
|
||||||
|
return 1;
|
||||||
|
if (node->isFolderNodeType())
|
||||||
|
return 2;
|
||||||
|
if (node->isVirtualFolderType())
|
||||||
|
return 3;
|
||||||
|
if (node->isProjectNodeType())
|
||||||
|
return 4;
|
||||||
|
QTC_CHECK(false);
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME: Looks like this could be done with less cycles.
|
||||||
for (Project *project : SessionManager::projects()) {
|
for (Project *project : SessionManager::projects()) {
|
||||||
if (ProjectNode *projectNode = project->rootProjectNode()) {
|
if (ProjectNode *projectNode = project->rootProjectNode()) {
|
||||||
projectNode->forEachGenericNode([&](Node *node) {
|
projectNode->forEachGenericNode([&](Node *node) {
|
||||||
@@ -362,10 +377,10 @@ Node *ProjectTreeWidget::nodeForFile(const FileName &fileName)
|
|||||||
if (!bestNode) {
|
if (!bestNode) {
|
||||||
bestNode = node;
|
bestNode = node;
|
||||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||||
} else if (node->nodeType() < bestNode->nodeType()) {
|
} else if (priority(node) < priority(bestNode)) {
|
||||||
bestNode = node;
|
bestNode = node;
|
||||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||||
} else if (node->nodeType() == bestNode->nodeType()) {
|
} else if (priority(node) == priority(bestNode)) {
|
||||||
int nodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
int nodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||||
if (nodeExpandCount < bestNodeExpandCount) {
|
if (nodeExpandCount < bestNodeExpandCount) {
|
||||||
bestNode = node;
|
bestNode = node;
|
||||||
|
Reference in New Issue
Block a user