Fraxinus  16.5.0-fx-rc6
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
45 namespace cx
46 {
47 
48 class TreeNode;
49 class TreeRepository;
50 typedef boost::shared_ptr<TreeNode> TreeNodePtr;
51 typedef boost::shared_ptr<TreeRepository> TreeRepositoryPtr;
52 typedef boost::shared_ptr<class StringListProperty> StringListPropertyPtr;
53 typedef boost::weak_ptr<class TreeRepository> TreeRepositoryWeakPtr;
54 typedef boost::shared_ptr<class WidgetTypeRepository> WidgetTypeRepositoryPtr;
55 
57 {
58 public:
59  template<class WIDGET>
60  WIDGET* find()
61  {
62  for (unsigned i=0; i<mWidgets.size(); ++i)
63  {
64  WIDGET* w = dynamic_cast<WIDGET*>(mWidgets[i].data());
65  if (w)
66  return w;
67  }
68  return NULL;
69  }
70  void add(QWidget* widget);
71 
72 private:
73  typedef QPointer<QWidget> QWidgetPtr;
74  std::vector<QWidgetPtr> mWidgets;
75 };
76 
77 class TreeRepository : public QObject
78 {
79  Q_OBJECT
80 public:
81  static TreeRepositoryPtr create(XmlOptionFile options, VisServicesPtr services);
83 
84  std::vector<TreeNodePtr> getNodes();
85  TreeNodePtr getNode(QString uid);
86 
87  // utility methods for accessing the nodes:
89  TreeNodePtr getNodeForGroup(QString groupname);
91 
93 
94  QString getMode() const;
95  StringPropertyPtr getModeProperty() { return mModeProperty; }
96  QStringList getVisibleNodeTypes() const;
97  StringListPropertyPtr getVisibilityProperty() { return mVisibilityProperty; }
98  QStringList getAllNodeTypes() const;
99 
100 public slots:
101  void update();
102  void invalidate();
103 
104 signals:
105  void changed();
106  void invalidated();
107  void loaded();
108 
109 private:
110  void createVisibilityProperty();
111  void createModeProperty();
112 // void onChanged();
113 
114  std::vector<TreeNodePtr> mNodes;
115  TreeRepositoryWeakPtr mSelf;
116  bool mInvalid;
117  VisServicesPtr mServices;
118 
119  StringPropertyPtr mModeProperty;
120  StringListPropertyPtr mVisibilityProperty;
121 
122  XmlOptionFile mOptions;
123  WidgetTypeRepositoryPtr mWidgetTypeRepository;
124 
125  explicit TreeRepository(XmlOptionFile options, VisServicesPtr services);
126  void rebuild();
127  void insertTopNode();
128  void insertDataNode(DataPtr data);
129  void insertSpaceNode(CoordinateSystem space);
130  void insertToolNode(ToolPtr tool);
131  void insertGroupNode(QString groupname);
132  void appendNode(TreeNode* rawNode);
133  void startListen();
134  void stopListen();
135 };
136 
137 } // namespace cx
138 
139 #endif // CXTREEREPOSITORY_H
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
TreeNodePtr getNodeForGroup(QString groupname)
boost::shared_ptr< TreeNode > TreeNodePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:51
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class StringProperty > StringPropertyPtr
QStringList getVisibleNodeTypes() const
std::vector< TreeNodePtr > getNodes()
StringListPropertyPtr getVisibilityProperty()
TreeNodePtr getTopNode()
QString getMode() const
boost::shared_ptr< class WidgetTypeRepository > WidgetTypeRepositoryPtr
Identification of a Coordinate system.
static TreeRepositoryPtr create(XmlOptionFile options, VisServicesPtr services)
StringPropertyPtr getModeProperty()
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
void add(QWidget *widget)
QStringList getAllNodeTypes() const
VisServicesPtr getServices()
WidgetTypeRepositoryPtr getWidgetTypeRepository()
Helper class for xml files used to store ssc/cx data.
TreeNodePtr getNode(QString uid)
boost::shared_ptr< class Tool > ToolPtr