Skip to content

Commit 2769409

Browse files
committed
Expose Node and Connection classes (paceholder#97)
1 parent 4278637 commit 2769409

9 files changed

Lines changed: 74 additions & 91 deletions

File tree

include/nodes/Connection

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../../src/Connection.hpp"

include/nodes/Node

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../../src/Node.hpp"

src/Connection.hpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,11 @@
1212
#include "Serializable.hpp"
1313
#include "ConnectionState.hpp"
1414
#include "ConnectionGeometry.hpp"
15+
#include "QUuidStdHash.hpp"
16+
#include "Export.hpp"
1517

1618
class QPointF;
1719

18-
namespace std
19-
{
20-
template<>
21-
struct hash<QUuid>
22-
{
23-
inline
24-
std::size_t
25-
operator()(QUuid const& uid) const
26-
{
27-
return qHash(uid);
28-
}
29-
};
30-
}
31-
3220
namespace QtNodes
3321
{
3422

@@ -37,7 +25,7 @@ class NodeData;
3725
class ConnectionGraphicsObject;
3826

3927
///
40-
class Connection
28+
class NODE_EDITOR_PUBLIC Connection
4129
: public QObject
4230
, public Serializable
4331
{

src/DataModelRegistry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NODE_EDITOR_PUBLIC DataModelRegistry
1818
{
1919

2020
public:
21-
21+
2222
using RegistryItemPtr = std::unique_ptr<NodeDataModel>;
2323
using RegisteredModelsMap = std::unordered_map<QString, RegistryItemPtr>;
2424
using RegisteredModelsCategoryMap = std::unordered_map<QString, QString>;

src/FlowScene.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "NodeGraphicsObject.hpp"
2323
#include "ConnectionGraphicsObject.hpp"
2424

25+
#include "Connection.hpp"
26+
2527
#include "FlowItemInterface.hpp"
2628
#include "FlowView.hpp"
2729
#include "DataModelRegistry.hpp"

src/FlowScene.hpp

Lines changed: 42 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <memory>
99
#include <functional>
1010

11-
#include "Connection.hpp"
11+
#include "QUuidStdHash.hpp"
1212
#include "Export.hpp"
1313
#include "DataModelRegistry.hpp"
1414

@@ -19,6 +19,7 @@ class NodeDataModel;
1919
class FlowItemInterface;
2020
class Node;
2121
class NodeGraphicsObject;
22+
class Connection;
2223
class ConnectionGraphicsObject;
2324
class NodeStyle;
2425

@@ -36,113 +37,80 @@ class NODE_EDITOR_PUBLIC FlowScene
3637

3738
public:
3839

39-
std::shared_ptr<Connection>
40-
createConnection(PortType connectedPort,
41-
Node& node,
42-
PortIndex portIndex);
40+
std::shared_ptr<Connection>createConnection(PortType connectedPort,
41+
Node& node,
42+
PortIndex portIndex);
4343

44-
std::shared_ptr<Connection>
45-
createConnection(Node& nodeIn,
46-
PortIndex portIndexIn,
47-
Node& nodeOut,
48-
PortIndex portIndexOut);
44+
std::shared_ptr<Connection>createConnection(Node& nodeIn,
45+
PortIndex portIndexIn,
46+
Node& nodeOut,
47+
PortIndex portIndexOut);
4948

50-
std::shared_ptr<Connection>
51-
restoreConnection(QJsonObject const &connectionJson);
49+
std::shared_ptr<Connection>restoreConnection(QJsonObject const &connectionJson);
5250

53-
void
54-
deleteConnection(Connection& connection);
51+
void deleteConnection(Connection& connection);
5552

56-
Node&
57-
createNode(std::unique_ptr<NodeDataModel> && dataModel);
53+
Node&createNode(std::unique_ptr<NodeDataModel> && dataModel);
5854

59-
Node&
60-
restoreNode(QJsonObject const& nodeJson);
55+
Node&restoreNode(QJsonObject const& nodeJson);
6156

62-
void
63-
removeNode(Node& node);
57+
void removeNode(Node& node);
6458

65-
DataModelRegistry&
66-
registry() const;
59+
DataModelRegistry&registry() const;
6760

68-
void
69-
setRegistry(std::shared_ptr<DataModelRegistry> registry);
61+
void setRegistry(std::shared_ptr<DataModelRegistry> registry);
7062

71-
void
72-
iterateOverNodes(std::function<void(Node*)> visitor);
63+
void iterateOverNodes(std::function<void(Node*)> visitor);
7364

74-
void
75-
iterateOverNodeData(std::function<void(NodeDataModel*)> visitor);
65+
void iterateOverNodeData(std::function<void(NodeDataModel*)> visitor);
7666

77-
void
78-
iterateOverNodeDataDependentOrder(std::function<void(NodeDataModel*)> visitor);
67+
void iterateOverNodeDataDependentOrder(std::function<void(NodeDataModel*)> visitor);
7968

80-
QPointF
81-
getNodePosition(const Node& node) const;
69+
QPointF getNodePosition(const Node& node) const;
8270

83-
void
84-
setNodePosition(Node& node, const QPointF& pos) const;
85-
86-
QSizeF
87-
getNodeSize(const Node& node) const;
71+
void setNodePosition(Node& node, const QPointF& pos) const;
72+
73+
QSizeF getNodeSize(const Node& node) const;
8874
public:
8975

90-
std::unordered_map<QUuid, std::unique_ptr<Node> > const &
91-
nodes() const;
76+
std::unordered_map<QUuid, std::unique_ptr<Node> > const &nodes() const;
9277

93-
std::unordered_map<QUuid, std::shared_ptr<Connection> > const &
94-
connections() const;
78+
std::unordered_map<QUuid, std::shared_ptr<Connection> > const &connections() const;
9579

96-
std::vector<Node*>
97-
selectedNodes() const;
80+
std::vector<Node*>selectedNodes() const;
9881

9982
public:
10083

101-
void
102-
clearScene();
84+
void clearScene();
10385

104-
void
105-
save() const;
86+
void save() const;
10687

107-
void
108-
load();
88+
void load();
10989

110-
QByteArray
111-
saveToMemory() const;
90+
QByteArray saveToMemory() const;
11291

113-
void
114-
loadFromMemory(const QByteArray& data);
92+
void loadFromMemory(const QByteArray& data);
11593

116-
signals:
94+
signals:
11795

118-
void
119-
nodeCreated(Node &n);
96+
void nodeCreated(Node &n);
12097

121-
void
122-
nodeDeleted(Node &n);
98+
void nodeDeleted(Node &n);
12399

124-
void
125-
connectionCreated(Connection &c);
126-
void
127-
connectionDeleted(Connection &c);
100+
void connectionCreated(Connection &c);
101+
void connectionDeleted(Connection &c);
128102

129-
void
130-
nodeMoved(Node& n, const QPointF& newLocation);
103+
void nodeMoved(Node& n, const QPointF& newLocation);
131104

132-
void
133-
nodeDoubleClicked(Node& n);
105+
void nodeDoubleClicked(Node& n);
134106

135-
void
136-
connectionHovered(Connection& c, QPoint screenPos);
107+
void connectionHovered(Connection& c, QPoint screenPos);
137108

138-
void
139-
nodeHovered(Node& n, QPoint screenPos);
109+
void nodeHovered(Node& n, QPoint screenPos);
140110

141-
void
142-
connectionHoverLeft(Connection& c);
111+
void connectionHoverLeft(Connection& c);
143112

144-
void
145-
nodeHoverLeft(Node& n);
113+
void nodeHoverLeft(Node& n);
146114

147115
private:
148116

src/Node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ConnectionState;
2525
class NodeGraphicsObject;
2626
class NodeDataModel;
2727

28-
class Node
28+
class NODE_EDITOR_PUBLIC Node
2929
: public QObject
3030
, public Serializable
3131
{

src/QStringStdHash.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <functional>
4+
35
#include <QtCore/QString>
46
#include <QtCore/QVariant>
57

src/QUuidStdHash.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <functional>
4+
5+
#include <QtCore/QUuid>
6+
#include <QtCore/QVariant>
7+
8+
namespace std
9+
{
10+
template<>
11+
struct hash<QUuid>
12+
{
13+
inline
14+
std::size_t
15+
operator()(QUuid const& uid) const
16+
{
17+
return qHash(uid);
18+
}
19+
};
20+
}
21+

0 commit comments

Comments
 (0)