MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ContentNode.hpp
1 #pragma once
2 
3 #include "GraphTypes.hpp"
4 #include "Slot.hpp"
5 
6 #include "UIComponent.hpp"
7 
8 namespace Showcase
9 {
25  class SHOWCASE_API ContentNode : public std::enable_shared_from_this<ContentNode>
26  {
27  public:
28  enum class Source
29  {
30  SELF = 0,
31  HOST_UI_NODE,
32  DEFAULT
33  };
34 
35  typedef std::vector<std::shared_ptr<ContentNode> > Nodes;
36  typedef QList<MultiWidgets::OperatorPtr> Operators;
37 
43  ContentNode(const GraphNode& node, UIComponentWeakPtr parentUiComponent,
44  const QByteArray & slotNameInUiComponent, bool contentRoot=false);
45 
47  virtual ~ContentNode();
48 
49  bool operator==(const ContentNode & node) const;
50  bool operator<(const ContentNode & node) const;
51 
54  void setSlots(const Slots& slot);
55 
57  void init();
58 
61  NodeId nodeId() const;
62 
65  bool isReady() const;
66 
70  bool isSlotReady(const QByteArray & slotName);
71 
75  QString componentName(const QByteArray & slotName) const;
76 
81  MultiWidgets::WidgetPtr createWidgetInstance(const QByteArray & slotName,
82  Valuable::Node::Uuid loggedParentId = 0);
83 
89  MultiWidgets::OperatorPtr createOperatorInstance(const QByteArray & slotName,
90  MultiWidgets::Widget & widget);
91 
98  Operators createOperatorInstancesForSlot(const QByteArray & slotName,
99  MultiWidgets::Widget & widget);
100 
103  Nodes children() const;
104 
107  float order() const;
108 
113  static QByteArray defaultContentNodeIdPrefix();
114 
117  void rewritePropertyKey(PropertyKey& key) const;
118 
121  void notifyCachedProperties(std::shared_ptr<UIComponentInstance> instance);
122 
124  void addListenerInstance(UIComponentInstancePtr instance);
125 
131  PropertyValue propertyValue(const PropertyKey & key);
132 
135  QByteArray type() const;
136 
137  private:
138  ComponentPtr createComponentWithoutLock(const QByteArray& slotName);
139 
140  MultiWidgets::OperatorPtr createOperatorInstanceWithoutLock(const QByteArray & slotName,
141  MultiWidgets::Widget & widget);
142 
143  void propertyReceived(const Property & property, Source source);
144  void propertyLost(const Property & property, Source source);
145 
146  void childFound(const NodeId & id);
147  void childLost(const NodeId & id);
148 
149  void childCompleted(const NodeId & id);
150  void childIncompleted(const NodeId & id);
151 
152  void completed();
153  void incompleted();
154 
155  void addEvents(CachedNodePtr node);
156  void addUiNodeEvents(CachedNodePtr node);
157  void addDefaultNodeEvents(CachedNodePtr node);
158 
159  ComponentPtr createComponent(const QByteArray & slotName);
160  void removeComponent(const QByteArray & slotName);
161 
162  void checkComplete();
163 
164  void sortChildren();
165 
166  QByteArray propertyPrefix() const;
167 
168  void prepareParentUiNodeCache();
169  void prepareOwnCache();
170  void prepareDefaultsCache();
171 
172  bool checkFoundPropertyPriority(const QByteArray & slotName,
173  const Property & property,
174  Source source);
175  bool checkLostPropertyPriority(const QByteArray & slotName,
176  Source source);
177 
178  void propertyFoundToComponents(const Property & property);
179  void propertyLostToComponents(const Property & property);
180 
181  void createPlaceholder(const QByteArray & slotName,
182  const Property & property);
183 
184  bool haveUiSlot(const QByteArray & name) const;
185 
186  void tryRestoreProperty(const QByteArray & slotName,
187  Source lostSource);
188  bool tryRestorePropertyFromSource(const QByteArray & slotName,
189  Source source);
190 
192  void applyCachedPropertiesToComponent(const Component & comp, ComponentInstance & instance);
193  void applyProperty(const Component & comp, ComponentInstance & instance,
194  const QByteArray & key, const PropertyValue & value,
195  Source source);
196 
199  void notifyCachedPropertiesToUiParent(UIComponentPtr ui);
200 
201  struct ComponentData
202  {
203  UIComponentPtr uiComponent;
204  ComponentPlaceholderPtr placeholder;
205  CachedGraphPtr cachedGraph;
206  };
207 
208  typedef std::unordered_map<QByteArray, ComponentData> SlotComponents;
209 
211  GraphNode m_node;
212 
216  UIComponentWeakPtr m_parentUiComponent;
218  QByteArray m_slotNameInUiComponent;
220  bool m_isGraphEntryPoint;
221 
226  Slots m_uiSlots;
227 
229  SlotComponents m_slotInstances;
230 
232  mutable std::mutex m_slotInstanceMutex;
233 
235  CachedNodePtr m_cachedNode;
237  CachedNodePtr m_cachedParentUiNode;
239  CachedNodePtr m_cachedDefaultsNode;
240 
242  mutable std::mutex m_childMutex;
244  Nodes m_children;
247  Nodes m_pendingChildren;
248 
250  bool m_isComplete;
251 
253  float m_order;
254 
255  QByteArray m_type;
256 
259  std::weak_ptr<ContentNode> m_parent;
260 
261  std::map<QByteArray, Source> m_activePropertySources;
262  PropertyMap m_contentProperties;
263 
264  mutable std::mutex m_propertyMutex;
265 
266  std::vector<std::weak_ptr<UIComponentInstance> > m_listenerInstances;
267  };
268  typedef std::shared_ptr<ContentNode> ContentNodePtr;
269  typedef std::weak_ptr<ContentNode> ContentNodeWeakPtr;
270 
271 }