CustusX  22.04
An IGT application
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) 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 
12 #include "cxFrameTreeWidget.h"
13 
14 #include <QVBoxLayout>
15 #include <QTreeWidget>
16 #include <QTreeWidgetItem>
17 #include "cxFrameForest.h"
18 #include "cxData.h"
19 #include "cxPatientModelService.h"
20 
21 namespace cx
22 {
23 
24 FrameTreeWidget::FrameTreeWidget(PatientModelServicePtr patientService, QWidget* parent) :
25  BaseWidget(parent, "frame_tree_widget", "Frame Tree"),
26  mPatientService(patientService)
27 {
28  QVBoxLayout* layout = new QVBoxLayout(this);
29 
30  //layout->setMargin(0);
31  this->setToolTip("A tree displaying relations between coordinate spaces");
32  mTreeWidget = new QTreeWidget(this);
33  layout->addWidget(mTreeWidget);
34  mTreeWidget->setHeaderLabels(QStringList() << "Frame");
35 
36  // TODO this must also listen to all changed() in all data
37  connect(mPatientService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataLoadedSlot()));
38 }
39 
40 void FrameTreeWidget::dataLoadedSlot()
41 {
42  for (std::map<QString, DataPtr>::iterator iter=mConnectedData.begin(); iter!=mConnectedData.end(); ++iter)
43  {
44  disconnect(iter->second.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
45  }
46 
47  mConnectedData = mPatientService->getDatas();
48 
49  for (std::map<QString, DataPtr>::iterator iter=mConnectedData.begin(); iter!=mConnectedData.end(); ++iter)
50  {
51  connect(iter->second.get(), SIGNAL(transformChanged()), this, SLOT(setModified()));
52  }
53 
54  this->setModified();
55 }
56 
58 {
59  this->rebuild();
60 }
61 
62 void FrameTreeWidget::rebuild()
63 {
64  mTreeWidget->clear();
65 
66  FrameForest forest(mPatientService->getDatas());
67  QDomElement root = forest.getDocument().documentElement();
68 
69  this->fill(mTreeWidget->invisibleRootItem(), root);
70 
71  mTreeWidget->expandToDepth(10);
72  mTreeWidget->resizeColumnToContents(0);
73 }
74 
75 void FrameTreeWidget::fill(QTreeWidgetItem* parent, QDomNode node)
76 {
77  for (QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling())
78  {
79  QString frameName = child.toElement().tagName();
80 
81  // if frame refers to a data, use its name instead.
82  DataPtr data = mPatientService->getData(frameName);
83  if (data)
84  frameName = data->getName();
85 
86  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList() << frameName);
87  this->fill(item, child);
88  }
89 }
90 
91 }
FrameTreeWidget(PatientModelServicePtr patientService, QWidget *parent)
A graph combining Space dependencies between all Data.Relations between coordinate spaces among Data ...
Definition: cxFrameForest.h:64
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:88
Namespace for all CustusX production code.