forked from paceholder/nodeeditor
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#6) In port now supports ConnectionPolicy::Many
- Loading branch information
Showing
25 changed files
with
608 additions
and
170 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,3 +7,5 @@ add_subdirectory(calculator) | |
add_subdirectory(images) | ||
|
||
add_subdirectory(styles) | ||
|
||
add_subdirectory(state_machine) |
This file contains 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 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 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,5 @@ | ||
file(GLOB_RECURSE CPPS ./*.cpp ) | ||
|
||
add_executable(state_machine ${CPPS}) | ||
|
||
target_link_libraries(state_machine nodes) |
This file contains 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,86 @@ | ||
#include "StateNodeModel.hpp" | ||
|
||
QString | ||
StateNodeModel:: | ||
caption() const | ||
{ | ||
return QStringLiteral("State"); | ||
} | ||
|
||
|
||
QString | ||
StateNodeModel:: | ||
name() const | ||
{ | ||
return QStringLiteral("state_node"); | ||
} | ||
|
||
|
||
unsigned int | ||
StateNodeModel:: | ||
nPorts(PortType portType) const | ||
{ | ||
std::ignore = portType; | ||
return 1; | ||
} | ||
|
||
|
||
NodeDataType | ||
StateNodeModel:: | ||
dataType(PortType portType, PortIndex portIndex) const | ||
{ | ||
std::ignore = portType; | ||
std::ignore = portIndex; | ||
return getTranstitionType(); | ||
} | ||
|
||
|
||
NodeDataType | ||
StateNodeModel:: | ||
getTranstitionType() | ||
{ | ||
return NodeDataType{"transition_port", ""}; | ||
} | ||
|
||
|
||
QtNodes::NodeDataModel::ConnectionPolicy | ||
StateNodeModel:: | ||
portOutConnectionPolicy(PortIndex) const | ||
{ | ||
return ConnectionPolicy::Many; | ||
} | ||
|
||
|
||
QtNodes::NodeDataModel::ConnectionPolicy | ||
StateNodeModel:: | ||
portInConnectionPolicy(PortIndex) const | ||
{ | ||
return ConnectionPolicy::Many; | ||
} | ||
|
||
|
||
void | ||
StateNodeModel:: | ||
setInData(std::shared_ptr<NodeData> nodeData, PortIndex port) | ||
{ | ||
std::ignore = nodeData; | ||
std::ignore = port; | ||
} | ||
|
||
|
||
void | ||
StateNodeModel:: | ||
setInData(std::vector<std::shared_ptr<NodeData> > nodeData, PortIndex port) | ||
{ | ||
std::ignore = nodeData; | ||
std::ignore = port; | ||
} | ||
|
||
|
||
std::shared_ptr<NodeData> | ||
StateNodeModel:: | ||
outData(PortIndex port) | ||
{ | ||
std::ignore = port; | ||
return nullptr; | ||
} |
This file contains 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,28 @@ | ||
#pragma once | ||
|
||
#include <nodes/NodeDataModel> | ||
|
||
using QtNodes::NodeData; | ||
using QtNodes::PortIndex; | ||
using QtNodes::PortType; | ||
using QtNodes::NodeDataType; | ||
|
||
class StateNodeModel : public QtNodes::NodeDataModel | ||
{ | ||
public: | ||
static NodeDataType getTranstitionType(); | ||
|
||
QString caption() const override; | ||
QString name() const override; | ||
|
||
unsigned int nPorts(PortType portType) const override; | ||
NodeDataType dataType(PortType portType, PortIndex portIndex) const override; | ||
ConnectionPolicy portOutConnectionPolicy(PortIndex) const override; | ||
ConnectionPolicy portInConnectionPolicy(PortIndex) const override; | ||
|
||
void setInData(std::shared_ptr<NodeData> nodeData, PortIndex port) override; | ||
void setInData(std::vector<std::shared_ptr<NodeData> > nodeData, PortIndex port) override; | ||
std::shared_ptr<NodeData> outData(PortIndex port) override; | ||
|
||
QWidget* embeddedWidget() override { return nullptr; } | ||
}; |
This file contains 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,84 @@ | ||
#include "StateNodeModel.hpp" | ||
|
||
#include <nodes/FlowScene> | ||
#include <nodes/FlowView> | ||
#include <nodes/ConnectionStyle> | ||
|
||
#include <QtWidgets/QApplication> | ||
#include <QtWidgets/QMenuBar> | ||
#include <QtWidgets/QBoxLayout> | ||
|
||
using QtNodes::FlowScene; | ||
using QtNodes::FlowView; | ||
using QtNodes::DataModelRegistry; | ||
using QtNodes::ConnectionStyle; | ||
|
||
std::shared_ptr<DataModelRegistry> | ||
registerDataModels() | ||
{ | ||
std::shared_ptr<DataModelRegistry> registry(new DataModelRegistry()); | ||
|
||
registry->registerModel<StateNodeModel>(); | ||
|
||
return registry; | ||
} | ||
|
||
|
||
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(); | ||
|
||
QWidget mainWidget; | ||
|
||
auto menuBar = new QMenuBar(); | ||
auto saveAction = menuBar->addAction("Save.."); | ||
auto loadAction = menuBar->addAction("Load.."); | ||
|
||
QVBoxLayout *l = new QVBoxLayout(&mainWidget); | ||
|
||
l->addWidget(menuBar); | ||
auto scene = new FlowScene(registerDataModels(), &mainWidget); | ||
l->addWidget(new FlowView(scene)); | ||
l->setContentsMargins(0, 0, 0, 0); | ||
l->setSpacing(0); | ||
|
||
QObject::connect(saveAction, &QAction::triggered, | ||
scene, &FlowScene::save); | ||
|
||
QObject::connect(loadAction, &QAction::triggered, | ||
scene, &FlowScene::load); | ||
|
||
mainWidget.setWindowTitle("Simplest state editor"); | ||
mainWidget.resize(800, 600); | ||
mainWidget.showNormal(); | ||
|
||
return app.exec(); | ||
} |
This file contains 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 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
Oops, something went wrong.