CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxMetricUtilities.cpp
Go to the documentation of this file.
1 #include "cxMetricUtilities.h"
2 
3 #include "cxFrameMetricWrapper.h"
4 #include "cxToolMetricWrapper.h"
5 #include "cxDataInterface.h"
7 #include "cxLogger.h"
8 
9 namespace
10 {
11 template<class T, class SUPER>
12 boost::shared_ptr<T> castTo(boost::shared_ptr<SUPER> data)
13 {
14  return boost::dynamic_pointer_cast<T>(data);
15 }
16 
17 template<class T, class SUPER>
18 bool isType(boost::shared_ptr<SUPER> data)
19 {
20  return (castTo<T>(data) ? true : false);
21 }
22 template<class WRAPPER, class METRIC, class SUPER>
23 boost::shared_ptr<WRAPPER> createMetricWrapperOfType(cx::ViewServicePtr viewService, cx::PatientModelServicePtr patientModelService, boost::shared_ptr<SUPER> data)
24 {
25  return boost::shared_ptr<WRAPPER>(new WRAPPER(viewService, patientModelService, castTo<METRIC>(data)));
26 }
27 }
28 
29 namespace cx {
30 
31 SingleMetricWidget::SingleMetricWidget(QWidget *parent, MetricBasePtr wrapper, QLabel* valueLabel) :
32  BaseWidget(parent, wrapper->getType()+"_single_metric_widget", wrapper->getType()+" Metric Widget"),
33  mWrapper(wrapper),
34  mValueLabel(valueLabel)
35 {
36 }
37 
39 {
40  return mWrapper->getData();
41 }
42 
44 {
45  mWrapper->update();
46  QString value = mWrapper->getValue();
47  mValueLabel->setText(value);
48 }
49 
50 
52  mPatientModelService(patientModelService),
53  mViewService(viewService)
54 {
55 
56 }
57 
59 {
60  if (isType<PointMetric>(data))
61  return createMetricWrapperOfType<PointMetricWrapper, PointMetric>(mViewService, mPatientModelService, data);
62  if (isType<DistanceMetric>(data))
63  return createMetricWrapperOfType<DistanceMetricWrapper, DistanceMetric>(mViewService, mPatientModelService, data);
64  if (isType<AngleMetric>(data))
65  return createMetricWrapperOfType<AngleMetricWrapper, AngleMetric>(mViewService, mPatientModelService, data);
66  if (isType<FrameMetric>(data))
67  return createMetricWrapperOfType<FrameMetricWrapper, FrameMetric>(mViewService, mPatientModelService, data);
68  if (isType<ToolMetric>(data))
69  return createMetricWrapperOfType<ToolMetricWrapper, ToolMetric>(mViewService, mPatientModelService, data);
70  if (isType<PlaneMetric>(data))
71  return createMetricWrapperOfType<PlaneMetricWrapper, PlaneMetric>(mViewService, mPatientModelService, data);
72  if (isType<DonutMetric>(data))
73  return createMetricWrapperOfType<DonutMetricWrapper, DonutMetric>(mViewService, mPatientModelService, data);
74  if (isType<CustomMetric>(data))
75  return createMetricWrapperOfType<CustomMetricWrapper, CustomMetric>(mViewService, mPatientModelService, data);
76  if (isType<SphereMetric>(data))
77  return createMetricWrapperOfType<SphereMetricWrapper, SphereMetric>(mViewService, mPatientModelService, data);
78  if (isType<RegionOfInterestMetric>(data))
79  return createMetricWrapperOfType<RegionOfInterestMetricWrapper, RegionOfInterestMetric>(mViewService, mPatientModelService, data);
80 
81  return MetricBasePtr();
82 }
83 
87 std::vector<MetricBasePtr> MetricUtilities::createMetricWrappers()
88 {
89  std::vector<MetricBasePtr> retval;
90  std::map<QString, DataPtr> all = mPatientModelService->getDatas();
91  for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
92  {
93  MetricBasePtr wrapper = this->createMetricWrapper(iter->second);
94  if (wrapper)
95  {
96  retval.push_back(wrapper);
97  }
98  }
99  return retval;
100 }
101 
103 {
104  MetricBasePtr wrapper = this->createMetricWrapper(data);
105 
106  QWidget* widget = wrapper->createWidget();
107  wrapper->update();
108 
109  QString value = wrapper->getValue();
110  QString type = wrapper->getType();
111 
112  QLabel* valueLabel = new QLabel(value);
113 
115  nameAdapter->setData(data);
116 
117  SingleMetricWidget* topWidget = new SingleMetricWidget(NULL, wrapper, valueLabel);
118  connect(data.get(), &Data::transformChanged, topWidget, &BaseWidget::setModified);
119 
120  QGroupBox* groupBox = new QGroupBox("Metric type: "+ type, topWidget);
121  groupBox->setFlat(true);
122  QVBoxLayout* verticalLayout = new QVBoxLayout(groupBox);
123  verticalLayout->setMargin(4);
124 
125  QHBoxLayout* valueLayout = new QHBoxLayout();
126  valueLayout->addWidget(new QLabel("Value: "));
127  valueLayout->addWidget(valueLabel);
128 
129  verticalLayout->addWidget(new LabeledLineEditWidget(topWidget, nameAdapter));
130  verticalLayout->addLayout(valueLayout);
131  verticalLayout->addWidget(widget, 1);
132 
133  QHBoxLayout* topLayout = new QHBoxLayout(topWidget);
134  topLayout->addWidget(groupBox);
135 
136  return topWidget;
137 }
138 
139 }//cx
MetricUtilities(ViewServicePtr viewService, PatientModelServicePtr patientModelService)
void transformChanged()
emitted when transform is changed
boost::shared_ptr< class StringPropertyDataNameEditable > StringPropertyDataNameEditablePtr
boost::shared_ptr< class ViewService > ViewServicePtr
std::vector< MetricBasePtr > createMetricWrappers()
Composite widget for string edit.
SingleMetricWidget(QWidget *parent, MetricBasePtr wrapper, QLabel *valueLabel)
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class MetricBase > MetricBasePtr
static StringPropertyDataNameEditablePtr New()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
cxLogicManager_EXPORT ViewServicePtr viewService()
QWidget * createMetricWidget(DataPtr data)
MetricBasePtr createMetricWrapper(DataPtr data)