DataFlowModel.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef DATAFLOWMODEL_H
  2. #define DATAFLOWMODEL_H
  3. #include <QtNodes/DataFlowGraphModel>
  4. using QtNodes::ConnectionId;
  5. using QtNodes::DataFlowGraphModel;
  6. using QtNodes::NodeDelegateModelRegistry;
  7. using QtNodes::NodeFlag;
  8. using QtNodes::NodeFlags;
  9. using QtNodes::NodeId;
  10. class DataFlowModel : public DataFlowGraphModel
  11. {
  12. public:
  13. DataFlowModel(std::shared_ptr<NodeDelegateModelRegistry> registry)
  14. : DataFlowGraphModel(std::move(registry)), _detachPossible { true }, _nodesLocked { false }
  15. {
  16. }
  17. bool detachPossible(ConnectionId const) const override { return _detachPossible; }
  18. void setDetachPossible(bool d = true) { _detachPossible = d; }
  19. //----
  20. NodeFlags nodeFlags(NodeId nodeId) const override
  21. {
  22. auto basicFlags = DataFlowGraphModel::nodeFlags(nodeId);
  23. if (_nodesLocked)
  24. basicFlags |= NodeFlag::Locked;
  25. return basicFlags;
  26. }
  27. void setNodesLocked(bool b = true)
  28. {
  29. _nodesLocked = b;
  30. for (NodeId nodeId : allNodeIds()) {
  31. Q_EMIT nodeFlagsUpdated(nodeId);
  32. }
  33. }
  34. private:
  35. bool _detachPossible;
  36. bool _nodesLocked;
  37. };
  38. #endif // DATAFLOWMODEL_H