Skip to content

Commit

Permalink
#228 Polish layouts sample. WIP.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <benoit@destrat.io>
  • Loading branch information
cneben committed Aug 15, 2024
1 parent c33a552 commit 66c5bfc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
58 changes: 48 additions & 10 deletions samples/layouts/layouts.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ ApplicationWindow {
navigable : true
resizeHandlerColor: "#03a9f4"
gridThickColor: Material.theme === Material.Dark ? "#4e4e4e" : "#c1c1c1"
property var treeRoot: undefined
graph: Qan.Graph {
parent: graphView
id: graph
Component.onCompleted: {
let n1 = graph.insertNode()
id: graphView
graphView.treeRoot = n1
n1.label = "n1"; n1.item.x=15; n1.item.y= 25
n1.item.ratio = 0.4

Expand All @@ -69,16 +72,13 @@ ApplicationWindow {
let n131 = graph.insertNode()
n131.label = "n131"; n131.item.x=225; n131.item.y= 125

graph.insertEdge(n1, n11);
graph.insertEdge(n1, n12);
graph.insertEdge(n1, n13);
graph.insertEdge(n12, n121);
graph.insertEdge(n12, n122);
//graph.insertEdge(n121, n1211);
graph.insertEdge(n13, n131);

orgTreeLayout.layoutOrientation = Qan.OrgTreeLayout.Mixed
orgTreeLayout.layout(n1);
graph.insertEdge(n1, n11)
graph.insertEdge(n1, n12)
graph.insertEdge(n1, n13)
graph.insertEdge(n12, n121)
graph.insertEdge(n12, n122)
//graph.insertEdge(n121, n1211)
graph.insertEdge(n13, n131)
}
Qan.OrgTreeLayout {
id: orgTreeLayout
Expand All @@ -101,6 +101,44 @@ ApplicationWindow {
contextMenu.y = pos.y
contextMenu.open()
}
Pane {
anchors.top: parent.top
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
width: 420
height: 50
padding: 2
RowLayout {
anchors.fill: parent
Label {
text: "Apply OrgTree:"
}
Button {
text: 'Mixed'
Material.roundedScale: Material.SmallScale
onClicked: {
orgTreeLayout.layoutOrientation = Qan.OrgTreeLayout.Mixed
orgTreeLayout.layout(graphView.treeRoot);
}
}
Button {
text: 'Vertical'
Material.roundedScale: Material.SmallScale
onClicked: {
orgTreeLayout.layoutOrientation = Qan.OrgTreeLayout.Vertical
orgTreeLayout.layout(graphView.treeRoot);
}
}
Button {
text: 'Horizontal'
Material.roundedScale: Material.SmallScale
onClicked: {
orgTreeLayout.layoutOrientation = Qan.OrgTreeLayout.Horizontal
orgTreeLayout.layout(graphView.treeRoot);
}
}
}
}
} // Qan.GraphView
}

4 changes: 2 additions & 2 deletions src/qanTreeLayouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ class OrgTreeLayout : public QObject
* running this algorithm on a non tree subgraph might lead to inifinite recursions or
* invalid layouts.
*/
void layout(qan::Node& root, qreal xSpacing = 35., qreal ySpacing = 25.) noexcept;
void layout(qan::Node& root, qreal xSpacing = 25., qreal ySpacing = 25.) noexcept;

//! QML invokable version of layout().
Q_INVOKABLE void layout(qan::Node* root, qreal xSpacing = 35., qreal ySpacing = 25.) noexcept;
Q_INVOKABLE void layout(qan::Node* root, qreal xSpacing = 25., qreal ySpacing = 25.) noexcept;
//@}
//-------------------------------------------------------------------------
};
Expand Down

0 comments on commit 66c5bfc

Please sign in to comment.