From 21189bb887dccf438a109be7243ee7216494e436 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Fri, 8 Dec 2017 15:07:33 +0100 Subject: [PATCH] src: moved bundling info to NodeType * also: fixed NodeType for global variables not in NodeTypeSet::all() --- src/lib/CMakeLists.txt | 1 + .../component/controller/GraphController.cpp | 126 ++++++++---------- .../component/controller/GraphController.h | 6 +- src/lib/data/NodeType.cpp | 63 ++++++++- src/lib/data/NodeType.h | 18 +++ src/lib/data/NodeTypeSet.cpp | 1 + src/lib/utility/Tree.h | 13 ++ 7 files changed, 148 insertions(+), 80 deletions(-) create mode 100644 src/lib/utility/Tree.h diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 9318cdbd..396a8f0f 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -523,6 +523,7 @@ add_files( utility/TimeStamp.h utility/tracing.cpp utility/tracing.h + utility/Tree.h utility/types.h utility/UserPaths.cpp utility/UserPaths.h diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 41597bd3..4f279ba0 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -1181,7 +1181,7 @@ std::shared_ptr GraphController::bundleNodesMatching( } } - if (!matchedNodes.size()) + if (matchedNodes.empty()) { return nullptr; } @@ -1204,23 +1204,59 @@ std::shared_ptr GraphController::bundleNodesMatching( return bundleNode; } -void GraphController::bundleByType( - std::list>& nodes, NodeType::Type type, const std::string& name) +std::shared_ptr GraphController::bundleByType( + std::list>& nodes, + const NodeType& type, + const Tree& bundleInfoTree, + const bool considerInvisibleNodes) { std::shared_ptr bundleNode = bundleNodesMatching( nodes, [&](const DummyNode* node) { - return node->visible && node->isGraphNode() && node->data->getType().getType() == type; + return + (considerInvisibleNodes || node->visible) && + node->isGraphNode() && + node->data->getType() == type && + bundleInfoTree.data.nameMatcher(node->name); }, - name + bundleInfoTree.data.bundleName ); if (bundleNode) { bundleNode->bundledNodeType = type; - m_dummyNodes.push_back(bundleNode); + bundleNode->bundledNodeCount = bundleNode->getBundledNodeCount(); + + if (!bundleInfoTree.children.empty()) + { + std::list> bundledNodes; + for (const std::shared_ptr& node : bundleNode->bundledNodes) + { + bundledNodes.push_back(node); + } + bundleNode->bundledNodes.clear(); + + // crate a sub-bundle for anonymous namespaces + for (const Tree& childBundleInfoTree : bundleInfoTree.children) + { + std::shared_ptr childBundle = bundleByType(bundledNodes, type, childBundleInfoTree, true); + + + if (childBundle) + { + bundleNode->bundledNodes.insert(childBundle); + } + } + + for (const std::shared_ptr& bundledNode : bundledNodes) + { + bundleNode->bundledNodes.insert(bundledNode); + } + } } + + return bundleNode; } void GraphController::bundleNodesByType() @@ -1236,78 +1272,22 @@ void GraphController::bundleNodesByType() nodes.push_back(oldNodes[i]); } - bundleByType(nodes, NodeType::NODE_FILE, "Files"); - bundleByType(nodes, NodeType::NODE_MACRO, "Macros"); - - bundleByType(nodes, NodeType::NODE_NAMESPACE, "Namespaces"); - bundleByType(nodes, NodeType::NODE_PACKAGE, "Packages"); - - // bundleByType(nodes, NodeType::NODE_BUILTIN_TYPE, "Built-in Types"); - bundleByType(nodes, NodeType::NODE_CLASS, "Classes"); - bundleByType(nodes, NodeType::NODE_INTERFACE, "Interfaces"); - bundleByType(nodes, NodeType::NODE_STRUCT, "Structs"); - - bundleByType(nodes, NodeType::NODE_FUNCTION, "Functions"); - bundleByType(nodes, NodeType::NODE_GLOBAL_VARIABLE, "Global Variables"); - - bundleByType(nodes, NodeType::NODE_TYPE, "Types"); - bundleByType(nodes, NodeType::NODE_TYPEDEF, "Typedefs"); - bundleByType(nodes, NodeType::NODE_ENUM, "Enums"); - bundleByType(nodes, NodeType::NODE_UNION, "Unions"); - - // // should never be visible - - // bundleByType(nodes, NodeType::NODE_METHOD, "Methods"); - // bundleByType(nodes, NodeType::NODE_FIELD, "Fields"); - // bundleByType(nodes, NodeType::NODE_ENUM_CONSTANT, "Enum Constants"); - // bundleByType(nodes, NodeType::NODE_TEMPLATE_PARAMETER_TYPE, "Template Parameter Types"); - // bundleByType(nodes, NodeType::NODE_TYPE_PARAMETER, "Type Parameters"); - // bundleByType(nodes, NodeType::NODE_SYMBOL, "Non-indexed Symbols"); + for (const NodeType& nodeType : NodeTypeSet::all().getNodeTypes()) + { + if (nodeType.hasOverviewBundle()) + { + std::shared_ptr bundleNode = bundleByType(nodes, nodeType, nodeType.getOverviewBundleTree()); + if (bundleNode) + { + m_dummyNodes.push_back(bundleNode); + } + } + } if (nodes.size()) { LOG_ERROR("Nodes left after bundling for overview"); } - - // crate a sub-bundle for anonymous namespaces - for (const std::shared_ptr& bundleNode : m_dummyNodes) - { - if (!bundleNode->isBundleNode()) - { - LOG_ERROR("Non-Bundle node in overview"); - } - - if (bundleNode->name == "Namespaces") - { - std::list> nodes; - for (const std::shared_ptr& node : bundleNode->bundledNodes) - { - nodes.push_back(node); - } - bundleNode->bundledNodes.clear(); - - std::shared_ptr anonymousBundle = bundleNodesMatching( - nodes, - [&](const DummyNode* node) - { - return node->name.find("anonymous namespace") != std::string::npos; - }, - "Anonymous Namespaces" - ); - - for (const std::shared_ptr& node : nodes) - { - bundleNode->bundledNodes.insert(node); - } - - if (anonymousBundle) - { - anonymousBundle->bundledNodeType = NodeType::NODE_NAMESPACE; - bundleNode->bundledNodeCount = bundleNode->getBundledNodeCount() + anonymousBundle->getBundledNodeCount(); - bundleNode->bundledNodes.insert(anonymousBundle); - } - } - } } void GraphController::addCharacterIndex() diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index a3add5ad..7f299222 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -97,7 +97,11 @@ private: const std::string& name); std::shared_ptr bundleNodesMatching( std::list>& nodes, std::function matcher, const std::string& name); - void bundleByType(std::list>& nodes, NodeType::Type type, const std::string& name); + std::shared_ptr bundleByType( + std::list>& nodes, + const NodeType& type, + const Tree& bundleInfoTree, + const bool considerInvisibleNodes = false); void bundleNodesByType(); void addCharacterIndex(); diff --git a/src/lib/data/NodeType.cpp b/src/lib/data/NodeType.cpp index fb50795b..a336639f 100644 --- a/src/lib/data/NodeType.cpp +++ b/src/lib/data/NodeType.cpp @@ -135,14 +135,57 @@ bool NodeType::isVisibleAsParentInGraph() const return !isPackage(); } -FilePath NodeType::getIconPath() const +Tree NodeType::getOverviewBundleTree() const { switch (m_type) { - case NodeType::NODE_NAMESPACE: - case NodeType::NODE_PACKAGE: - // package icon cannot be changed + case NodeType::NODE_FILE: + return Tree(BundleInfo([](const std::string&) { return true; }, "Files")); + case NodeType::NODE_MACRO: + return Tree(BundleInfo([](const std::string&) { return true; }, "Macros")); + case NodeType::NODE_NAMESPACE: + { + Tree tree(BundleInfo([](const std::string&) { return true; }, "Namespaces")); + tree.children.push_back(Tree(BundleInfo([](const std::string& nodeName) { return nodeName.find("anonymous namespace") != std::string::npos; }, "Anonymous Namespaces"))); + return tree; + } + case NodeType::NODE_PACKAGE: + return Tree(BundleInfo([](const std::string&) { return true; }, "Packages")); + case NodeType::NODE_CLASS: + return Tree(BundleInfo([](const std::string&) { return true; }, "Classes")); + case NodeType::NODE_INTERFACE: + return Tree(BundleInfo([](const std::string&) { return true; }, "Interfaces")); + case NodeType::NODE_STRUCT: + return Tree(BundleInfo([](const std::string&) { return true; }, "Structs")); + case NodeType::NODE_FUNCTION: + return Tree(BundleInfo([](const std::string&) { return true; }, "Functions")); + case NodeType::NODE_GLOBAL_VARIABLE: + return Tree(BundleInfo([](const std::string&) { return true; }, "Global Variables")); + case NodeType::NODE_TYPE: + return Tree(BundleInfo([](const std::string&) { return true; }, "Types")); + case NodeType::NODE_TYPEDEF: + return Tree(BundleInfo([](const std::string&) { return true; }, "Typedefs")); + case NodeType::NODE_ENUM: + return Tree(BundleInfo([](const std::string&) { return true; }, "Enums")); + case NodeType::NODE_UNION: + return Tree(BundleInfo([](const std::string&) { return true; }, "Unions")); + default: + break; + } + + return Tree(); +} + +FilePath NodeType::getIconPath() const +{ + if (isPackage()) + { + // this icon cannot be changed return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/namespace.png")); + } + + switch (m_type) + { case NodeType::NODE_ENUM: return ResourcePaths::getGuiPath().concat(FilePath("graph_view/images/enum.png")); case NodeType::NODE_TYPEDEF: @@ -158,9 +201,12 @@ FilePath NodeType::getIconPath() const bool NodeType::hasIcon() const { + if (isPackage()) + { + return true; + } + const NodeType::TypeMask mask = - NodeType::NODE_NAMESPACE | - NodeType::NODE_PACKAGE | NodeType::NODE_ENUM | NodeType::NODE_TYPEDEF | NodeType::NODE_FILE | @@ -198,6 +244,11 @@ NodeType::StyleType NodeType::getNodeStyle() const } } +bool NodeType::hasOverviewBundle() const +{ + return !getOverviewBundleTree().data.bundleName.empty(); +} + std::string NodeType::getUnderscoredTypeString() const { return utility::replace(utility::replace(getReadableTypeString(), "-", "_"), " ", "_"); diff --git a/src/lib/data/NodeType.h b/src/lib/data/NodeType.h index f4bd352f..29b472f2 100644 --- a/src/lib/data/NodeType.h +++ b/src/lib/data/NodeType.h @@ -7,6 +7,7 @@ #include #include "utility/file/FilePath.h" +#include "utility/Tree.h" #include "utility/types.h" class NodeType @@ -49,6 +50,20 @@ public: STYLE_BIG_NODE = 2 }; + struct BundleInfo + { + BundleInfo() + : nameMatcher(nullptr) + , bundleName("") + {} + BundleInfo(std::function nameMatcher, std::string bundleName) + : nameMatcher(nameMatcher) + , bundleName(bundleName) + {} + std::function nameMatcher; + std::string bundleName; + }; + NodeType(Type type); bool operator==(const NodeType& o) const; @@ -68,11 +83,14 @@ public: bool isPotentialMember() const; bool isCollapsible() const; bool isVisibleAsParentInGraph() const; + Tree getOverviewBundleTree() const; + FilePath getIconPath() const; bool hasIcon() const; StyleType getNodeStyle() const; + bool hasOverviewBundle() const; std::string getUnderscoredTypeString() const; std::string getReadableTypeString() const; diff --git a/src/lib/data/NodeTypeSet.cpp b/src/lib/data/NodeTypeSet.cpp index e8ed8e32..60ee1e1a 100644 --- a/src/lib/data/NodeTypeSet.cpp +++ b/src/lib/data/NodeTypeSet.cpp @@ -142,6 +142,7 @@ const std::vector NodeTypeSet::s_allNodeTypes = { NodeType(NodeType::NODE_STRUCT), NodeType(NodeType::NODE_CLASS), NodeType(NodeType::NODE_INTERFACE), + NodeType(NodeType::NODE_GLOBAL_VARIABLE), NodeType(NodeType::NODE_FIELD), NodeType(NodeType::NODE_FUNCTION), NodeType(NodeType::NODE_METHOD), diff --git a/src/lib/utility/Tree.h b/src/lib/utility/Tree.h new file mode 100644 index 00000000..eb1e49d2 --- /dev/null +++ b/src/lib/utility/Tree.h @@ -0,0 +1,13 @@ +#ifndef TREE_H +#define TREE_H + +template +struct Tree +{ + Tree() {} + Tree(T data) : data(data) {} + T data; + std::vector> children; +}; + +#endif // TREE_H