NorMIT-nav  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);
71 
72  std::vector<TreeNodePtr> getNodes();
73  TreeNodePtr getNode(QString uid);
74 
75  // utility methods for accessing the nodes:
77  TreeNodePtr getNodeForGroup(QString groupname);
79 
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
cx::WidgetTypeRepositoryPtr
boost::shared_ptr< class WidgetTypeRepository > WidgetTypeRepositoryPtr
Definition: cxTreeRepository.h:35
cx::TreeRepository::getVisibilityProperty
StringListPropertyPtr getVisibilityProperty()
Definition: cxTreeRepository.h:85
cx::XmlOptionFile
Helper class for xml files used to store ssc/cx data.
Definition: cxXmlOptionItem.h:78
cxLogger.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxForwardDeclarations.h
cx::TreeRepository::getNodes
std::vector< TreeNodePtr > getNodes()
Definition: cxTreeRepository.cpp:137
cx::TreeRepository::create
static TreeRepositoryPtr create(XmlOptionFile options, VisServicesPtr services)
Definition: cxTreeRepository.cpp:55
cxXmlOptionItem.h
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cx::TreeRepository::getMode
QString getMode() const
Definition: cxTreeRepository.cpp:172
cx::StringPropertyPtr
boost::shared_ptr< class StringProperty > StringPropertyPtr
Definition: cxVideoConnectionWidget.h:42
cx::TreeRepository::update
void update()
Definition: cxTreeRepository.cpp:106
cx::TreeRepository::getModeProperty
StringPropertyPtr getModeProperty()
Definition: cxTreeRepository.h:83
cx::TreeRepository::getWidgetTypeRepository
WidgetTypeRepositoryPtr getWidgetTypeRepository()
Definition: cxTreeRepository.cpp:167
cx::WidgetTypeRepository::find
boost::shared_ptr< WIDGET > find()
Definition: cxTreeRepository.h:45
cx::TreeRepository::getVisibleNodeTypes
QStringList getVisibleNodeTypes() const
Definition: cxTreeRepository.cpp:177
cx::TreeNode
Definition: cxTreeNode.h:34
cx::TreeRepository
Definition: cxTreeRepository.h:65
cx::TreeRepository::~TreeRepository
~TreeRepository()
Definition: cxTreeRepository.cpp:101
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::TreeRepository::invalidated
void invalidated()
cx::TreeRepository::getNodeForGroup
TreeNodePtr getNodeForGroup(QString groupname)
Definition: cxTreeRepository.cpp:252
cxCoordinateSystemHelpers.h
cx::TreeRepository::changed
void changed(TreeNode *node=NULL)
cx::TreeRepositoryPtr
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
Definition: cxTreeItemModel.h:22
cx::TreeRepository::invalidate
void invalidate()
Definition: cxTreeRepository.cpp:114
cx::TreeNodePtr
boost::shared_ptr< TreeNode > TreeNodePtr
Definition: cxDataTreeNode.h:22
cx::TreeRepository::loaded
void loaded()
cx::TreeRepository::getServices
VisServicesPtr getServices()
Definition: cxTreeRepository.cpp:162
cx::StringListPropertyPtr
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
Definition: cxTreeItemModel.h:21
cx::TreeRepository::getNode
TreeNodePtr getNode(QString uid)
Definition: cxTreeRepository.cpp:142
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::WidgetTypeRepository::add
void add(boost::shared_ptr< QWidget > widget)
Definition: cxTreeRepository.cpp:46
cx::WidgetTypeRepository::~WidgetTypeRepository
~WidgetTypeRepository()
Definition: cxTreeRepository.h:40
cx::TreeRepository::getAllNodeTypes
QStringList getAllNodeTypes() const
Definition: cxTreeRepository.cpp:182
cx::WidgetTypeRepository
Definition: cxTreeRepository.h:37
cx::TreeRepository::getTopNode
TreeNodePtr getTopNode()
Definition: cxTreeRepository.cpp:152
cxMetricUtilities.h
cx::TreeRepositoryWeakPtr
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
cx::CoordinateSystem
Identification of a Coordinate system.
Definition: cxCoordinateSystemHelpers.h:31
cx::WidgetTypeRepository::findMetricWidget
boost::shared_ptr< QWidget > findMetricWidget(DataPtr data)
Definition: cxTreeRepository.cpp:35