logic: Refactored graph node sorting

* Fixed sorting to always be alphabetical within each bucket
* Bundled nodes will expand in place
* Overview bundles are not sorted alphabetical
* Probably improved sorting performance by using std::set
This commit is contained in:
Eberhard Graether
2016-12-10 12:40:46 +01:00
parent 8bf02140b2
commit 05ad054421
5 changed files with 114 additions and 98 deletions
+39 -16
View File
@@ -15,6 +15,25 @@ class Node;
struct DummyNode
{
public:
struct DummyNodeComp
{
bool operator()(const std::shared_ptr<DummyNode> a, const std::shared_ptr<DummyNode> b) const
{
if (a->bundleId != b->bundleId)
{
return a->bundleId > b->bundleId;
}
else if (a->isBundleNode() != b->isBundleNode())
{
return a->isBundleNode();
}
return utility::toLowerCase(a->name) < utility::toLowerCase(b->name);
}
};
typedef std::set<std::shared_ptr<DummyNode>, DummyNodeComp> BundledNodesSet;
struct BundleInfo
{
BundleInfo()
@@ -46,6 +65,7 @@ public:
, hasQualifier(false)
, accessKind(ACCESS_NONE)
, invisibleSubNodeCount(0)
, bundleId(0)
, layoutBucket(0, 0)
, bundledNodeCount(0)
{
@@ -184,21 +204,6 @@ public:
return bundledNodes.size();
}
void sortBundleNode()
{
sort(bundledNodes.begin(), bundledNodes.end(),
[](const std::shared_ptr<DummyNode> a, const std::shared_ptr<DummyNode> b) -> bool
{
if (a->isBundleNode() != b->isBundleNode())
{
return a->isBundleNode();
}
return utility::toLowerCase(a->name) < utility::toLowerCase(b->name);
}
);
}
void forEachDummyNodeRecursive(std::function<void(DummyNode*)> func)
{
func(this);
@@ -209,6 +214,23 @@ public:
}
}
Id setBundleIdRecursive(Id bundleId)
{
if (isBundleNode())
{
bundleId++;
}
this->bundleId = bundleId;
for (std::shared_ptr<DummyNode> node : bundledNodes)
{
bundleId = node->setBundleIdRecursive(bundleId);
}
return bundleId;
}
Vec2i position;
Vec2i size;
@@ -239,12 +261,13 @@ public:
// Bundling
BundleInfo bundleInfo;
Id bundleId;
// Layout
Vec2i layoutBucket;
// BundleNode
std::vector<std::shared_ptr<DummyNode>> bundledNodes;
BundledNodesSet bundledNodes;
size_t bundledNodeCount;
// QualifierNode