CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxFrameTreeWidget.cpp
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 
33 #include "cxFrameTreeWidget.h"
34 
35 #include <QVBoxLayout>
36 #include <QTreeWidget>
37 #include <QTreeWidgetItem>
38 #include "cxFrameForest.h"
39 #include "cxData.h"
40 #include "cxPatientModelService.h"
41 
42 namespace cx
43 {
44 
46  BaseWidget(parent, "FrameTreeWidget", "Frame Tree"),
47  mPatientService(patientService)
48 {
49  QVBoxLayout* layout = new QVBoxLayout(this);
50 
51  //layout->setMargin(0);
52  mTreeWidget = new QTreeWidget(this);
53  layout->addWidget(mTreeWidget);
54  mTreeWidget->setHeaderLabels(QStringList() << "Frame");
55 
56  // TODO this must also listen to all changed() in all data
57  connect(mPatientService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataLoadedSlot()));
58 }
59 
61 {
62  return "<html>"
63  "<h3>Frame dependencies display.</h3>"
64  "<p>Lets you look at the frame dependencies between different data.</p>"
65  "<p><i></i></p>"
66  "</html>";
67 }
68 
69 void FrameTreeWidget::dataLoadedSlot()
70 {
71  for (std::map<QString, DataPtr>::iterator iter=mConnectedData.begin(); iter!=mConnectedData.end(); ++iter)
72  {
73  disconnect(iter->second.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
74  }
75 
76  mConnectedData = mPatientService->getData();
77 
78  for (std::map<QString, DataPtr>::iterator iter=mConnectedData.begin(); iter!=mConnectedData.end(); ++iter)
79  {
80  connect(iter->second.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
81  }
82 
83  this->setModified();
84 }
85 
87 {
88  this->rebuild();
89 }
90 
91 void FrameTreeWidget::rebuild()
92 {
93  mTreeWidget->clear();
94 
95  FrameForest forest(mPatientService->getData());
96  QDomElement root = forest.getDocument().documentElement();
97 
98  this->fill(mTreeWidget->invisibleRootItem(), root);
99 
100  mTreeWidget->expandToDepth(10);
101  mTreeWidget->resizeColumnToContents(0);
102 }
103 
104 void FrameTreeWidget::fill(QTreeWidgetItem* parent, QDomNode node)
105 {
106  for (QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling())
107  {
108  QString frameName = child.toElement().tagName();
109 
110  // if frame refers to a data, use its name instead.
111  DataPtr data = mPatientService->getData(frameName);
112  if (data)
113  frameName = data->getName();
114 
115  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList() << frameName);
116  this->fill(item, child);
117  }
118 }
119 
120 }
FrameTreeWidget(PatientModelServicePtr patientService, QWidget *parent)
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
A graph combining Space dependencies between all Data.Relations between coordinate spaces among Data ...
Definition: cxFrameForest.h:85
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual void prePaintEvent()
QDomDocument getDocument()
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
cxLogicManager_EXPORT PatientModelServicePtr patientService()