Skip to content

Commit e1290f3

Browse files
committed
Descend into inner nodes
1 parent 5713be5 commit e1290f3

6 files changed

Lines changed: 50 additions & 12 deletions

File tree

src/gui/models/nodeGraph/graphModel.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ QAbstractListModel *GraphModel::nodes() { return &nodes_; }
4343

4444
int GraphModel::count() { return nodes_.rowCount(); }
4545

46-
QString GraphModel::location() const {
47-
if (!graph_)
48-
return "";
49-
return QString::fromStdString(graph_->location());
46+
QString GraphModel::location() const
47+
{
48+
if (!graph_)
49+
return "";
50+
return QString::fromStdString(graph_->location());
5051
};
5152

52-
bool GraphModel::atRoot() const {
53-
return !graph_;
53+
bool GraphModel::atRoot() const
54+
{
55+
if (!graph_)
56+
return true;
57+
return !graph_->parentGraph();
5458
}
5559

5660
// Provide relative coordinates for an input on a node
@@ -71,14 +75,24 @@ void GraphModel::addOutput(int nodeIndex, QString paramName, double x, double y)
7175
node.outputPos.insert({paramName.toStdString(), {x, y}});
7276
}
7377

74-
7578
// Switch to parent graph
76-
void GraphModel::upLevel() {
77-
if (!graph_);
78-
return;
79+
void GraphModel::upLevel()
80+
{
81+
if (!graph_)
82+
return;
7983
setGraph(graph_->parentGraph());
8084
}
8185

86+
// Move into an inner graph
87+
void GraphModel::descend(int index)
88+
{
89+
auto &node = wrapped_[index];
90+
if (node.hasInner())
91+
{
92+
setGraph(static_cast<Graph *>(&node.rawValue()));
93+
}
94+
}
95+
8296
void GraphModel::emplace_back(int x, int y, QVariant type, QVariant name)
8397
{
8498
if (!graph_)

src/gui/models/nodeGraph/graphModel.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class GraphModel : public QObject
2323
Q_PROPERTY(QAbstractListModel *nodes READ nodes NOTIFY graphChanged);
2424
Q_PROPERTY(int nodeCount READ count NOTIFY graphChanged);
2525
Q_PROPERTY(int edgeCount READ nEdges NOTIFY graphChanged);
26-
Q_PROPERTY(QString location READ location);
27-
Q_PROPERTY(bool atRoot READ atRoot);
26+
Q_PROPERTY(QString location READ location NOTIFY graphChanged);
27+
Q_PROPERTY(bool atRoot READ atRoot NOTIFY graphChanged);
2828

2929
friend GraphNodeModel;
3030
friend GraphEdgeModel;
@@ -94,4 +94,6 @@ class GraphModel : public QObject
9494

9595
// Switch to parent graph
9696
void upLevel();
97+
// Move into an inner graph
98+
void descend(int index);
9799
};

src/gui/models/nodeGraph/graphNodeModel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum Role
1818
INPUTS,
1919
OUTPUTS,
2020
OPTIONS,
21+
INNER_GRAPH,
2122
};
2223

2324
GraphNodeModel &GraphNodeModel::operator=(const GraphNodeModel &other)
@@ -54,6 +55,7 @@ QHash<int, QByteArray> GraphNodeModel::roleNames() const
5455
roles[Qt::UserRole + (int)INPUTS] = "inputs";
5556
roles[Qt::UserRole + (int)OUTPUTS] = "outputs";
5657
roles[Qt::UserRole + (int)OPTIONS] = "options";
58+
roles[Qt::UserRole + (int)INNER_GRAPH] = "inner_graph";
5759
return roles;
5860
}
5961

@@ -79,6 +81,8 @@ QVariant GraphNodeModel::data(const QModelIndex &index, int role) const
7981
return QVariant::fromValue(item.outputs.get());
8082
case OPTIONS:
8183
return QVariant::fromValue(item.options.get());
84+
case INNER_GRAPH:
85+
return item.hasInner();
8286
}
8387
return {};
8488
}

src/gui/models/nodeGraph/nodeWrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class NodeWrapper
3131
Node &rawValue() { return *value_; }
3232
const Node &rawValue() const { return *value_; }
3333

34+
// Does this node contain other nodes?
35+
bool hasInner() { return dynamic_cast<Graph *>(value_) != nullptr; }
36+
3437
private:
3538
// The actual value of the node
3639
Node *value_;

src/gui/qml/nodeGraph/GraphDelegate.qml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ NodeBox {
1212
property variant rootModel
1313
property double startX: x + width
1414
signal edgeCreated(srcNode: string, srcOutput: string, tgtNode: string, tgtInput: string)
15+
signal descended(idx: int)
1516

1617
image: icon
1718
nodeType: name
@@ -167,6 +168,15 @@ NodeBox {
167168
height: options.rowCount() > 0 ? 2 : 0
168169
width: parent.width
169170
}
171+
Button {
172+
Layout.fillWidth: true
173+
text: "Inner Graph"
174+
visible: inner_graph
175+
176+
onClicked: {
177+
descended(index);
178+
}
179+
}
170180
GridLayout {
171181
columns: 3
172182
width: parent.width

src/gui/qml/nodeGraph/GraphView.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ Pane {
109109

110110
onClicked: graphRoot.rootModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Configuration", "New Node")
111111
}
112+
MenuItem {
113+
text: "Graph"
114+
115+
onClicked: graphRoot.rootModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Graph", "New Graph")
116+
}
112117
}
113118
}
114119
}

0 commit comments

Comments
 (0)