began node viewer for dag insight

This commit is contained in:
itsmattkc
2019-07-15 03:52:44 -04:00
parent 33f9f9dbc4
commit dc2101938e
19 changed files with 401 additions and 42 deletions
+66 -7
View File
@@ -20,22 +20,81 @@
#include "nodeview.h"
#include <QGraphicsRectItem>
#include "nodeviewitem.h"
NodeView::NodeView(QWidget *parent) :
QGraphicsView(parent),
graph_(nullptr)
{
setScene(&scene_);
NodeViewItem* item = new NodeViewItem();
scene_.addItem(item);
connect(&scene_, SIGNAL(changed(const QList<QRectF>&)), this, SLOT(ItemsChanged()));
}
void NodeView::SetGraph(NodeGraph *graph)
{
// Clear the scene of all UI objects
scene_.clear();
edges_.clear();
// Set reference to the graph
graph_ = graph;
// If the graph is valid, add UI objects for each of its Nodes
if (graph_ != nullptr) {
QList<Node*> graph_nodes = graph_->nodes();
foreach (Node* node, graph_nodes) {
NodeViewItem* item = new NodeViewItem();
item->SetNode(node);
scene_.addItem(item);
// Add a NodeViewEdge for each connection
QList<NodeParam*> node_params = node->parameters();
foreach (NodeParam* param, node_params) {
// We only bother working with outputs since eventually this will cover all inputs too
// (covering both would lead to duplicates since every edge connects to one input and one output)
if (param->type() == NodeParam::kOutput) {
const QVector<NodeEdgePtr>& edges = param->edges();
foreach(NodeEdgePtr edge, edges) {
NodeViewEdge* edge_ui = new NodeViewEdge();
edge_ui->SetEdge(edge);
scene_.addItem(edge_ui);
// Keep track of edge widgets so they can be quickly updated whenever nodes move
edges_.append(edge_ui);
}
}
}
}
}
}
NodeViewItem *NodeView::NodeToUIObject(QGraphicsScene *scene, Node *n)
{
QList<QGraphicsItem*> graphics_items = scene->items();
for (int i=0;i<graphics_items.size();i++) {
NodeViewItem* item = dynamic_cast<NodeViewItem*>(graphics_items.at(i));
if (item != nullptr) {
if (item->node() == n) {
return item;
}
}
}
return nullptr;
}
void NodeView::ItemsChanged()
{
foreach (NodeViewEdge* edge, edges_) {
edge->Adjust();
}
}