2016-08-21 19:20:29 +02:00
|
|
|
#include <nodes/NodeData>
|
|
|
|
|
#include <nodes/FlowScene>
|
2016-09-23 09:45:07 +02:00
|
|
|
#include <nodes/FlowView>
|
2017-01-30 18:03:50 +01:00
|
|
|
#include <nodes/ConnectionStyle>
|
2018-04-03 18:46:54 +02:00
|
|
|
#include <nodes/TypeConverter>
|
2016-08-21 19:20:29 +02:00
|
|
|
|
|
|
|
|
#include <QtWidgets/QApplication>
|
2016-09-23 09:45:07 +02:00
|
|
|
#include <QtWidgets/QVBoxLayout>
|
|
|
|
|
#include <QtWidgets/QMenuBar>
|
2016-08-21 19:20:29 +02:00
|
|
|
|
|
|
|
|
#include <nodes/DataModelRegistry>
|
|
|
|
|
|
|
|
|
|
#include "NumberSourceDataModel.hpp"
|
|
|
|
|
#include "NumberDisplayDataModel.hpp"
|
|
|
|
|
#include "AdditionModel.hpp"
|
|
|
|
|
#include "SubtractionModel.hpp"
|
2016-08-22 22:47:20 +02:00
|
|
|
#include "MultiplicationModel.hpp"
|
|
|
|
|
#include "DivisionModel.hpp"
|
2017-01-30 18:03:50 +01:00
|
|
|
#include "ModuloModel.hpp"
|
2018-04-03 18:46:54 +02:00
|
|
|
#include "Converters.hpp"
|
|
|
|
|
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2017-01-30 10:31:43 +01:00
|
|
|
using QtNodes::DataModelRegistry;
|
|
|
|
|
using QtNodes::FlowScene;
|
|
|
|
|
using QtNodes::FlowView;
|
2017-01-30 18:03:50 +01:00
|
|
|
using QtNodes::ConnectionStyle;
|
2018-04-03 18:46:54 +02:00
|
|
|
using QtNodes::TypeConverter;
|
|
|
|
|
using QtNodes::TypeConverterId;
|
2017-01-30 10:31:43 +01:00
|
|
|
|
2016-11-25 18:02:44 -07:00
|
|
|
static std::shared_ptr<DataModelRegistry>
|
2016-08-21 19:20:29 +02:00
|
|
|
registerDataModels()
|
|
|
|
|
{
|
2016-11-25 18:02:44 -07:00
|
|
|
auto ret = std::make_shared<DataModelRegistry>();
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<NumberSourceDataModel>("Sources");
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<NumberDisplayDataModel>("Displays");
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<AdditionModel>("Operators");
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<SubtractionModel>("Operators");
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<MultiplicationModel>("Operators");
|
2016-08-22 22:47:20 +02:00
|
|
|
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<DivisionModel>("Operators");
|
2016-08-22 22:47:20 +02:00
|
|
|
|
2017-03-09 13:31:26 +01:00
|
|
|
ret->registerModel<ModuloModel>("Operators");
|
2017-01-30 18:03:50 +01:00
|
|
|
|
2018-04-03 18:46:54 +02:00
|
|
|
ret->registerTypeConverter(std::make_pair(DecimalData().type(),
|
|
|
|
|
IntegerData().type()),
|
|
|
|
|
TypeConverter{DecimalToIntegerConverter()});
|
2017-01-30 18:03:50 +01:00
|
|
|
|
2018-04-03 18:46:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
ret->registerTypeConverter(std::make_pair(IntegerData().type(),
|
|
|
|
|
DecimalData().type()),
|
|
|
|
|
TypeConverter{IntegerToDecimalConverter()});
|
2017-01-30 18:03:50 +01:00
|
|
|
|
2016-11-22 14:08:12 -07:00
|
|
|
return ret;
|
2016-08-21 19:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-22 22:01:28 +01:00
|
|
|
|
2017-01-30 18:03:50 +01:00
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
setStyle()
|
|
|
|
|
{
|
|
|
|
|
ConnectionStyle::setConnectionStyle(
|
|
|
|
|
R"(
|
|
|
|
|
{
|
|
|
|
|
"ConnectionStyle": {
|
2017-06-08 09:03:37 +02:00
|
|
|
"ConstructionColor": "gray",
|
|
|
|
|
"NormalColor": "black",
|
|
|
|
|
"SelectedColor": "gray",
|
|
|
|
|
"SelectedHaloColor": "deepskyblue",
|
|
|
|
|
"HoveredColor": "deepskyblue",
|
|
|
|
|
|
|
|
|
|
"LineWidth": 3.0,
|
|
|
|
|
"ConstructionLineWidth": 2.0,
|
|
|
|
|
"PointDiameter": 10.0,
|
|
|
|
|
|
2017-01-30 18:03:50 +01:00
|
|
|
"UseDataDefinedColors": true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-08-21 19:20:29 +02:00
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
QApplication app(argc, argv);
|
2016-11-22 22:01:28 +01:00
|
|
|
|
2017-01-30 18:03:50 +01:00
|
|
|
setStyle();
|
|
|
|
|
|
2016-09-23 09:45:07 +02:00
|
|
|
QWidget mainWidget;
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2016-09-23 09:45:07 +02:00
|
|
|
auto menuBar = new QMenuBar();
|
|
|
|
|
auto saveAction = menuBar->addAction("Save..");
|
|
|
|
|
auto loadAction = menuBar->addAction("Load..");
|
2016-08-21 19:20:29 +02:00
|
|
|
|
2016-09-23 09:45:07 +02:00
|
|
|
QVBoxLayout *l = new QVBoxLayout(&mainWidget);
|
|
|
|
|
|
|
|
|
|
l->addWidget(menuBar);
|
2018-04-27 19:37:58 +02:00
|
|
|
auto scene = new FlowScene(registerDataModels(), &mainWidget);
|
2016-09-23 09:45:07 +02:00
|
|
|
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("Dataflow tools: simplest calculator");
|
|
|
|
|
mainWidget.resize(800, 600);
|
|
|
|
|
mainWidget.showNormal();
|
2016-08-21 19:20:29 +02:00
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|