-
Notifications
You must be signed in to change notification settings - Fork 885
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
bansan85
wants to merge
27
commits into
paceholder:master
Choose a base branch
from
bansan85:add_qml
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add qml #449
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0aa87ed
Fix CMake warnings
bansan85 94be995
Fix MSVC warnings
bansan85 c96829b
Add calculator_test
bansan85 5bf9066
Missing MultiplicationModel.hpp in CMakeLists.txt
bansan85 c51ebc3
Minors fixes in library
bansan85 8c6b9fc
Apply clang-format
bansan85 285ebc9
Remove qml debug messages
bansan85 dc79eaf
IWYU qml
bansan85 31a267e
IWYU
bansan85 05752dd
Avoid overlap between connections and nodes
bansan85 144a7eb
Add Acquisition Viewer
bansan85 c755681
Fix Dynamic ports example
bansan85 671b4c4
Add Compute viewer that embedded parameters
bansan85 9639b52
Fix Load / Save for Acquisition Viewer
bansan85 0ea5f78
Implement full compute_viewer
bansan85 9860f83
Call WINDEPLOYQT_EXECUTABLE for all example
bansan85 4f8f543
Don't skip default action for mouse event
bansan85 ef934e0
Use ResultWidget
bansan85 2941a32
Add images for examples
bansan85 c650806
Add package init in Config.cmake.in
bansan85 cc44a1c
Fix examples Win static build
bansan85 ee0860d
Fix format and dedicated CI
bansan85 7290349
Remove openGL dependency
bansan85 7cc0759
Fix CI and reduce dependencies
bansan85 a70646d
Fix usage of dataInvalidated
bansan85 0888da8
Fix typos
bansan85 a195372
setPortData should return true if success
bansan85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ add_subdirectory(dynamic_ports) | |
|
||
add_subdirectory(lock_nodes_and_connections) | ||
|
||
add_subdirectory(calculator_qml) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QML needs Quick