Skip to content

Commit

Permalink
Add support for qan::NodeBehaviour::host property.
Browse files Browse the repository at this point in the history
Add a new dataflow sample (WIP).

Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Dec 12, 2017
1 parent 9577603 commit 3ea0ad4
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 3 deletions.
2 changes: 2 additions & 0 deletions quickqanava.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test-connector.subdir = samples/connector
test-groups.subdir = samples/groups
test-selection.subdir = samples/selection
test-style.subdir = samples/style
test-dataflow.subdir = samples/dataflow

test-topology.subdir = samples/topology
#test-40k.subdir = samples/40k
Expand All @@ -23,5 +24,6 @@ SUBDIRS += test-groups
SUBDIRS += test-selection
SUBDIRS += test-style
SUBDIRS += test-topology
SUBDIRS += test-dataflow

#SUBDIRS += test-40k
54 changes: 54 additions & 0 deletions samples/dataflow/FlowNode.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright (c) 2008-2017, 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 FlowNode.qml
// \author [email protected]
// \date 2017 12 12
//-----------------------------------------------------------------------------

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0

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

Qan.NodeItem {
id: flowNodeItem
Layout.preferredWidth: 100
Layout.preferredHeight: 125
width: Layout.preferredWidth
height: Layout.preferredHeight

Qan.RectNodeTemplate {
anchors.fill: parent
nodeItem : parent
}
}
Binary file added samples/dataflow/Lenna-scaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions samples/dataflow/dataflow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright (c) 2008-2017, 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.
//
// \file dataflow.cpp
// \author [email protected]
// \date 2017 12 12
//-----------------------------------------------------------------------------

// Qt headers
#include <QApplication>
#include <QGuiApplication>
#include <QtQml>
#include <QQuickStyle>

// QuickQanava headers
#include <QuickQanava>

#include "./qanFlowNode.h"

using namespace qan;

//-----------------------------------------------------------------------------
int main( int argc, char** argv )
{
QApplication app(argc, argv); // Necessary for Qt.labs ColorDialog
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QQuickStyle::setStyle("Material");
QQmlApplicationEngine engine;
QuickQanava::initialize(&engine);
//qmlRegisterType< qan::FaceNode >( "QuickQanava", 2, 0, "AbstractFaceNode");
qmlRegisterType< qan::FlowGraph >( "QuickQanava.Samples", 1, 0, "FlowGraph");

engine.load(QUrl("qrc:/dataflow.qml"));
return app.exec();
}
//-----------------------------------------------------------------------------


16 changes: 16 additions & 0 deletions samples/dataflow/dataflow.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TEMPLATE = app
TARGET = test-dataflow
CONFIG += qt warn_on thread c++14
QT += widgets core gui qml quick

include(../../src/quickqanava.pri)

SOURCES += dataflow.cpp \
qanFlowNode.cpp

HEADERS += qanFlowNode.h

OTHER_FILES += dataflow.qml FlowNode.qml

RESOURCES += dataflow.qrc

60 changes: 60 additions & 0 deletions samples/dataflow/dataflow.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright (c) 2008-2017, 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.
*/

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

import QuickQanava 2.0 as Qan
import QuickQanava.Samples 1.0
import "qrc:/QuickQanava" as Qan

ApplicationWindow {
id: window
visible: true
width: 1280; height: 720
title: "Dataflow sample"

Pane { anchors.fill: parent }

Qan.GraphView {
id: graphView
anchors.fill: parent
navigable : true
graph: FlowGraph {
id: graph
connectorEnabled: true
Component.onCompleted: {
var i1 = graph.insertFlowNode()
i1.label = "Input"; i1.item.x = 50; i1.item.y = 50
var i2 = graph.insertFlowNode()
i2.label = "Input"; i2.item.x = 50; i2.item.y = 150
}
}
} // Qan.GraphView
}

8 changes: 8 additions & 0 deletions samples/dataflow/dataflow.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/">
<file>dataflow.qml</file>
<file>FlowNode.qml</file>
<file>Lenna-scaled.png</file>
<file>qtquickcontrols2.conf</file>
</qresource>
</RCC>
89 changes: 89 additions & 0 deletions samples/dataflow/qanFlowNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright (c) 2008-2017, 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.
//
// \file qanFaceNode.cpp
// \author [email protected]
// \date 2017 12 12
//-----------------------------------------------------------------------------

// QuickQanava headers
#include "../../src/QuickQanava.h"
#include "./qanFlowNode.h"

namespace qan { // ::qan

void FlowNodeBehaviour::inNodeInserted( qan::Node& inNode, qan::Edge& edge ) noexcept
{
const auto inFlowNode = qobject_cast<qan::FlowNode*>(&inNode);
const auto flowNodeHost = qobject_cast<qan::FlowNode*>(getHost());
if ( inFlowNode != nullptr &&
flowNodeHost != nullptr ) {
//
QObject::connect(inFlowNode, &qan::FlowNode::outputChanged,
flowNodeHost, &qan::FlowNode::inNodeOutputChanged);
}
}

void FlowNodeBehaviour::inNodeRemoved( qan::Node& inNode, qan::Edge& edge ) noexcept
{

}

QQmlComponent* FlowNode::delegate(QObject* caller) noexcept
{
static std::unique_ptr<QQmlComponent> qan_FlowNode_delegate;
if ( !qan_FlowNode_delegate &&
caller != nullptr ) {
const auto engine = qmlEngine(caller);
if ( engine != nullptr )
qan_FlowNode_delegate = std::make_unique<QQmlComponent>(engine, "qrc:/FlowNode.qml");
else qWarning() << "[static]qan::FlowNode::delegate(): Error: QML engine is nullptr.";
}
return qan_FlowNode_delegate.get();
}

void FlowNode::inNodeOutputChanged()
{
qDebug() << "In node output value changed for " << getLabel();
}

void FlowNode::setOutput(QVariant output) noexcept
{
_output = output;
emit outputChanged();
}

qan::Node* FlowGraph::insertFlowNode()
{
const auto flowNode = insertNode<FlowNode>(nullptr);
flowNode->installBehaviour(std::make_unique<FlowNodeBehaviour>());
return flowNode;
}

} // ::qan
Loading

0 comments on commit 3ea0ad4

Please sign in to comment.