Skip to content

Commit

Permalink
advanced sample for collapsing childs / ancestors is working.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Nov 17, 2023
1 parent 3bbb901 commit 7ac8ff2
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 9 deletions.
106 changes: 106 additions & 0 deletions samples/advanced/AdvancedNode.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Copyright (c) 2008-2022, Benoit AUTHEMAN All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the author or Destrat.io nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

//-----------------------------------------------------------------------------
// This file is a part of the QuickQanava software library. Copyright 2015 Benoit AUTHEMAN.
//
// \file AdvancedNode.qml
// \author [email protected]
// \date 2023 11 17
//-----------------------------------------------------------------------------

import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3

import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan

Qan.NodeItem {
id: customNode
width: 110; height: 60

/*Qan.RectGlowEffect {
anchors.fill: parent
style: customNode.style
}*/

RowLayout {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.top
anchors.bottomMargin: 4

ToolButton {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
icon.source: 'qrc:/collapse-parents.png'
visible: customNode.node && customNode.node.inNodes.length > 0
property bool collapsed: false
checked: collapsed
checkable: true
onClicked: {
customNode.collapseAncestors(collapsed)
collapsed = !collapsed
}
}
ToolButton {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
icon.source: 'qrc:/collapse-childs.png'
visible: customNode.node && customNode.node.outNodes.length > 0
property bool collapsed: false
checked: collapsed
checkable: true
onClicked: {
customNode.collapseChilds(collapsed)
collapsed = !collapsed
}
}
}

Item {
anchors.fill: parent
Rectangle {
id: background
anchors.fill: parent
radius: 10; color: light
border.color: "violet"; border.width: 2
readonly property color dark: "blue"
readonly property color light: "lightblue"
Label {
anchors.fill: parent
anchors.margins: 5
text: "Custom Node"
}
CheckBox {
anchors.bottom: parent.bottom; anchors.left: parent.left
text: "Light"
checked: background.color === background.light
onClicked: background.color = ( background.color === background.light ? background.dark : background.light )
}
}
}
}
16 changes: 7 additions & 9 deletions samples/advanced/advanced.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,24 @@ ApplicationWindow {
connectorEnabled: true
objectName: "graph"
anchors.fill: parent
property var advancedNodeDelegate: Qt.createComponent("qrc:/AdvancedNode.qml")
Component.onCompleted: {
const g1 = topology.insertGroup();
g1.label = "GROUP";
g1.item.x = 300; g1.item.y = 80;
g1.item.width = 450; g1.item.height = 250;
g1.item.width = 450; g1.item.height = 150;

const n1 = topology.insertNode();
const n1 = topology.insertNode(advancedNodeDelegate);
topology.groupNode(g1, n1);
n1.label = "N1";
n1.item.x = 10; n1.item.y = 15;
n1.item.x = 10; n1.item.y = 35;

const n2 = topology.insertNode();
const n2 = topology.insertNode(advancedNodeDelegate);
topology.groupNode(g1, n2);
n2.label = "N2";
n2.item.x = 180; n2.item.y = 15;
n2.item.x = 180; n2.item.y = 35;

topology.insertEdge(n1, n2);

const n3 = topology.insertNode();
n3.label = "N3";
const n3 = topology.insertNode(advancedNodeDelegate);
n3.item.x = 850; n3.item.y = 80 + 50;
topology.insertEdge(n2, n3);

Expand Down
3 changes: 3 additions & 0 deletions samples/advanced/advanced.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<RCC>
<qresource prefix="/">
<file>advanced.qml</file>
<file>AdvancedNode.qml</file>
<file>qtquickcontrols2.conf</file>
<file>collapse-childs.png</file>
<file>collapse-parents.png</file>
</qresource>
</RCC>
Binary file added samples/advanced/collapse-childs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/advanced/collapse-parents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7ac8ff2

Please sign in to comment.