134 lines
2.3 KiB
C++
134 lines
2.3 KiB
C++
|
#pragma once
|
|||
|
|
|||
|
|
|||
|
#include <QtCore/QObject>
|
|||
|
#include <QtCore/QUuid>
|
|||
|
|
|||
|
#include <QtCore/QJsonObject>
|
|||
|
|
|||
|
#include "PortType.hpp"
|
|||
|
|
|||
|
#include "Export.hpp"
|
|||
|
#include "NodeState.hpp"
|
|||
|
#include "NodeGeometry.hpp"
|
|||
|
#include "NodeData.hpp"
|
|||
|
#include "NodeGraphicsObject.hpp"
|
|||
|
#include "ConnectionGraphicsObject.hpp"
|
|||
|
#include "Serializable.hpp"
|
|||
|
#include "memory.hpp"
|
|||
|
|
|||
|
namespace QtNodes
|
|||
|
{
|
|||
|
|
|||
|
class Connection;
|
|||
|
class ConnectionState;
|
|||
|
class NodeGraphicsObject;
|
|||
|
class NodeDataModel;
|
|||
|
|
|||
|
class Node
|
|||
|
: public QObject
|
|||
|
, public Serializable
|
|||
|
{
|
|||
|
Q_OBJECT
|
|||
|
|
|||
|
public:
|
|||
|
|
|||
|
/// NodeDataModel should be an rvalue and is moved into the Node
|
|||
|
Node(std::unique_ptr<NodeDataModel>&& dataModel);
|
|||
|
|
|||
|
virtual
|
|||
|
~Node();
|
|||
|
|
|||
|
public:
|
|||
|
/**
|
|||
|
* \brief Json序列化
|
|||
|
* \return json object
|
|||
|
*/
|
|||
|
QJsonObject
|
|||
|
save() const override;
|
|||
|
/**
|
|||
|
* \brief Json反序列化
|
|||
|
* \param json json
|
|||
|
*/
|
|||
|
void
|
|||
|
restore(QJsonObject const& json) override;
|
|||
|
|
|||
|
public:
|
|||
|
/**
|
|||
|
* \brief 节点的QUuid
|
|||
|
* \return uid
|
|||
|
*/
|
|||
|
QUuid
|
|||
|
id() const;
|
|||
|
|
|||
|
void reactToPossibleConnection(PortType,
|
|||
|
NodeDataType const&,
|
|||
|
QPointF const& scenePoint);
|
|||
|
|
|||
|
void
|
|||
|
resetReactionToConnection();
|
|||
|
|
|||
|
public:
|
|||
|
|
|||
|
NodeGraphicsObject const&
|
|||
|
nodeGraphicsObject() const;
|
|||
|
|
|||
|
NodeGraphicsObject&
|
|||
|
nodeGraphicsObject();
|
|||
|
|
|||
|
void
|
|||
|
setGraphicsObject(std::unique_ptr<NodeGraphicsObject>&& graphics);
|
|||
|
|
|||
|
NodeGeometry&
|
|||
|
nodeGeometry();
|
|||
|
|
|||
|
NodeGeometry const&
|
|||
|
nodeGeometry() const;
|
|||
|
|
|||
|
NodeState const&
|
|||
|
nodeState() const;
|
|||
|
|
|||
|
NodeState&
|
|||
|
nodeState();
|
|||
|
|
|||
|
NodeDataModel*
|
|||
|
nodeDataModel() const;
|
|||
|
|
|||
|
public Q_SLOTS: // data propagation
|
|||
|
|
|||
|
/// Propagates incoming data to the underlying model.
|
|||
|
void
|
|||
|
propagateData(std::shared_ptr<NodeData> nodeData,
|
|||
|
PortIndex inPortIndex,
|
|||
|
const QUuid& connectionId) const;
|
|||
|
|
|||
|
/// Fetches data from model's OUT #index port
|
|||
|
/// and propagates it to the connection
|
|||
|
void
|
|||
|
onDataUpdated(PortIndex index);
|
|||
|
|
|||
|
/// Propagates empty data to the attached connection.
|
|||
|
void
|
|||
|
onDataInvalidated(PortIndex index);
|
|||
|
|
|||
|
/// update the graphic part if the size of the embeddedwidget changes
|
|||
|
void
|
|||
|
onNodeSizeUpdated();
|
|||
|
|
|||
|
private:
|
|||
|
|
|||
|
// addressing
|
|||
|
QUuid _uid;
|
|||
|
|
|||
|
// data
|
|||
|
std::unique_ptr<NodeDataModel> _nodeDataModel;
|
|||
|
|
|||
|
NodeState _nodeState;
|
|||
|
|
|||
|
// painting
|
|||
|
NodeGeometry _nodeGeometry;
|
|||
|
|
|||
|
std::unique_ptr<NodeGraphicsObject> _nodeGraphicsObject;
|
|||
|
};
|
|||
|
}
|