-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathNodeDelegateModel.hpp
More file actions
137 lines (95 loc) · 3.86 KB
/
NodeDelegateModel.hpp
File metadata and controls
137 lines (95 loc) · 3.86 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#pragma once
#include <memory>
#include <QtWidgets/QWidget>
#include "Definitions.hpp"
#include "Export.hpp"
#include "NodeData.hpp"
#include "NodeStyle.hpp"
#include "Serializable.hpp"
namespace QtNodes {
class StyleCollection;
/**
* The class wraps Node-specific data operations and propagates it to
* the nesting DataFlowGraphModel which is a subclass of
* AbstractGraphModel.
* This class is the same what has been called NodeDataModel before v3.
*/
class NODE_EDITOR_PUBLIC NodeDelegateModel
: public QObject
, public Serializable
{
Q_OBJECT
public:
NodeDelegateModel();
virtual ~NodeDelegateModel() = default;
/// It is possible to hide caption in GUI
virtual bool captionVisible() const { return true; }
/// Caption is used in GUI
virtual QString caption() const = 0;
/// It is possible to hide port caption in GUI
virtual bool portCaptionVisible(PortType, PortIndex) const { return false; }
/// Port caption is used in GUI to label individual ports
virtual QString portCaption(PortType, PortIndex) const { return QString(); }
/// Name makes this model unique
virtual QString name() const = 0;
public:
QJsonObject save() const override;
void load(QJsonObject const &) override;
public:
virtual unsigned int nPorts(PortType portType) const = 0;
virtual NodeDataType dataType(PortType portType, PortIndex portIndex) const = 0;
public:
virtual ConnectionPolicy portConnectionPolicy(PortType, PortIndex) const;
NodeStyle const &nodeStyle() const;
void setNodeStyle(NodeStyle const &style);
public:
virtual void setInData(std::shared_ptr<NodeData> nodeData, PortIndex const portIndex) = 0;
virtual std::shared_ptr<NodeData> outData(PortIndex const port) = 0;
/**
* It is recommented to preform a lazy initialization for the
* embedded widget and create it inside this function, not in the
* constructor of the current model.
*
* Our Model Registry is able to shortly instantiate models in order
* to call the non-static `Model::name()`. If the embedded widget is
* allocated in the constructor but not actually embedded into some
* QGraphicsProxyWidget, we'll gonna have a dangling pointer.
*/
virtual QWidget *embeddedWidget() = 0;
virtual bool widgetEmbeddable() const { return true; }
virtual bool resizable() const { return false; }
public Q_SLOTS:
virtual void inputConnectionCreated(ConnectionId const &) {}
virtual void inputConnectionDeleted(ConnectionId const &) {}
virtual void outputConnectionCreated(ConnectionId const &) {}
virtual void outputConnectionDeleted(ConnectionId const &) {}
Q_SIGNALS:
/// Triggers the updates in the nodes downstream.
void dataUpdated(PortIndex const index);
/// Triggers the propagation of the empty data downstream.
void dataInvalidated(PortIndex const index);
void computingStarted();
void computingFinished();
void embeddedWidgetSizeUpdated();
/// Call this function before deleting the data associated with ports.
/**
* The function notifies the Graph Model and makes it remove and recompute the
* affected connection addresses.
*/
void portsAboutToBeDeleted(PortType const portType, PortIndex const first, PortIndex const last);
/// Call this function when data and port moditications are finished.
void portsDeleted();
/// Call this function before inserting the data associated with ports.
/**
* The function notifies the Graph Model and makes it recompute the affected
* connection addresses.
*/
void portsAboutToBeInserted(PortType const portType,
PortIndex const first,
PortIndex const last);
/// Call this function when data and port moditications are finished.
void portsInserted();
private:
NodeStyle _nodeStyle;
};
} // namespace QtNodes