NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
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 #include "cxVisServices.h"
10 
11 namespace
12 {
13 template<class T, class SUPER>
14 boost::shared_ptr<T> castTo(boost::shared_ptr<SUPER> data)
15 {
16  return boost::dynamic_pointer_cast<T>(data);
17 }
18 
19 template<class T, class SUPER>
20 bool isType(boost::shared_ptr<SUPER> data)
21 {
22  return (castTo<T>(data) ? true : false);
23 }
24 template<class WRAPPER, class METRIC, class SUPER>
25 boost::shared_ptr<WRAPPER> createMetricWrapperOfType(cx::VisServicesPtr services, boost::shared_ptr<SUPER> data)
26 {
27  return boost::shared_ptr<WRAPPER>(new WRAPPER(services, castTo<METRIC>(data)));
28 }
29 }
30 
31 namespace cx {
32 
33 SingleMetricWidget::SingleMetricWidget(QWidget *parent, MetricBasePtr wrapper, QLabel* valueLabel) :
34  BaseWidget(parent, wrapper->getType()+"_single_metric_widget", wrapper->getType()+" Metric Widget"),
35  mWrapper(wrapper),
36  mValueLabel(valueLabel)
37 {
38 }
39 
41 {
42  return mWrapper->getData();
43 }
44 
46 {
47  mWrapper->update();
48  QString value = mWrapper->getValue();
49  mValueLabel->setText(value);
50 }
51 
52 
54  mServices(services)
55 {
56 
57 }
58 
60 {
61  if (isType<PointMetric>(data))
62  return createMetricWrapperOfType<PointMetricWrapper, PointMetric>(mServices, data);
63  if (isType<DistanceMetric>(data))
64  return createMetricWrapperOfType<DistanceMetricWrapper, DistanceMetric>(mServices, data);
65  if (isType<AngleMetric>(data))
66  return createMetricWrapperOfType<AngleMetricWrapper, AngleMetric>(mServices, data);
67  if (isType<FrameMetric>(data))
68  return createMetricWrapperOfType<FrameMetricWrapper, FrameMetric>(mServices, data);
69  if (isType<ToolMetric>(data))
70  return createMetricWrapperOfType<ToolMetricWrapper, ToolMetric>(mServices, data);
71  if (isType<PlaneMetric>(data))
72  return createMetricWrapperOfType<PlaneMetricWrapper, PlaneMetric>(mServices, data);
73  if (isType<DonutMetric>(data))
74  return createMetricWrapperOfType<DonutMetricWrapper, DonutMetric>(mServices, data);
75  if (isType<CustomMetric>(data))
76  return createMetricWrapperOfType<CustomMetricWrapper, CustomMetric>(mServices, data);
77  if (isType<SphereMetric>(data))
78  return createMetricWrapperOfType<SphereMetricWrapper, SphereMetric>(mServices, data);
79  if (isType<RegionOfInterestMetric>(data))
80  return createMetricWrapperOfType<RegionOfInterestMetricWrapper, RegionOfInterestMetric>(mServices, data);
81 
82  return MetricBasePtr();
83 }
84 
88 std::vector<MetricBasePtr> MetricUtilities::createMetricWrappers()
89 {
90  std::vector<MetricBasePtr> retval;
91  std::map<QString, DataPtr> all = mServices->patient()->getDatas();
92  for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
93  {
94  MetricBasePtr wrapper = this->createMetricWrapper(iter->second);
95  if (wrapper)
96  {
97  retval.push_back(wrapper);
98  }
99  }
100  return retval;
101 }
102 
104 {
105  MetricBasePtr wrapper = this->createMetricWrapper(data);
106 
107  QWidget* widget = wrapper->createWidget();
108  wrapper->update();
109 
110  QString value = wrapper->getValue();
111  QString type = wrapper->getType();
112 
113  QLabel* valueLabel = new QLabel(value);
114 
116  nameAdapter->setData(data);
117 
118  SingleMetricWidget* topWidget = new SingleMetricWidget(NULL, wrapper, valueLabel);
119  connect(data.get(), &Data::transformChanged, topWidget, &BaseWidget::setModified);
120 
121  QGroupBox* groupBox = new QGroupBox("Metric type: "+ type, topWidget);
122  groupBox->setFlat(true);
123  QVBoxLayout* verticalLayout = new QVBoxLayout(groupBox);
124  verticalLayout->setMargin(4);
125 
126  QHBoxLayout* valueLayout = new QHBoxLayout();
127  valueLayout->addWidget(new QLabel("Value: "));
128  valueLayout->addWidget(valueLabel);
129 
130  verticalLayout->addWidget(new LabeledLineEditWidget(topWidget, nameAdapter));
131  verticalLayout->addLayout(valueLayout);
132  verticalLayout->addWidget(widget, 1);
133 
134  QHBoxLayout* topLayout = new QHBoxLayout(topWidget);
135  topLayout->addWidget(groupBox);
136 
137  return topWidget;
138 }
139 
140 }//cx
cxLogger.h
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::StringPropertyDataNameEditablePtr
boost::shared_ptr< class StringPropertyDataNameEditable > StringPropertyDataNameEditablePtr
Definition: cxDataInterface.h:190
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cx::MetricUtilities::MetricUtilities
MetricUtilities(VisServicesPtr services)
Definition: cxMetricUtilities.cpp:53
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cxFrameMetricWrapper.h
cx::MetricUtilities::createMetricWrappers
std::vector< MetricBasePtr > createMetricWrappers()
Definition: cxMetricUtilities.cpp:88
cxToolMetricWrapper.h
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::SingleMetricWidget::SingleMetricWidget
SingleMetricWidget(QWidget *parent, MetricBasePtr wrapper, QLabel *valueLabel)
Definition: cxMetricUtilities.cpp:33
cxDataInterface.h
cx::StringPropertyDataNameEditable::New
static StringPropertyDataNameEditablePtr New()
Definition: cxDataInterface.h:199
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::SingleMetricWidget::mValueLabel
QLabel * mValueLabel
Definition: cxMetricUtilities.h:25
cx::MetricUtilities::createMetricWidget
QWidget * createMetricWidget(DataPtr data)
Definition: cxMetricUtilities.cpp:103
cxPatientModelService.h
cx::LabeledLineEditWidget
Composite widget for string edit.
Definition: cxLabeledLineEditWidget.h:35
cx::MetricUtilities::createMetricWrapper
MetricBasePtr createMetricWrapper(DataPtr data)
Definition: cxMetricUtilities.cpp:59
cx::SingleMetricWidget::mWrapper
MetricBasePtr mWrapper
Definition: cxMetricUtilities.h:24
cxLabeledLineEditWidget.h
cx::MetricBasePtr
boost::shared_ptr< class MetricBase > MetricBasePtr
Definition: cxDataMetricWrappers.h:51
cx::SingleMetricWidget::prePaintEvent
virtual void prePaintEvent()
Definition: cxMetricUtilities.cpp:45
cxMetricUtilities.h
cx::SingleMetricWidget
Definition: cxMetricUtilities.h:11
cx::SingleMetricWidget::getData
DataPtr getData()
Definition: cxMetricUtilities.cpp:40
cxVisServices.h