nodeview: further improved auto-positioning system

This commit is contained in:
itsmattkc
2020-05-08 19:20:24 +10:00
parent 12672aae7c
commit 1efd4e9f99
4 changed files with 44 additions and 8 deletions
+26
View File
@@ -549,6 +549,32 @@ bool Node::OutputsTo(Node *n) const
return false;
}
int Node::GetRoutesTo(Node *n) const
{
bool outputs_directly = false;
int routes = 0;
QList<NodeOutput*> outputs = GetOutputs();
foreach (NodeOutput* o, outputs) {
foreach (NodeEdgePtr edge, o->edges()) {
Node* connected_node = edge->input()->parentNode();
if (connected_node == n) {
outputs_directly = true;
} else {
routes += connected_node->GetRoutesTo(n);
}
}
}
if (outputs_directly) {
routes++;
}
return routes;
}
bool Node::HasInputs() const
{
return HasParamOfType(NodeParam::kInput, false);
+6 -1
View File
@@ -229,10 +229,15 @@ public:
NodeOutput* GetOutputWithID(const QString& id) const;
/**
* @brief Returns whether this Node outputs data to the Node `n` in any way
* @brief Returns whether this Node outputs directly to `n`
*/
bool OutputsTo(Node* n) const;
/**
* @brief Determines how many paths go from this node out to another node
*/
int GetRoutesTo(Node* n) const;
/**
* @brief Return whether this Node has input parameters
*/
+1 -1
View File
@@ -38,7 +38,7 @@ NodeView::NodeView(QWidget *parent) :
drop_edge_(nullptr)
{
setScene(&scene_);
setDragMode(RubberBandDrag);
SetDefaultDragMode(RubberBandDrag);
setContextMenuPolicy(Qt::CustomContextMenu);
setMouseTracking(true);
setRenderHint(QPainter::Antialiasing);
+11 -6
View File
@@ -229,7 +229,9 @@ int NodeViewScene::DetermineWeight(Node *n)
int weight = 0;
foreach (Node* i, inputs) {
weight += DetermineWeight(i);
if (i->GetRoutesTo(n) == 1) {
weight += DetermineWeight(i);
}
}
return qMax(1, weight);
@@ -257,6 +259,7 @@ void NodeViewScene::ReorganizeFrom(Node* n)
QPointF parent_pos = n->GetPosition();
int weight_count = DetermineWeight(n);
qDebug() << "Weight" << n->id() << "is" << weight_count;
qreal child_x = parent_pos.x() - 1.0;
qreal children_height = weight_count-1;
@@ -265,14 +268,16 @@ void NodeViewScene::ReorganizeFrom(Node* n)
int weight_counter = 0;
foreach (Node* i, immediates) {
int weight = DetermineWeight(i);
if (i->GetRoutesTo(n) == 1) {
int weight = DetermineWeight(i);
i->SetPosition(QPointF(child_x,
children_y + weight_counter + (weight - 1) * 0.5));
i->SetPosition(QPointF(child_x,
children_y + weight_counter + (weight - 1) * 0.5));
weight_counter += weight;
weight_counter += weight;
ReorganizeFrom(i);
ReorganizeFrom(i);
}
}
}