Skip to content

Add qml #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0aa87ed
Fix CMake warnings
bansan85 Oct 17, 2023
94be995
Fix MSVC warnings
bansan85 Oct 17, 2023
c96829b
Add calculator_test
bansan85 Oct 21, 2024
5bf9066
Missing MultiplicationModel.hpp in CMakeLists.txt
bansan85 Oct 23, 2023
c51ebc3
Minors fixes in library
bansan85 Oct 24, 2023
8c6b9fc
Apply clang-format
bansan85 Oct 21, 2024
285ebc9
Remove qml debug messages
bansan85 Oct 21, 2024
dc79eaf
IWYU qml
bansan85 Oct 21, 2024
31a267e
IWYU
bansan85 Oct 21, 2024
05752dd
Avoid overlap between connections and nodes
bansan85 Nov 3, 2023
144a7eb
Add Acquisition Viewer
bansan85 Oct 21, 2024
c755681
Fix Dynamic ports example
bansan85 Nov 6, 2023
671b4c4
Add Compute viewer that embedded parameters
bansan85 Oct 21, 2024
9639b52
Fix Load / Save for Acquisition Viewer
bansan85 Nov 7, 2023
0ea5f78
Implement full compute_viewer
bansan85 Oct 21, 2024
9860f83
Call WINDEPLOYQT_EXECUTABLE for all example
bansan85 Nov 8, 2023
4f8f543
Don't skip default action for mouse event
bansan85 Nov 10, 2023
ef934e0
Use ResultWidget
bansan85 Oct 21, 2024
2941a32
Add images for examples
bansan85 Nov 15, 2023
c650806
Add package init in Config.cmake.in
bansan85 Jan 24, 2024
cc44a1c
Fix examples Win static build
bansan85 Oct 21, 2024
ee0860d
Fix format and dedicated CI
bansan85 Oct 21, 2024
7290349
Remove openGL dependency
bansan85 Jun 26, 2024
7cc0759
Fix CI and reduce dependencies
bansan85 Oct 21, 2024
a70646d
Fix usage of dataInvalidated
bansan85 Oct 21, 2024
0888da8
Fix typos
bansan85 Jun 26, 2024
a195372
setPortData should return true if success
bansan85 Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else()
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets)
endif()

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Gui OpenGL)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Gui OpenGL Quick)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QML needs Quick

message(STATUS "QT_VERSION: ${QT_VERSION}, QT_DIR: ${QT_DIR}")

if (${QT_VERSION} VERSION_LESS 5.11.0)
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ add_subdirectory(dynamic_ports)

add_subdirectory(lock_nodes_and_connections)

add_subdirectory(calculator_qml)

39 changes: 39 additions & 0 deletions examples/calculator_qml/AdditionModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "DecimalData.hpp"
#include "MathOperationDataModel.hpp"

#include <QtNodes/NodeDelegateModel>

#include <QtCore/QObject>
#include <QtWidgets/QLabel>

/// The model dictates the number of inputs and outputs for the Node.
/// In this example it has no logic.
class AdditionModel : public MathOperationDataModel
{
public:
~AdditionModel() = default;

public:
QString caption() const override { return QStringLiteral("Addition"); }

QString name() const override { return QStringLiteral("Addition"); }

private:
void compute() override
{
PortIndex const outPortIndex = 0;

auto n1 = _number1.lock();
auto n2 = _number2.lock();

if (n1 && n2) {
_result = std::make_shared<DecimalData>(n1->number() + n2->number());
} else {
_result.reset();
}

Q_EMIT dataUpdated(outPortIndex);
}
};
33 changes: 33 additions & 0 deletions examples/calculator_qml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(CALC_SOURCE_FILES
main.cpp MathOperationDataModel.cpp NumberDisplayDataModel.cpp
NumberSourceDataModel.cpp StringDataModel.cpp QmlWrapper.cpp)

set(CALC_HEADER_FILES
AdditionModel.hpp
DivisionModel.hpp
DecimalData.hpp
MathOperationDataModel.hpp
NumberDisplayDataModel.hpp
NumberSourceDataModel.hpp
SubtractionModel.hpp
StringDataModel.hpp
StringData.hpp
QmlWrapper.hpp)

set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
cmake_policy(SET CMP0071 NEW)

qt_standard_project_setup(REQUIRES 6.5)

qt_add_resources(QT_RESOURCES "main.qrc")
qt_add_executable(calculator_qml ${CALC_SOURCE_FILES} ${CALC_HEADER_FILES}
${QT_RESOURCES})

qt_add_qml_module(
calculator_qml VERSION 1.0 URI hello QML_FILES main.qml # FramedImage.qml RESOURCES
# img/world.png
)

target_link_libraries(calculator_qml PRIVATE Qt6::Gui Qt6::Quick QtNodes)
29 changes: 29 additions & 0 deletions examples/calculator_qml/DecimalData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <QtNodes/NodeData>

using QtNodes::NodeData;
using QtNodes::NodeDataType;

/// The class can potentially incapsulate any user data which
/// need to be transferred within the Node Editor graph
class DecimalData : public NodeData
{
public:
DecimalData()
: _number(0.0)
{}

DecimalData(double const number)
: _number(number)
{}

NodeDataType type() const override { return NodeDataType{"decimal", "Decimal"}; }

double number() const { return _number; }

QString numberAsText() const { return QString::number(_number, 'f'); }

private:
double _number;
};
74 changes: 74 additions & 0 deletions examples/calculator_qml/DivisionModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

#include "DecimalData.hpp"
#include "MathOperationDataModel.hpp"

#include <QtNodes/NodeDelegateModel>

#include <QtCore/QObject>
#include <QtWidgets/QLabel>

/// The model dictates the number of inputs and outputs for the Node.
/// In this example it has no logic.
class DivisionModel : public MathOperationDataModel
{
public:
virtual ~DivisionModel() {}

public:
QString caption() const override { return QStringLiteral("Division"); }

bool portCaptionVisible(PortType portType, PortIndex portIndex) const override
{
Q_UNUSED(portType);
Q_UNUSED(portIndex);
return true;
}

QString portCaption(PortType portType, PortIndex portIndex) const override
{
switch (portType) {
case PortType::In:
if (portIndex == 0)
return QStringLiteral("Dividend");
else if (portIndex == 1)
return QStringLiteral("Divisor");

break;

case PortType::Out:
return QStringLiteral("Result");

default:
break;
}
return QString();
}

QString name() const override { return QStringLiteral("Division"); }

private:
void compute() override
{
PortIndex const outPortIndex = 0;

auto n1 = _number1.lock();
auto n2 = _number2.lock();

if (n2 && (n2->number() == 0.0)) {
//modelValidationState = NodeValidationState::Error;
//modelValidationError = QStringLiteral("Division by zero error");
_result.reset();
} else if (n1 && n2) {
//modelValidationState = NodeValidationState::Valid;
//modelValidationError = QString();
_result = std::make_shared<DecimalData>(n1->number() / n2->number());
} else {
//modelValidationState = NodeValidationState::Warning;
//modelValidationError = QStringLiteral("Missing or incorrect inputs");
_result.reset();
}

Q_EMIT dataUpdated(outPortIndex);
}
};
42 changes: 42 additions & 0 deletions examples/calculator_qml/MathOperationDataModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "MathOperationDataModel.hpp"

#include "DecimalData.hpp"

unsigned int MathOperationDataModel::nPorts(PortType portType) const
{
unsigned int result;

if (portType == PortType::In)
result = 2;
else
result = 1;

return result;
}

NodeDataType MathOperationDataModel::dataType(PortType, PortIndex) const
{
return DecimalData().type();
}

std::shared_ptr<NodeData> MathOperationDataModel::outData(PortIndex)
{
return std::static_pointer_cast<NodeData>(_result);
}

void MathOperationDataModel::setInData(std::shared_ptr<NodeData> data, PortIndex portIndex)
{
auto numberData = std::dynamic_pointer_cast<DecimalData>(data);

if (!data) {
Q_EMIT dataInvalidated(0);
}

if (portIndex == 0) {
_number1 = numberData;
} else {
_number2 = numberData;
}

compute();
}
47 changes: 47 additions & 0 deletions examples/calculator_qml/MathOperationDataModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <QtNodes/NodeDelegateModel>

#include <QtCore/QJsonObject>
#include <QtCore/QObject>
#include <QtWidgets/QLabel>

#include <iostream>

class DecimalData;

using QtNodes::NodeData;
using QtNodes::NodeDataType;
using QtNodes::NodeDelegateModel;
using QtNodes::PortIndex;
using QtNodes::PortType;

/// The model dictates the number of inputs and outputs for the Node.
/// In this example it has no logic.
class MathOperationDataModel : public NodeDelegateModel
{
Q_OBJECT

public:
~MathOperationDataModel() = default;

public:
unsigned int nPorts(PortType portType) const override;

NodeDataType dataType(PortType portType, PortIndex portIndex) const override;

std::shared_ptr<NodeData> outData(PortIndex port) override;

void setInData(std::shared_ptr<NodeData> data, PortIndex portIndex) override;

QWidget *embeddedWidget() override { return nullptr; }

protected:
virtual void compute() = 0;

protected:
std::weak_ptr<DecimalData> _number1;
std::weak_ptr<DecimalData> _number2;

std::shared_ptr<DecimalData> _result;
};
44 changes: 44 additions & 0 deletions examples/calculator_qml/MultiplicationModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <QtNodes/NodeDelegateModel>

#include <QtCore/QObject>
#include <QtWidgets/QLabel>

#include "MathOperationDataModel.hpp"

#include "DecimalData.hpp"

/// The model dictates the number of inputs and outputs for the Node.
/// In this example it has no logic.
class MultiplicationModel : public MathOperationDataModel
{
public:
virtual ~MultiplicationModel() {}

public:
QString caption() const override { return QStringLiteral("Multiplication"); }

QString name() const override { return QStringLiteral("Multiplication"); }

private:
void compute() override
{
PortIndex const outPortIndex = 0;

auto n1 = _number1.lock();
auto n2 = _number2.lock();

if (n1 && n2) {
//modelValidationState = NodeValidationState::Valid;
//modelValidationError = QString();
_result = std::make_shared<DecimalData>(n1->number() * n2->number());
} else {
//modelValidationState = NodeValidationState::Warning;
//modelValidationError = QStringLiteral("Missing or incorrect inputs");
_result.reset();
}

Q_EMIT dataUpdated(outPortIndex);
}
};
Loading