nodeview: further improved auto-positioning system
This commit is contained in:
@@ -549,6 +549,32 @@ bool Node::OutputsTo(Node *n) const
|
|||||||
return false;
|
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
|
bool Node::HasInputs() const
|
||||||
{
|
{
|
||||||
return HasParamOfType(NodeParam::kInput, false);
|
return HasParamOfType(NodeParam::kInput, false);
|
||||||
|
|||||||
+6
-1
@@ -229,10 +229,15 @@ public:
|
|||||||
NodeOutput* GetOutputWithID(const QString& id) const;
|
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;
|
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
|
* @brief Return whether this Node has input parameters
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ NodeView::NodeView(QWidget *parent) :
|
|||||||
drop_edge_(nullptr)
|
drop_edge_(nullptr)
|
||||||
{
|
{
|
||||||
setScene(&scene_);
|
setScene(&scene_);
|
||||||
setDragMode(RubberBandDrag);
|
SetDefaultDragMode(RubberBandDrag);
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setRenderHint(QPainter::Antialiasing);
|
setRenderHint(QPainter::Antialiasing);
|
||||||
|
|||||||
@@ -229,7 +229,9 @@ int NodeViewScene::DetermineWeight(Node *n)
|
|||||||
int weight = 0;
|
int weight = 0;
|
||||||
|
|
||||||
foreach (Node* i, inputs) {
|
foreach (Node* i, inputs) {
|
||||||
weight += DetermineWeight(i);
|
if (i->GetRoutesTo(n) == 1) {
|
||||||
|
weight += DetermineWeight(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qMax(1, weight);
|
return qMax(1, weight);
|
||||||
@@ -257,6 +259,7 @@ void NodeViewScene::ReorganizeFrom(Node* n)
|
|||||||
QPointF parent_pos = n->GetPosition();
|
QPointF parent_pos = n->GetPosition();
|
||||||
|
|
||||||
int weight_count = DetermineWeight(n);
|
int weight_count = DetermineWeight(n);
|
||||||
|
qDebug() << "Weight" << n->id() << "is" << weight_count;
|
||||||
|
|
||||||
qreal child_x = parent_pos.x() - 1.0;
|
qreal child_x = parent_pos.x() - 1.0;
|
||||||
qreal children_height = weight_count-1;
|
qreal children_height = weight_count-1;
|
||||||
@@ -265,14 +268,16 @@ void NodeViewScene::ReorganizeFrom(Node* n)
|
|||||||
int weight_counter = 0;
|
int weight_counter = 0;
|
||||||
|
|
||||||
foreach (Node* i, immediates) {
|
foreach (Node* i, immediates) {
|
||||||
int weight = DetermineWeight(i);
|
if (i->GetRoutesTo(n) == 1) {
|
||||||
|
int weight = DetermineWeight(i);
|
||||||
|
|
||||||
i->SetPosition(QPointF(child_x,
|
i->SetPosition(QPointF(child_x,
|
||||||
children_y + weight_counter + (weight - 1) * 0.5));
|
children_y + weight_counter + (weight - 1) * 0.5));
|
||||||
|
|
||||||
weight_counter += weight;
|
weight_counter += weight;
|
||||||
|
|
||||||
ReorganizeFrom(i);
|
ReorganizeFrom(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user