-
Notifications
You must be signed in to change notification settings - Fork 949
Expand file tree
/
Copy pathmain.cpp
More file actions
115 lines (82 loc) · 2.9 KB
/
main.cpp
File metadata and controls
115 lines (82 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <nodes/NodeData>
#include <nodes/FlowScene>
#include <nodes/FlowView>
#include <nodes/ConnectionStyle>
#include <nodes/TypeConverter>
#include <QtWidgets/QApplication>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QMenuBar>
#include <nodes/DataModelRegistry>
#include "NumberSourceDataModel.hpp"
#include "NumberDisplayDataModel.hpp"
#include "AdditionModel.hpp"
#include "SubtractionModel.hpp"
#include "MultiplicationModel.hpp"
#include "DivisionModel.hpp"
#include "ModuloModel.hpp"
#include "Converters.hpp"
using QtNodes::DataModelRegistry;
using QtNodes::FlowScene;
using QtNodes::FlowView;
using QtNodes::ConnectionStyle;
using QtNodes::TypeConverter;
using QtNodes::TypeConverterId;
static std::shared_ptr<DataModelRegistry>
registerDataModels()
{
auto ret = std::make_shared<DataModelRegistry>();
ret->registerModel<NumberSourceDataModel>("Sources");
ret->registerModel<NumberDisplayDataModel>("Displays");
ret->registerModel<AdditionModel>("Operators");
ret->registerModel<SubtractionModel>("Operators");
ret->registerModel<MultiplicationModel>("Operators");
ret->registerModel<DivisionModel>("Operators");
ret->registerModel<ModuloModel>("Operators");
ret->registerTypeConverter(std::make_pair(DecimalData().type(),
IntegerData().type()),
TypeConverter{DecimalToIntegerConverter()});
ret->registerTypeConverter(std::make_pair(IntegerData().type(),
DecimalData().type()),
TypeConverter{IntegerToDecimalConverter()});
return ret;
}
static
auto
connectionStyle()
{
auto style = ConnectionStyle::defaultStyle();
style.setConstructionColor(QColor("gray"));
style.setNormalColor(QColor("black"));
style.setSelectedColor(QColor("gray"));
style.setSelectedHaloColor(QColor("deepskyblue"));
style.setHoveredColor(QColor("deepskyblue"));
style.setLineWidth(3.0);
style.setConstructionLineWidth(2.0);
style.setPointDiameter(10.0);
style.useDataDefinedColors(true);
return style;
}
int
main(int argc, char *argv[])
{
QApplication app(argc, argv);
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);
scene->setConnectionStyle(connectionStyle());
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();
return app.exec();
}