Skip to content

Commit 6a4340e

Browse files
committed
Implement Converters separately from DataModels (paceholder#148)
1 parent 2340a0b commit 6a4340e

30 files changed

+537
-557
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ target_compile_definitions(nodes
7676
NODE_EDITOR_SHARED
7777
PRIVATE
7878
NODE_EDITOR_EXPORTS
79+
#NODE_DEBUG_DRAWING
7980
)
8081

8182
target_compile_options(nodes
8283
PRIVATE
83-
$<$<CXX_COMPILER_ID:MSVC>:/W4 /EHsc>
84+
$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4127 /EHsc>
8485
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra>
8586
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra>
8687
)

examples/calculator/Converters.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "Converters.hpp"
2+
3+
#include <QtGui/QDoubleValidator>
4+
5+
#include "DecimalData.hpp"
6+
#include "IntegerData.hpp"
7+
8+
9+
10+
std::shared_ptr<NodeData>
11+
DecimalToIntegerConverter::
12+
operator()(std::shared_ptr<NodeData> data)
13+
{
14+
auto numberData =
15+
std::dynamic_pointer_cast<DecimalData>(data);
16+
17+
if (numberData)
18+
{
19+
_integer = std::make_shared<IntegerData>(numberData->number());
20+
}
21+
22+
return _integer;
23+
}
24+
25+
26+
std::shared_ptr<NodeData>
27+
IntegerToDecimalConverter::
28+
operator()(std::shared_ptr<NodeData> data)
29+
{
30+
auto numberData =
31+
std::dynamic_pointer_cast<IntegerData>(data);
32+
33+
if (numberData)
34+
{
35+
_decimal = std::make_shared<DecimalData>(numberData->number());
36+
}
37+
38+
return _decimal;
39+
}
40+

examples/calculator/Converters.hpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include "DecimalData.hpp"
4+
#include "IntegerData.hpp"
5+
6+
using QtNodes::PortType;
7+
using QtNodes::PortIndex;
8+
using QtNodes::NodeData;
9+
using QtNodes::NodeDataType;
10+
using QtNodes::NodeDataModel;
11+
12+
class DecimalData;
13+
class IntegerData;
14+
15+
16+
class DecimalToIntegerConverter
17+
{
18+
19+
public:
20+
21+
std::shared_ptr<NodeData>
22+
operator()(std::shared_ptr<NodeData> data);
23+
24+
private:
25+
26+
std::shared_ptr<NodeData> _integer;
27+
};
28+
29+
30+
class IntegerToDecimalConverter
31+
{
32+
33+
public:
34+
35+
std::shared_ptr<NodeData>
36+
operator()(std::shared_ptr<NodeData> data);
37+
38+
private:
39+
40+
std::shared_ptr<NodeData> _decimal;
41+
};

examples/calculator/DecimalData.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <nodes/NodeDataModel>
44

55
using QtNodes::NodeDataType;
6+
using QtNodes::NodeData;
67

78
/// The class can potentially incapsulate any user data which
89
/// need to be transferred within the Node Editor graph

examples/calculator/DecimalToIntegerModel.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

examples/calculator/DecimalToIntegerModel.hpp

Lines changed: 0 additions & 74 deletions
This file was deleted.

examples/calculator/IntegerData.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include <nodes/NodeDataModel>
44

5+
using QtNodes::NodeDataType;
6+
using QtNodes::NodeData;
7+
58
/// The class can potentially incapsulate any user data which
69
/// need to be transferred within the Node Editor graph
710
class IntegerData : public NodeData

examples/calculator/IntegerToDecimalModel.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)