src: moved bundling info to NodeType
* also: fixed NodeType for global variables not in NodeTypeSet::all()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1181,7 +1181,7 @@ std::shared_ptr<DummyNode> GraphController::bundleNodesMatching(
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchedNodes.size())
|
||||
if (matchedNodes.empty())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1204,23 +1204,59 @@ std::shared_ptr<DummyNode> GraphController::bundleNodesMatching(
|
||||
return bundleNode;
|
||||
}
|
||||
|
||||
void GraphController::bundleByType(
|
||||
std::list<std::shared_ptr<DummyNode>>& nodes, NodeType::Type type, const std::string& name)
|
||||
std::shared_ptr<DummyNode> GraphController::bundleByType(
|
||||
std::list<std::shared_ptr<DummyNode>>& nodes,
|
||||
const NodeType& type,
|
||||
const Tree<NodeType::BundleInfo>& bundleInfoTree,
|
||||
const bool considerInvisibleNodes)
|
||||
{
|
||||
std::shared_ptr<DummyNode> 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<std::shared_ptr<DummyNode>> bundledNodes;
|
||||
for (const std::shared_ptr<DummyNode>& node : bundleNode->bundledNodes)
|
||||
{
|
||||
bundledNodes.push_back(node);
|
||||
}
|
||||
bundleNode->bundledNodes.clear();
|
||||
|
||||
// crate a sub-bundle for anonymous namespaces
|
||||
for (const Tree<NodeType::BundleInfo>& childBundleInfoTree : bundleInfoTree.children)
|
||||
{
|
||||
std::shared_ptr<DummyNode> childBundle = bundleByType(bundledNodes, type, childBundleInfoTree, true);
|
||||
|
||||
|
||||
if (childBundle)
|
||||
{
|
||||
bundleNode->bundledNodes.insert(childBundle);
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::shared_ptr<DummyNode>& 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<DummyNode> 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<DummyNode>& bundleNode : m_dummyNodes)
|
||||
{
|
||||
if (!bundleNode->isBundleNode())
|
||||
{
|
||||
LOG_ERROR("Non-Bundle node in overview");
|
||||
}
|
||||
|
||||
if (bundleNode->name == "Namespaces")
|
||||
{
|
||||
std::list<std::shared_ptr<DummyNode>> nodes;
|
||||
for (const std::shared_ptr<DummyNode>& node : bundleNode->bundledNodes)
|
||||
{
|
||||
nodes.push_back(node);
|
||||
}
|
||||
bundleNode->bundledNodes.clear();
|
||||
|
||||
std::shared_ptr<DummyNode> anonymousBundle = bundleNodesMatching(
|
||||
nodes,
|
||||
[&](const DummyNode* node)
|
||||
{
|
||||
return node->name.find("anonymous namespace") != std::string::npos;
|
||||
},
|
||||
"Anonymous Namespaces"
|
||||
);
|
||||
|
||||
for (const std::shared_ptr<DummyNode>& 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()
|
||||
|
||||
@@ -97,7 +97,11 @@ private:
|
||||
const std::string& name);
|
||||
std::shared_ptr<DummyNode> bundleNodesMatching(
|
||||
std::list<std::shared_ptr<DummyNode>>& nodes, std::function<bool(const DummyNode*)> matcher, const std::string& name);
|
||||
void bundleByType(std::list<std::shared_ptr<DummyNode>>& nodes, NodeType::Type type, const std::string& name);
|
||||
std::shared_ptr<DummyNode> bundleByType(
|
||||
std::list<std::shared_ptr<DummyNode>>& nodes,
|
||||
const NodeType& type,
|
||||
const Tree<NodeType::BundleInfo>& bundleInfoTree,
|
||||
const bool considerInvisibleNodes = false);
|
||||
void bundleNodesByType();
|
||||
|
||||
void addCharacterIndex();
|
||||
|
||||
@@ -135,14 +135,57 @@ bool NodeType::isVisibleAsParentInGraph() const
|
||||
return !isPackage();
|
||||
}
|
||||
|
||||
FilePath NodeType::getIconPath() const
|
||||
Tree<NodeType::BundleInfo> 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>(BundleInfo([](const std::string&) { return true; }, "Files"));
|
||||
case NodeType::NODE_MACRO:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Macros"));
|
||||
case NodeType::NODE_NAMESPACE:
|
||||
{
|
||||
Tree<BundleInfo> tree(BundleInfo([](const std::string&) { return true; }, "Namespaces"));
|
||||
tree.children.push_back(Tree<BundleInfo>(BundleInfo([](const std::string& nodeName) { return nodeName.find("anonymous namespace") != std::string::npos; }, "Anonymous Namespaces")));
|
||||
return tree;
|
||||
}
|
||||
case NodeType::NODE_PACKAGE:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Packages"));
|
||||
case NodeType::NODE_CLASS:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Classes"));
|
||||
case NodeType::NODE_INTERFACE:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Interfaces"));
|
||||
case NodeType::NODE_STRUCT:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Structs"));
|
||||
case NodeType::NODE_FUNCTION:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Functions"));
|
||||
case NodeType::NODE_GLOBAL_VARIABLE:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Global Variables"));
|
||||
case NodeType::NODE_TYPE:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Types"));
|
||||
case NodeType::NODE_TYPEDEF:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Typedefs"));
|
||||
case NodeType::NODE_ENUM:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Enums"));
|
||||
case NodeType::NODE_UNION:
|
||||
return Tree<BundleInfo>(BundleInfo([](const std::string&) { return true; }, "Unions"));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Tree<BundleInfo>();
|
||||
}
|
||||
|
||||
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(), "-", "_"), " ", "_");
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#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<bool(std::string)> nameMatcher, std::string bundleName)
|
||||
: nameMatcher(nameMatcher)
|
||||
, bundleName(bundleName)
|
||||
{}
|
||||
std::function<bool(const std::string&)> 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<BundleInfo> getOverviewBundleTree() const;
|
||||
|
||||
FilePath getIconPath() const;
|
||||
|
||||
bool hasIcon() const;
|
||||
StyleType getNodeStyle() const;
|
||||
|
||||
bool hasOverviewBundle() const;
|
||||
std::string getUnderscoredTypeString() const;
|
||||
std::string getReadableTypeString() const;
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ const std::vector<NodeType> 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),
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef TREE_H
|
||||
#define TREE_H
|
||||
|
||||
template <typename T>
|
||||
struct Tree
|
||||
{
|
||||
Tree() {}
|
||||
Tree(T data) : data(data) {}
|
||||
T data;
|
||||
std::vector<Tree<T>> children;
|
||||
};
|
||||
|
||||
#endif // TREE_H
|
||||
Reference in New Issue
Block a user