various node UI improvements

This commit is contained in:
itsmattkc
2019-07-16 13:25:38 -04:00
parent ea4e142e0c
commit a78cc3950a
26 changed files with 279 additions and 154 deletions
+25 -5
View File
@@ -33,6 +33,11 @@ NodeView::NodeView(QWidget *parent) :
void NodeView::SetGraph(NodeGraph *graph)
{
if (graph_ != nullptr) {
disconnect(graph_, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(AddEdge(NodeEdgePtr)));
disconnect(graph_, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(RemoveEdge(NodeEdgePtr)));
}
// Clear the scene of all UI objects
scene_.clear();
@@ -41,6 +46,9 @@ void NodeView::SetGraph(NodeGraph *graph)
// If the graph is valid, add UI objects for each of its Nodes
if (graph_ != nullptr) {
connect(graph_, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(AddEdge(NodeEdgePtr)));
connect(graph_, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(RemoveEdge(NodeEdgePtr)));
QList<Node*> graph_nodes = graph_->nodes();
foreach (Node* node, graph_nodes) {
@@ -61,11 +69,7 @@ void NodeView::SetGraph(NodeGraph *graph)
const QVector<NodeEdgePtr>& edges = param->edges();
foreach(NodeEdgePtr edge, edges) {
NodeViewEdge* edge_ui = new NodeViewEdge();
edge_ui->SetEdge(edge);
scene_.addItem(edge_ui);
AddEdge(edge);
}
}
}
@@ -107,6 +111,22 @@ NodeViewEdge *NodeView::EdgeToUIObject(QGraphicsScene *scene, NodeEdgePtr n)
return nullptr;
}
void NodeView::AddEdge(NodeEdgePtr edge)
{
NodeViewEdge* edge_ui = new NodeViewEdge();
edge_ui->SetEdge(edge);
scene_.addItem(edge_ui);
}
void NodeView::RemoveEdge(NodeEdgePtr edge)
{
NodeViewEdge* edge_ui = EdgeToUIObject(scene(), edge);
scene_.removeItem(edge_ui);
}
void NodeView::ItemsChanged()
{
QList<QGraphicsItem*> items = scene_.items();