Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 #ifndef CXTREEREPOSITORY_H
33 #define CXTREEREPOSITORY_H
34 
35 #include <vector>
36 #include <boost/weak_ptr.hpp>
37 #include <boost/shared_ptr.hpp>
38 #include <QString>
39 #include <QObject>
40 #include <QWidget>
41 #include "cxForwardDeclarations.h"
43 #include "cxXmlOptionItem.h"
44 #include "cxMetricUtilities.h"
45 #include "cxLogger.h"
46 
47 namespace cx
48 {
49 
50 class TreeNode;
51 class TreeRepository;
52 typedef boost::shared_ptr<TreeNode> TreeNodePtr;
53 typedef boost::shared_ptr<TreeRepository> TreeRepositoryPtr;
54 typedef boost::shared_ptr<class StringListProperty> StringListPropertyPtr;
55 typedef boost::weak_ptr<class TreeRepository> TreeRepositoryWeakPtr;
56 typedef boost::shared_ptr<class WidgetTypeRepository> WidgetTypeRepositoryPtr;
57 
59 {
60 public:
62  {
63  }
64 
65  template<class WIDGET>
66  boost::shared_ptr<WIDGET> find()
67  {
68  for (unsigned i=0; i<mWidgets.size(); ++i)
69  {
70  boost::shared_ptr<WIDGET> w = boost::dynamic_pointer_cast<WIDGET>(mWidgets[i]);
71  if (w)
72  return w;
73  }
74  return boost::shared_ptr<WIDGET>();
75  }
76 
77  boost::shared_ptr<QWidget> findMetricWidget(DataPtr data);
78 
79  void add(boost::shared_ptr<QWidget> widget);
80 
81 private:
82  typedef QPointer<QWidget> QWidgetPtr;
83  std::vector<boost::shared_ptr<QWidget> > mWidgets;
84 };
85 
86 class TreeRepository : public QObject
87 {
88  Q_OBJECT
89 public:
90  static TreeRepositoryPtr create(XmlOptionFile options, VisServicesPtr services);
91  ~TreeRepository();
92 
93  std::vector<TreeNodePtr> getNodes();
94  TreeNodePtr getNode(QString uid);
95 
96  // utility methods for accessing the nodes:
97  TreeNodePtr getTopNode();
98  TreeNodePtr getNodeForGroup(QString groupname);
99  VisServicesPtr getServices();
100 
101  WidgetTypeRepositoryPtr getWidgetTypeRepository();
102 
103  QString getMode() const;
104  StringPropertyPtr getModeProperty() { return mModeProperty; }
105  QStringList getVisibleNodeTypes() const;
106  StringListPropertyPtr getVisibilityProperty() { return mVisibilityProperty; }
107  QStringList getAllNodeTypes() const;
108 
109 public slots:
110  void update();
111  void invalidate();
112 
113 signals:
114  void changed(TreeNode* node=NULL);
115  void invalidated();
116  void loaded();
117 
118 private:
119  void createVisibilityProperty();
120  void createModeProperty();
121  void onChanged();
122 
123  std::vector<TreeNodePtr> mNodes;
124  TreeRepositoryWeakPtr mSelf;
125  bool mInvalid;
126  VisServicesPtr mServices;
127 
128  StringPropertyPtr mModeProperty;
129  StringListPropertyPtr mVisibilityProperty;
130 
131  XmlOptionFile mOptions;
132  WidgetTypeRepositoryPtr mWidgetTypeRepository;
133 
134  explicit TreeRepository(XmlOptionFile options, VisServicesPtr services);
135  void rebuild();
136  void insertTopNode();
137  void insertDataNode(DataPtr data);
138  void insertSpaceNode(CoordinateSystem space);
139  void insertToolNode(ToolPtr tool);
140  void insertGroupNode(QString groupname);
141  void appendNode(TreeNode* rawNode);
142  void startListen();
143  void stopListen();
144 };
145 
146 } // namespace cx
147 
148 #endif // CXTREEREPOSITORY_H
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
boost::shared_ptr< TreeNode > TreeNodePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:51
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