Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkNumberPropertyView.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 ============================================================================*/
13 #include <QTextStream>
14 
15 #define DT_SHORT 1
16 #define DT_INT 2
17 #define DT_FLOAT 3
18 #define DT_DOUBLE 4
19 
21  : QLabel(parent), PropertyView(property), m_IntProperty(property), m_DataType(DT_INT)
22 {
23  initialize();
24 }
25 
27  : QLabel(parent), PropertyView(property), m_FloatProperty(property), m_DataType(DT_FLOAT)
28 {
29  initialize();
30 }
31 
33  : QLabel(parent), PropertyView(property), m_DoubleProperty(property), m_DataType(DT_DOUBLE)
34 {
35  initialize();
36 }
37 
39 {
40 }
41 
43 { // only to be called from constructors
44  m_Suffix = "";
45  m_DisplayFactor = 1.0;
47 }
48 
50 {
51  return m_DecimalPlaces;
52 }
53 
55 {
56  m_DecimalPlaces = places;
57  DisplayNumber();
58 }
59 
60 QString QmitkNumberPropertyView::suffix() const
61 {
62  if (m_Suffix == "")
63  return QString::null;
64  else
65  return m_Suffix;
66 }
67 
69 {
70  m_Suffix = suffix;
71 
72  DisplayNumber();
73 }
74 
76 {
77  return m_DisplayFactor == 100.0;
78 }
79 
81 {
82  if (show)
83  {
84  m_DisplayFactor = 100.0;
85  setSuffix("%");
86  }
87  else
88  {
89  m_DisplayFactor = 1.0;
90  setSuffix("");
91  }
92 }
93 
95 {
96  if (m_Property)
97  DisplayNumber();
98 }
99 
101 {
102  m_Property = nullptr;
103  setText("n/a");
104 }
105 
107 {
108  QString displayedText;
109  QTextStream stream(&displayedText);
110 
111  stream.setRealNumberPrecision(m_DecimalPlaces);
112 
113  switch (m_DataType)
114  {
115  case DT_INT:
116  {
117  int i = m_IntProperty->GetValue();
118  stream << (i * m_DisplayFactor);
119  break;
120  }
121  case DT_FLOAT:
122  {
123  float f = m_FloatProperty->GetValue();
124  stream << (f * m_DisplayFactor);
125  break;
126  }
127  case DT_DOUBLE:
128  {
129  double d = m_DoubleProperty->GetValue();
130  stream << (d * m_DisplayFactor);
131  break;
132  }
133  default:
134  break;
135  }
136 
137  setText(displayedText);
138 }
PropertyView(const mitk::BaseProperty *)
const mitk::GenericProperty< double > * m_DoubleProperty
#define DT_FLOAT
const mitk::GenericProperty< float > * m_FloatProperty
const mitk::GenericProperty< int > * m_IntProperty
virtual T GetValue() const
bool showPercent() const
QmitkNumberPropertyView(const mitk::IntProperty *, QWidget *parent)
#define DT_DOUBLE
const mitk::BaseProperty * m_Property
void setSuffix(const QString &)
QString suffix() const
#define DT_INT
QString m_Suffix
-1 indicates "no limit to decimal places"