-
Notifications
You must be signed in to change notification settings - Fork 834
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
Add qml #449
base: master
Are you sure you want to change the base?
Add qml #449
Changes from all commits
0aa87ed
94be995
c96829b
5bf9066
c51ebc3
8c6b9fc
285ebc9
dc79eaf
31a267e
05752dd
144a7eb
c755681
671b4c4
9639b52
0ea5f78
9860f83
4f8f543
ef934e0
2941a32
c650806
cc44a1c
ee0860d
7290349
7cc0759
a70646d
0888da8
a195372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
|
||
cmake_policy(SET CMP0072 NEW) # new in 3.11. The NEW behavior for this policy is to set OpenGL_GL_PREFERENCE to GLVND. | ||
cmake_policy(SET CMP0068 NEW) # new in 3.9. The NEW behavior of this policy is to ignore the RPATH settings for install_name on macOS. | ||
|
||
|
||
project(QtNodesLibrary CXX) | ||
|
||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) | ||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) | ||
set(CMAKE_DISABLE_SOURCE_CHANGES ON) | ||
set(OpenGL_GL_PREFERENCE LEGACY) | ||
set(CMAKE_DISABLE_SOURCE_CHANGES ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
get_directory_property(_has_parent PARENT_DIRECTORY) | ||
|
@@ -53,7 +50,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 Quick QuickWidgets) | ||
message(STATUS "QT_VERSION: ${QT_VERSION}, QT_DIR: ${QT_DIR}") | ||
|
||
if (${QT_VERSION} VERSION_LESS 5.11.0) | ||
|
@@ -161,7 +158,6 @@ target_link_libraries(QtNodes | |
Qt${QT_VERSION_MAJOR}::Core | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
Qt${QT_VERSION_MAJOR}::Gui | ||
Qt${QT_VERSION_MAJOR}::OpenGL | ||
) | ||
|
||
target_compile_definitions(QtNodes | ||
|
@@ -188,12 +184,6 @@ if(NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") | |
) | ||
endif() | ||
|
||
if(QT_NODES_DEVELOPER_DEFAULTS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is not defined anywhere. |
||
target_compile_features(QtNodes PUBLIC cxx_std_14) | ||
set_target_properties(QtNodes PROPERTIES CXX_EXTENSIONS OFF) | ||
endif() | ||
|
||
|
||
set_target_properties(QtNodes | ||
PROPERTIES | ||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
get_filename_component(QtNodes_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) | ||
@PACKAGE_INIT@ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Config.cmake.in pattern from CMake documentation |
||
|
||
include(CMakeFindDependencyMacro) | ||
|
||
|
@@ -8,11 +8,6 @@ find_dependency(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) | |
find_dependency(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS | ||
Core | ||
Widgets | ||
Gui | ||
OpenGL) | ||
Gui) | ||
|
||
if(NOT TARGET QtNodes::QtNodes) | ||
include("${QtNodes_CMAKE_DIR}/QtNodesTargets.cmake") | ||
endif() | ||
|
||
set(QtNodes_LIBRARIES QtNodes::QtNodes) | ||
include("${CMAKE_CURRENT_LIST_DIR}/QtNodesTargets.cmake") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#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 AcqData : public NodeData | ||
{ | ||
public: | ||
NodeDataType type() const override { return NodeDataType{"acquisition", ""}; } | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "AcqModel.hpp" | ||
#include "AcqData.hpp" | ||
#include <cstdlib> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an example with multiple nodes. 2941a32#diff-120ecb7b30a5ce4c1454cc1df1fc127292170959b6e58c6aec19aed28f9932b8 |
||
#include <QColor> | ||
#include <QInputDialog> | ||
#include <QJsonValue> | ||
#include <QJsonValueRef> | ||
#include <QLineEdit> | ||
#include <QtNodes/NodeDelegateModel> | ||
|
||
using QtNodes::NodeStyle; | ||
|
||
unsigned int AcqModel::nPorts(PortType portType) const | ||
{ | ||
unsigned int result; | ||
|
||
if (portType == PortType::In) | ||
result = 1; | ||
else | ||
result = 1; | ||
|
||
return result; | ||
} | ||
|
||
NodeDataType AcqModel::dataType(PortType, PortIndex) const | ||
{ | ||
return AcqData().type(); | ||
} | ||
|
||
std::shared_ptr<NodeData> AcqModel::outData(PortIndex) | ||
{ | ||
return std::static_pointer_cast<NodeData>(_result); | ||
} | ||
|
||
void AcqModel::setInData(std::shared_ptr<NodeData> data, PortIndex portIndex) | ||
{ | ||
auto numberData = std::dynamic_pointer_cast<AcqData>(data); | ||
|
||
if (!data) { | ||
Q_EMIT dataInvalidated(0); | ||
} | ||
} | ||
|
||
QWidget *AcqModel::embeddedWidget() | ||
{ | ||
if (_result) { | ||
return nullptr; | ||
} | ||
|
||
_result = std::make_shared<AcqData>(); | ||
|
||
if (_title.isEmpty()) { | ||
bool ok; | ||
|
||
QString text = QInputDialog::getText(nullptr, | ||
"Acquisition node", | ||
"Title:", | ||
QLineEdit::Normal, | ||
"", | ||
&ok); | ||
if (ok && !text.isEmpty()) | ||
_title = text; | ||
} | ||
|
||
NodeStyle style; | ||
style.GradientColor0 = {rand() % 256, rand() % 256, rand() % 256}; | ||
style.GradientColor1 = {rand() % 256, rand() % 256, rand() % 256}; | ||
style.GradientColor2 = {rand() % 256, rand() % 256, rand() % 256}; | ||
style.GradientColor3 = {rand() % 256, rand() % 256, rand() % 256}; | ||
setNodeStyle(style); | ||
|
||
return nullptr; | ||
} | ||
|
||
QJsonObject AcqModel::save() const | ||
{ | ||
QJsonObject retval = NodeDelegateModel::save(); | ||
retval["Title"] = _title; | ||
return retval; | ||
} | ||
|
||
void AcqModel::load(QJsonObject const &object) | ||
{ | ||
NodeDelegateModel::load(object); | ||
_title = object["Title"].toString(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <QJsonObject> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QStringLiteral> | ||
#include <QWidget> | ||
#include <QtNodes/NodeDelegateModel> | ||
|
||
class AcqData; | ||
|
||
using QtNodes::ConnectionPolicy; | ||
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 AcqModel : public NodeDelegateModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
~AcqModel() override = 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; | ||
|
||
QString caption() const override { return _title; } | ||
|
||
QString name() const override { return QStringLiteral("Acquisition"); } | ||
|
||
ConnectionPolicy portConnectionPolicy(PortType, PortIndex) const override | ||
{ | ||
return ConnectionPolicy::Many; | ||
} | ||
|
||
QJsonObject save() const override; | ||
|
||
void load(QJsonObject const &) override; | ||
|
||
private: | ||
std::shared_ptr<AcqData> _result; | ||
QString _title; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
set(ACQ_SOURCE_FILES main.cpp AcqModel.cpp) | ||
|
||
set(ACQ_HEADER_FILES AcqData.hpp AcqModel.hpp) | ||
|
||
add_executable(acquisition_viewer WIN32 ${ACQ_SOURCE_FILES} ${ACQ_HEADER_FILES} | ||
CMakeLists.txt) | ||
|
||
target_link_libraries(acquisition_viewer QtNodes) | ||
|
||
if(WIN32 AND BUILD_SHARED_LIBS) | ||
add_custom_command( | ||
TARGET acquisition_viewer | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E env VCINSTALLDIR=${CMAKE_GENERATOR_INSTANCE}/VC | ||
${WINDEPLOYQT_EXECUTABLE} --pdb "$<TARGET_FILE:acquisition_viewer>") | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "AcqModel.hpp" | ||
#include <memory> | ||
#include <QAction> | ||
#include <QApplication> | ||
#include <QMenu> | ||
#include <QMenuBar> | ||
#include <QObject> | ||
#include <QPoint> | ||
#include <QRect> | ||
#include <QScreen> | ||
#include <QVBoxLayout> | ||
#include <QWidget> | ||
#include <QtNodes/ConnectionStyle> | ||
#include <QtNodes/DataFlowGraphicsScene> | ||
#include <QtNodes/GraphicsView> | ||
|
||
using QtNodes::ConnectionStyle; | ||
using QtNodes::DataFlowGraphicsScene; | ||
using QtNodes::DataFlowGraphModel; | ||
using QtNodes::GraphicsView; | ||
using QtNodes::NodeDelegateModelRegistry; | ||
|
||
static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels() | ||
{ | ||
auto ret = std::make_shared<NodeDelegateModelRegistry>(); | ||
|
||
ret->registerModel<AcqModel>("Acquisition"); | ||
|
||
return ret; | ||
} | ||
|
||
static void setStyle() | ||
{ | ||
/* | ||
ConnectionStyle::setConnectionStyle( | ||
R"( | ||
{ | ||
"ConnectionStyle": { | ||
"ConstructionColor": "gray", | ||
"NormalColor": "black", | ||
"SelectedColor": "gray", | ||
"SelectedHaloColor": "deepskyblue", | ||
"HoveredColor": "deepskyblue", | ||
|
||
"LineWidth": 3.0, | ||
"ConstructionLineWidth": 2.0, | ||
"PointDiameter": 10.0, | ||
|
||
"UseDataDefinedColors": true | ||
} | ||
} | ||
)");*/ | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication app(argc, argv); | ||
|
||
setStyle(); | ||
|
||
std::shared_ptr<NodeDelegateModelRegistry> registry = registerDataModels(); | ||
|
||
QWidget mainWidget; | ||
|
||
auto menuBar = new QMenuBar(); | ||
QMenu *menu = menuBar->addMenu("File"); | ||
auto saveAction = menu->addAction("Save Scene"); | ||
auto loadAction = menu->addAction("Load Scene"); | ||
|
||
QVBoxLayout *l = new QVBoxLayout(&mainWidget); | ||
|
||
DataFlowGraphModel dataFlowGraphModel(registry); | ||
|
||
l->addWidget(menuBar); | ||
auto scene = new DataFlowGraphicsScene(dataFlowGraphModel, &mainWidget); | ||
|
||
auto view = new GraphicsView(scene); | ||
l->addWidget(view); | ||
l->setContentsMargins(0, 0, 0, 0); | ||
l->setSpacing(0); | ||
|
||
QObject::connect(saveAction, &QAction::triggered, scene, &DataFlowGraphicsScene::save); | ||
|
||
QObject::connect(loadAction, &QAction::triggered, scene, &DataFlowGraphicsScene::load); | ||
|
||
QObject::connect(scene, &DataFlowGraphicsScene::sceneLoaded, view, &GraphicsView::centerScene); | ||
|
||
mainWidget.setWindowTitle("Data Flow: simplest calculator"); | ||
mainWidget.resize(800, 600); | ||
// Center window. | ||
mainWidget.move(QApplication::primaryScreen()->availableGeometry().center() | ||
- mainWidget.rect().center()); | ||
mainWidget.showNormal(); | ||
|
||
return app.exec(); | ||
} |
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.
CMAKE_MODULE_PATH is a list. Better use
list(APPEND
. See https://stackoverflow.com/questions/52730397/how-can-i-set-cmake-module-path-for-doing-regular-and-out-of-source-builds-in-cm