Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkPropertyViewFactory.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 // the different view and editor classes
16 #include "QmitkBasePropertyView.h"
19 #include "QmitkColorPropertyView.h"
26 
28 
30 {
31  static QmitkPropertyViewFactory instance;
32  return &instance;
33 }
34 
36 {
37 }
38 
40 {
41 }
42 QWidget *QmitkPropertyViewFactory::CreateView(const mitk::BaseProperty *property, unsigned int, QWidget *parent)
43 {
44  if (const mitk::StringProperty *prop = dynamic_cast<const mitk::StringProperty *>(property))
45  {
46  // a string property
47  return new QmitkStringPropertyView(prop, parent);
48  }
49  else if (const mitk::ColorProperty *prop = dynamic_cast<const mitk::ColorProperty *>(property))
50  {
51  // a color property
52  return new QmitkColorPropertyView(prop, parent);
53  }
54  else if (const mitk::BoolProperty *prop = dynamic_cast<const mitk::BoolProperty *>(property))
55  {
56  // a bool property
57  // TODO fix after refactoring
58  auto widget = new QmitkBoolPropertyWidget(parent);
59  widget->SetProperty(const_cast<mitk::BoolProperty *>(prop));
60  return widget;
61  }
62  else if (const mitk::IntProperty *prop = dynamic_cast<const mitk::IntProperty *>(property))
63  {
64  // a number property
65  return new QmitkNumberPropertyView(prop, parent);
66  }
67  else if (const mitk::FloatProperty *prop = dynamic_cast<const mitk::FloatProperty *>(property))
68  {
69  // a number property
70  return new QmitkNumberPropertyView(prop, parent);
71  }
72  else if (const mitk::DoubleProperty *prop = dynamic_cast<const mitk::DoubleProperty *>(property))
73  {
74  // a number property
75  return new QmitkNumberPropertyView(prop, parent);
76  }
77  else if (property != nullptr)
78  {
79  // some unknown property --> use the GetValueAsString() method to
80  return new QmitkBasePropertyView(prop, parent);
81  }
82 
83  return nullptr;
84 }
85 
86 QWidget *QmitkPropertyViewFactory::CreateEditor(mitk::BaseProperty *property, unsigned int type, QWidget *parent)
87 {
88  if (!property)
89  return nullptr;
90 
91  if (mitk::StringProperty *prop = dynamic_cast<mitk::StringProperty *>(property))
92  {
93  switch (type)
94  {
95  case etON_DEMAND_EDIT:
96  // a string property
97  return new QmitkStringPropertyOnDemandEdit(prop, parent);
98  default:
99  // a string property
100  return new QmitkStringPropertyEditor(prop, parent);
101  }
102  }
103  else if (mitk::ColorProperty *prop = dynamic_cast<mitk::ColorProperty *>(property))
104  {
105  // a color property
106  return new QmitkColorPropertyEditor(prop, parent);
107  }
108  else if (mitk::BoolProperty *prop = dynamic_cast<mitk::BoolProperty *>(property))
109  {
110  // a bool property
111  // TODO fix after refactoring
112  auto widget = new QmitkBoolPropertyWidget(parent);
113  widget->SetProperty(prop);
114  return widget;
115  }
116  else if (mitk::IntProperty *prop = dynamic_cast<mitk::IntProperty *>(property))
117  {
118  // a number property
119  return new QmitkNumberPropertyEditor(prop, parent);
120  }
121  else if (mitk::FloatProperty *prop = dynamic_cast<mitk::FloatProperty *>(property))
122  {
123  // a number property
124  auto pe = new QmitkNumberPropertyEditor(prop, parent);
125  pe->setDecimalPlaces(2);
126  return pe;
127  }
128  else if (mitk::DoubleProperty *prop = dynamic_cast<mitk::DoubleProperty *>(property))
129  {
130  // a number property
131  auto pe = new QmitkNumberPropertyEditor(prop, parent);
132  pe->setDecimalPlaces(2);
133  return pe;
134  }
135  else if (mitk::EnumerationProperty *prop = dynamic_cast<mitk::EnumerationProperty *>(property))
136  {
137  // a enumeration property
138  auto pe = new QmitkEnumerationPropertyWidget(parent);
139  pe->SetProperty(prop);
140  return pe;
141  }
142  else
143  {
144  // some unknown property --> no editor possible
145  return nullptr;
146  }
147 }
QWidget * CreateEditor(mitk::BaseProperty *property, unsigned int type=0, QWidget *parent=nullptr)
static QmitkPropertyViewFactory * GetInstance()
The ColorProperty class RGB color property.
Abstract base class for properties.
QWidget * CreateView(const mitk::BaseProperty *property, unsigned int type=0, QWidget *parent=nullptr)
Property for strings.