CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxTreeRepository.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #ifndef CXTREEREPOSITORY_H
12 #define CXTREEREPOSITORY_H
13 
14 #include <vector>
15 #include <boost/weak_ptr.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <QString>
18 #include <QObject>
19 #include <QWidget>
20 #include "cxForwardDeclarations.h"
22 #include "cxXmlOptionItem.h"
23 #include "cxMetricUtilities.h"
24 #include "cxLogger.h"
25 
26 namespace cx
27 {
28 
29 class TreeNode;
30 class TreeRepository;
31 typedef boost::shared_ptr<TreeNode> TreeNodePtr;
32 typedef boost::shared_ptr<TreeRepository> TreeRepositoryPtr;
33 typedef boost::shared_ptr<class StringListProperty> StringListPropertyPtr;
34 typedef boost::weak_ptr<class TreeRepository> TreeRepositoryWeakPtr;
35 typedef boost::shared_ptr<class WidgetTypeRepository> WidgetTypeRepositoryPtr;
36 
38 {
39 public:
41  {
42  }
43 
44  template<class WIDGET>
45  boost::shared_ptr<WIDGET> find()
46  {
47  for (unsigned i=0; i<mWidgets.size(); ++i)
48  {
49  boost::shared_ptr<WIDGET> w = boost::dynamic_pointer_cast<WIDGET>(mWidgets[i]);
50  if (w)
51  return w;
52  }
53  return boost::shared_ptr<WIDGET>();
54  }
55 
56  boost::shared_ptr<QWidget> findMetricWidget(DataPtr data);
57 
58  void add(boost::shared_ptr<QWidget> widget);
59 
60 private:
61  typedef QPointer<QWidget> QWidgetPtr;
62  std::vector<boost::shared_ptr<QWidget> > mWidgets;
63 };
64 
65 class TreeRepository : public QObject
66 {
67  Q_OBJECT
68 public:
69  static TreeRepositoryPtr create(XmlOptionFile options, VisServicesPtr services);
70  ~TreeRepository();
71 
72  std::vector<TreeNodePtr> getNodes();
73  TreeNodePtr getNode(QString uid);
74 
75  // utility methods for accessing the nodes:
76  TreeNodePtr getTopNode();
77  TreeNodePtr getNodeForGroup(QString groupname);
78  VisServicesPtr getServices();
79 
80  WidgetTypeRepositoryPtr getWidgetTypeRepository();
81 
82  QString getMode() const;
83  StringPropertyPtr getModeProperty() { return mModeProperty; }
84  QStringList getVisibleNodeTypes() const;
85  StringListPropertyPtr getVisibilityProperty() { return mVisibilityProperty; }
86  QStringList getAllNodeTypes() const;
87 
88 public slots:
89  void update();
90  void invalidate();
91 
92 signals:
93  void changed(TreeNode* node=NULL);
94  void invalidated();
95  void loaded();
96 
97 private:
98  void createVisibilityProperty();
99  void createModeProperty();
100  void onChanged();
101 
102  std::vector<TreeNodePtr> mNodes;
103  TreeRepositoryWeakPtr mSelf;
104  bool mInvalid;
105  VisServicesPtr mServices;
106 
107  StringPropertyPtr mModeProperty;
108  StringListPropertyPtr mVisibilityProperty;
109 
110  XmlOptionFile mOptions;
111  WidgetTypeRepositoryPtr mWidgetTypeRepository;
112 
113  explicit TreeRepository(XmlOptionFile options, VisServicesPtr services);
114  void rebuild();
115  void insertTopNode();
116  void insertDataNode(DataPtr data);
117  void insertSpaceNode(CoordinateSystem space);
118  void insertToolNode(ToolPtr tool);
119  void insertGroupNode(QString groupname);
120  void appendNode(TreeNode* rawNode);
121  void startListen();
122  void stopListen();
123 };
124 
125 } // namespace cx
126 
127 #endif // CXTREEREPOSITORY_H
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
boost::shared_ptr< TreeNode > TreeNodePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class StringProperty > StringPropertyPtr
StringListPropertyPtr getVisibilityProperty()
boost::shared_ptr< class WidgetTypeRepository > WidgetTypeRepositoryPtr
Identification of a Coordinate system.
void add(boost::shared_ptr< QWidget > widget)
StringPropertyPtr getModeProperty()
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
boost::shared_ptr< WIDGET > find()
boost::shared_ptr< QWidget > findMetricWidget(DataPtr data)
Helper class for xml files used to store ssc/cx data.
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr