1 #ifndef VIEWER_VIEWERNODE_H_INCLUDED
2 #define VIEWER_VIEWERNODE_H_INCLUDED
27 #include <type_traits>
34 template <
class ViewerType>
36 static const bool value =
false;
39 template <
class ViewerTYpe>
41 static const bool value =
false;
49 template <
class ViewerType,
class SubjectType>
54 ViewerNode(std::shared_ptr<Ws::MergedPreferences> p,
55 IViewerNode::ChildrenMap&& c,
58 ViewerNode(std::shared_ptr<Ws::MergedPreferences> p,
77 virtual IViewerNode::ChildrenMap::const_iterator
begin()
const;
80 virtual IViewerNode::ChildrenMap::const_iterator
end()
const;
92 template <
class T = ViewerType>
93 typename std::enable_if<!viewer_is_widget<T>::value, std::shared_ptr<T>>::type CreateViewer();
95 template <
class T = ViewerType>
96 typename std::enable_if<viewer_is_widget<T>::value, std::shared_ptr<T>>::type CreateViewer();
99 std::shared_ptr<Ws::MergedPreferences> m_preferences;
100 std::shared_ptr<SubjectType> m_subject;
101 IViewerNode::ChildrenMap m_children;
103 bool m_parent_enabled;
104 std::shared_ptr<ViewerType> m_viewer;
108 template <
class ViewerType,
class SubjectType>
109 ViewerNode<ViewerType, SubjectType>::ViewerNode(std::shared_ptr<Ws::MergedPreferences> p,
110 IViewerNode::ChildrenMap&& c,
114 m_enabled(m_preferences->Get<bool>(
"enabled_at_startup")),
115 m_parent_enabled(false),
120 template <
class ViewerType,
class SubjectType>
121 ViewerNode<ViewerType, SubjectType>::ViewerNode(std::shared_ptr<Ws::MergedPreferences> p,
122 Gui::Controller::AppController* a)
124 m_enabled(m_preferences->Get<bool>(
"enabled_at_startup")),
125 m_parent_enabled(false),
130 template <
bool enabled>
133 template <
class ViewerType>
134 static void Do(std::shared_ptr<ViewerType>, IViewerNode::ChildrenMap&) {}
136 template <
class ViewerType>
137 static void Undo(std::shared_ptr<ViewerType> , IViewerNode::ChildrenMap& ) {}
143 template <
class ViewerType>
144 static void Do(std::shared_ptr<ViewerType> v, IViewerNode::ChildrenMap& m)
146 for (
auto& child : m) {
151 template <
class ViewerType>
152 static void Undo(std::shared_ptr<ViewerType> , IViewerNode::ChildrenMap& m)
154 for (
auto& child : m) {
160 template <
class ViewerType,
class SubjectType>
162 typename std::enable_if<!viewer_is_widget<T>::value, std::shared_ptr<T>>::type
165 return std::make_shared<T>(m_preferences);
168 template <
class ViewerType,
class SubjectType>
170 typename std::enable_if<viewer_is_widget<T>::value, std::shared_ptr<T>>::type
171 ViewerNode<ViewerType, SubjectType>::CreateViewer()
174 return std::make_shared<ViewerType>(m_preferences, m_app, [
this](){ this->Disable();});
181 template <
class ViewerType,
class SubjectType>
185 template <
typename V = ViewerType,
typename S = SubjectType,
187 static void Do(std::shared_ptr<V> v,
typename S::EventType::Source s)
190 v->Update(
typename SubjectType::EventType({s, 0, init_type}));
193 template <
typename T,
typename U>
200 template <
class ViewerType,
class SubjectType>
201 void ViewerNode<ViewerType, SubjectType>::Check()
203 if (m_enabled && m_parent_enabled)
206 if (!m_viewer && (m_viewer = CreateViewer())) {
209 typedef typename SubjectType::EventType EventType;
210 auto handler = std::bind(&ViewerType::template Update<EventType>, m_viewer.get(), std::placeholders::_1);
211 m_subject->Register(m_viewer, handler);
216 Register<viewer_is_subject<ViewerType>::value>::Do(m_viewer, m_children);
221 Register<viewer_is_subject<ViewerType>::value>::Undo(m_viewer, m_children);
225 m_subject->Unregister(m_viewer);
232 template <
class ViewerType,
class SubjectType>
236 m_preferences->Put(
"enabled_at_startup",
false);
241 template <
class ViewerType,
class SubjectType>
245 m_preferences->Put(
"enabled_at_startup",
true);
250 template <
class ViewerType,
class SubjectType>
256 template <
class ViewerType,
class SubjectType>
259 return m_parent_enabled;
262 template <
class ViewerType,
class SubjectType>
265 return m_children.begin();
268 template <
class ViewerType,
class SubjectType>
271 return m_children.end();
274 template <
class ViewerType,
class SubjectType>
278 m_parent_enabled =
true;
282 template <
class ViewerType,
class SubjectType>
285 m_parent_enabled =
false;
292 #endif // end_of_inclde_guard
virtual ~ViewerNode()
Virtual destructor.
Type
Enumerates the wall types.
virtual bool IsParentEnabled() const
static void Do(std::shared_ptr< V > v, typename S::EventType::Source s)
Try to initialize viewer with "Initialized" type of event.
virtual IViewerNode::ChildrenMap::const_iterator begin() const
virtual bool IsEnabled() const
Interface for MergedPreferences.
virtual void ParentDisabled()
virtual IViewerNode::ChildrenMap::const_iterator end() const
see the online Qt documentation
Template implementing a node in a hierarchical tree of viewers.Parameters:
Namespace for generic graphical shell for simulators.
Interface for IViewerNode.
see the online C++11 documentation
virtual void ParentEnabled(std::shared_ptr< SubjectType >)
A viewer node with a parent.