Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 // the different view and editor classes
20 #include "QmitkBasePropertyView.h"
23 #include "QmitkColorPropertyView.h"
30 
32 
34 {
35  static QmitkPropertyViewFactory instance;
36  return &instance;
37 }
38 
40 {
41 }
42 
44 {
45 }
46 QWidget *QmitkPropertyViewFactory::CreateView(const mitk::BaseProperty *property, unsigned int, QWidget *parent)
47 {
48  if (const mitk::StringProperty *prop = dynamic_cast<const mitk::StringProperty *>(property))
49  {
50  // a string property
51  return new QmitkStringPropertyView(prop, parent);
52  }
53  else if (const mitk::ColorProperty *prop = dynamic_cast<const mitk::ColorProperty *>(property))
54  {
55  // a color property
56  return new QmitkColorPropertyView(prop, parent);
57  }
58  else if (const mitk::BoolProperty *prop = dynamic_cast<const mitk::BoolProperty *>(property))
59  {
60  // a bool property
61  // TODO fix after refactoring
62  auto widget = new QmitkBoolPropertyWidget(parent);
63  widget->SetProperty(const_cast<mitk::BoolProperty *>(prop));
64  return widget;
65  }
66  else if (const mitk::IntProperty *prop = dynamic_cast<const mitk::IntProperty *>(property))
67  {
68  // a number property
69  return new QmitkNumberPropertyView(prop, parent);
70  }
71  else if (const mitk::FloatProperty *prop = dynamic_cast<const mitk::FloatProperty *>(property))
72  {
73  // a number property
74  return new QmitkNumberPropertyView(prop, parent);
75  }
76  else if (const mitk::DoubleProperty *prop = dynamic_cast<const mitk::DoubleProperty *>(property))
77  {
78  // a number property
79  return new QmitkNumberPropertyView(prop, parent);
80  }
81  else if (property != nullptr)
82  {
83  // some unknown property --> use the GetValueAsString() method to
84  return new QmitkBasePropertyView(prop, parent);
85  }
86 
87  return nullptr;
88 }
89 
90 QWidget *QmitkPropertyViewFactory::CreateEditor(mitk::BaseProperty *property, unsigned int type, QWidget *parent)
91 {
92  if (!property)
93  return nullptr;
94 
95  if (mitk::StringProperty *prop = dynamic_cast<mitk::StringProperty *>(property))
96  {
97  switch (type)
98  {
99  case etON_DEMAND_EDIT:
100  // a string property
101  return new QmitkStringPropertyOnDemandEdit(prop, parent);
102  default:
103  // a string property
104  return new QmitkStringPropertyEditor(prop, parent);
105  }
106  }
107  else if (mitk::ColorProperty *prop = dynamic_cast<mitk::ColorProperty *>(property))
108  {
109  // a color property
110  return new QmitkColorPropertyEditor(prop, parent);
111  }
112  else if (mitk::BoolProperty *prop = dynamic_cast<mitk::BoolProperty *>(property))
113  {
114  // a bool property
115  // TODO fix after refactoring
116  auto widget = new QmitkBoolPropertyWidget(parent);
117  widget->SetProperty(prop);
118  return widget;
119  }
120  else if (mitk::IntProperty *prop = dynamic_cast<mitk::IntProperty *>(property))
121  {
122  // a number property
123  return new QmitkNumberPropertyEditor(prop, parent);
124  }
125  else if (mitk::FloatProperty *prop = dynamic_cast<mitk::FloatProperty *>(property))
126  {
127  // a number property
128  auto pe = new QmitkNumberPropertyEditor(prop, parent);
129  pe->setDecimalPlaces(2);
130  return pe;
131  }
132  else if (mitk::DoubleProperty *prop = dynamic_cast<mitk::DoubleProperty *>(property))
133  {
134  // a number property
135  auto pe = new QmitkNumberPropertyEditor(prop, parent);
136  pe->setDecimalPlaces(2);
137  return pe;
138  }
139  else if (mitk::EnumerationProperty *prop = dynamic_cast<mitk::EnumerationProperty *>(property))
140  {
141  // a enumeration property
142  auto pe = new QmitkEnumerationPropertyWidget(parent);
143  pe->SetProperty(prop);
144  return pe;
145  }
146  else
147  {
148  // some unknown property --> no editor possible
149  return nullptr;
150  }
151 }
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.