Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmlMitkSliderNavigatorItem.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 
20  : QQuickItem(parent)
21 {
22 
23  // this avoids trying to use m_Stepper until it is set to something != NULL
24  // (additionally to the avoiding recursions during refetching)
25  m_InRefetch = true;
26  m_HasLabels = false;
27  m_HasLabelUnit = true;
28  m_InverseDirection = false;
29 }
30 
32 {
33  this->m_Min = min;
34 }
35 
37 {
38  this->m_Max = max;
39 }
40 
42 {
43  this->m_Value = value;
44 
45  if(!m_InRefetch)
46  {
48  {
49  m_Stepper->SetPos( m_Stepper->GetSteps()-1-value );
50  }
51  else
52  {
53  m_Stepper->SetPos( value );
54  }
55  this->Refetch();
56  }
57 }
58 
60 {
61  return this->m_Max;
62 }
63 
65 {
66  return this->m_Min;
67 }
68 
70 {
71  return this->m_Value;
72 }
73 
75 {
76  if (!m_InRefetch)
77  {
78  m_InRefetch = true;
79 
80  this->m_Min = 0;
81  this->m_Max = m_Stepper->GetSteps()-1;
82 
84  this->m_Value = m_Stepper->GetSteps()-1-m_Stepper->GetPos();
85  else
86  this->m_Value = m_Stepper->GetPos();
87 
88  m_InRefetch = false;
89 
90  emit this->sync();
91  }
92 }
93 
94 
96 {
97  m_Stepper = stepper;
98 
99  // this avoids trying to use m_Stepper until it is set to something != NULL
100  // (additionally to the avoiding recursions during refetching)
101  m_InRefetch = (stepper==nullptr);
102 }
103 
105 {
106  m_HasLabels = show;
107 }
108 
110 {
111  m_HasLabelUnit = show;
112 }
113 
115 {
116  m_MinValue = min;
117  m_MaxValue = max;
118 }
119 
120 void QmlMitkSliderNavigatorItem::SetLabelValuesValid( bool minValid, bool maxValid )
121 {
122  m_MinValueValid = minValid;
123  m_MaxValueValid = maxValid;
124 }
125 
127 {
128  m_LabelUnit = unit;
129 }
130 
132 {
133  return m_LabelUnit;
134 }
135 
137 {
138  if ( value < -10000000.0 )
139  {
140  return "-INF";
141  }
142  else if ( value > 10000000.0 )
143  {
144  return "+INF";
145  }
146  else
147  {
148  return QString::number( value, 'f', 2 );
149  }
150 }
151 
153 {
154  if ( m_MinValueValid )
155  {
156  return this->ClippedValueToString( m_MinValue );
157  }
158  else
159  {
160  return "N/A";
161  }
162 }
163 
165 {
166  if ( m_MaxValueValid )
167  {
168  return this->ClippedValueToString( m_MaxValue );
169  }
170  else
171  {
172  return "N/A";
173  }
174 }
175 
177 {
178  return m_Stepper->GetPos();
179 }
180 
182 {
183  if (!m_InRefetch)
184  {
185  m_Stepper->SetPos( val );
186  }
187 }
188 
190 {
191  m_InverseDirection = inverseDirection;
192 }
193 
195 {
196  qmlRegisterType<QmlMitkSliderNavigatorItem>("Mitk.Views", 1, 0, "SliderNavigator");
197 }
QString ClippedValueToString(float value)
Converts the passed value to a QString representation.
void Refetch()
Updates the slider with the recent changes applied to the navigator.
void SetInverseDirection(bool inverseDirection)
QString GetMinValueLabel()
Returns range-minimum (displayed as label left of slider if enabled)
void SetLabelUnit(const char *unit)
Set range unit (e.g. mm or ms) which will be displayed below range labels if enabled.
void SetLabelValuesValid(bool minValid, bool maxValid)
static T max(T x, T y)
Definition: svm.cpp:70
void ShowLabelUnit(bool show)
En-/disables displaying of the unit label (range will be displayed without unit if enabled)...
static T min(T x, T y)
Definition: svm.cpp:67
Helper class to step through a list.
Definition: mitkStepper.h:51
QmlMitkSliderNavigatorItem(QQuickItem *parent=nullptr)
void SetStepper(mitk::Stepper *stepper)
void SetLabelValues(float min, float max)
Set range minimum and maximum (displayed as labels left and right of slider if enabled) ...