Fraxinus  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
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
void transformChanged()
emitted when transform is changed
boost::shared_ptr< class StringPropertyDataNameEditable > StringPropertyDataNameEditablePtr
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()
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
QWidget * createMetricWidget(DataPtr data)
MetricBasePtr createMetricWrapper(DataPtr data)
MetricUtilities(VisServicesPtr services)
Namespace for all CustusX production code.