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