Skip to content

Commit f5d3fa2

Browse files
authored
feat:Inner graphs (#2226)
1 parent 1992bb9 commit f5d3fa2

11 files changed

Lines changed: 186 additions & 72 deletions

File tree

.github/workflows/build/osx/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ runs:
2929
# Setup / Install Dependencies
3030
#
3131

32+
- name: Choose XCode version
33+
shell: bash
34+
run: |
35+
sudo xcode-select -s /Applications/Xcode_16.2.app
36+
3237
- name: Manage Homebrew Dependencies
3338
shell: bash
3439
run: |

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gui-qml/qml/DissolveMain.qml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ ApplicationWindow {
223223
Label {
224224
text: "Edges: " + graphModel.edgeCount
225225
}
226+
ToolButton {
227+
enabled: !graphModel.atRoot
228+
icon.color: graphModel.atRoot ? "grey" : "transparent"
229+
icon.source: "qrc:/IconsModule/arrowUp.svg"
230+
231+
onClicked: graphModel.upLevel()
232+
}
233+
Label {
234+
text: "Location: " + graphModel.location
235+
}
226236
}
227237
}
228238
GraphView {
@@ -240,6 +250,9 @@ ApplicationWindow {
240250
GraphDelegate {
241251
rootModel: graphModel
242252

253+
onDescended: function (idx) {
254+
graphModel.descend(idx);
255+
}
243256
onEdgeCreated: function (srcNode, srcOutput, tgtNode, tgtInput) {
244257
graphModel.addEdge(srcNode, srcOutput, tgtNode, tgtInput);
245258
}

src/gui/models/nodeGraph/graphModel.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ QAbstractListModel *GraphModel::nodes() { return &nodes_; }
4343

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

46+
QString GraphModel::location() const
47+
{
48+
if (!graph_)
49+
return "";
50+
return QString::fromStdString(graph_->location());
51+
};
52+
53+
bool GraphModel::atRoot() const
54+
{
55+
if (!graph_)
56+
return true;
57+
return !graph_->parentGraph();
58+
}
59+
4660
// Provide relative coordinates for an input on a node
4761
void GraphModel::addInput(int nodeIndex, QString paramName, double x, double y)
4862
{
@@ -61,6 +75,24 @@ void GraphModel::addOutput(int nodeIndex, QString paramName, double x, double y)
6175
node.outputPos.insert({paramName.toStdString(), {x, y}});
6276
}
6377

78+
// Switch to parent graph
79+
void GraphModel::upLevel()
80+
{
81+
if (!graph_)
82+
return;
83+
setGraph(graph_->parentGraph());
84+
}
85+
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+
6496
void GraphModel::emplace_back(int x, int y, QVariant type, QVariant name)
6597
{
6698
if (!graph_)

src/gui/models/nodeGraph/graphModel.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +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 NOTIFY graphChanged);
27+
Q_PROPERTY(bool atRoot READ atRoot NOTIFY graphChanged);
2628

2729
friend GraphNodeModel;
2830
friend GraphEdgeModel;
@@ -31,26 +33,30 @@ class GraphModel : public QObject
3133
GraphModel();
3234

3335
public:
34-
// Access the acutal nodes in the model
36+
// Access the actual nodes in the model
3537
Graph *graph();
3638

3739
void setGraph(Graph *graph);
3840

3941
// The model for the edges in the graph
4042
GraphEdgeModel *edges();
41-
// The modelfor the nodes in the graph
43+
// The model for the nodes in the graph
4244
QAbstractListModel *nodes();
4345
// The total number of nodes in the graph
4446
int count();
4547
// The total number of edges in the graph
4648
int nEdges();
49+
// The path to the current graph
50+
QString location() const;
51+
// Whether the current graph has a parent
52+
bool atRoot() const;
4753

4854
protected:
4955
// The abstract data model for the nodes
5056
GraphNodeModel nodes_;
5157
// The abstract data model for the edges between nodes
5258
GraphEdgeModel edges_;
53-
// The graph being modeled
59+
// The graph being modelled
5460
Graph *graph_;
5561
// Graph nodes wrapped in the wrappers
5662
std::vector<NodeWrapper> wrapped_;
@@ -85,4 +91,9 @@ class GraphModel : public QObject
8591

8692
// Add a new node at a specific position
8793
void emplace_back(int x, int y, QVariant type, QVariant name);
94+
95+
// Switch to parent graph
96+
void upLevel();
97+
// Move into an inner graph
98+
void descend(int index);
8899
};

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_;

0 commit comments

Comments
 (0)