CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxDoubleSpanSlider.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #ifndef CXDOUBLESPANSLIDER_H_
12 #define CXDOUBLESPANSLIDER_H_
13 
14 #include "cxResourceWidgetsExport.h"
15 
16 #include <QWidget>
17 #include "cxDoubleRange.h"
18 #include "qxtspanslider.h"
19 #include "cxDoubleWidgets.h"
22 class QDoubleSpinBox;
23 
24 namespace cx
25 {
26 
32 class cxResourceWidgets_EXPORT DoubleSpanSlider : public QxtSpanSlider
33 {
34  Q_OBJECT
35 
36 public:
37  virtual ~DoubleSpanSlider() {}
38  DoubleSpanSlider(QWidget* parent = 0) : QxtSpanSlider(parent)
39  {
40  connect(this, SIGNAL(spanChanged(int,int)), this, SLOT(spanChangedSlot(int,int)));
41  this->setDoubleRange(DoubleRange(0,1,0.1));
42  }
43  void setDoubleRange(const DoubleRange& range)
44  {
45  mRange = range;
46  this->setRange(0, mRange.resolution());
47  this->setSingleStep(mRange.step());
48  }
50  {
51  return mRange;
52  }
53  void setDoubleSpan(double lower, double upper)
54  {
55  int lower_i = (lower-mRange.min())/mRange.step();
56  int upper_i = (upper-mRange.min())/mRange.step();
57  this->setSpan(lower_i, upper_i);
58  }
59  void setDoubleLowerValue(double val)
60  {
61  int v_i = (val-mRange.min())/mRange.step();
62  this->setLowerValue(v_i);
63  }
64  double getDoubleLowerValue() const
65  {
66  double v_d = mRange.step()*(double)(this->lowerValue()) + mRange.min();
67  return v_d;
68  }
69  void setDoubleUpperValue(double val)
70  {
71  int v_i = (val-mRange.min())/mRange.step();
72  this->setUpperValue(v_i);
73  }
74  double getDoubleUpperValue() const
75  {
76  double v_d = mRange.step()*(double)(this->upperValue()) + mRange.min();
77  return v_d;
78  }
79  void setDoubleTickInterval(double interval)
80  {
81  this->setTickInterval(interval/mRange.step());
82  }
83 
84 signals:
85  void doubleSpanChanged(double lower, double upper);
86 
87 private slots:
88  void spanChangedSlot(int lower, int upper)
89  {
90  emit doubleSpanChanged(getDoubleLowerValue(), getDoubleUpperValue());
91  }
92 
93 private:
94  DoubleRange mRange;
95 };
96 
101 class cxResourceWidgets_EXPORT SliderRangeGroupWidget : public OptimizedUpdateWidget
102 {
103  Q_OBJECT
104 public:
105  SliderRangeGroupWidget(QWidget* parent, DoublePairPropertyBasePtr dataInterface, QGridLayout* gridLayout = 0, int row = 0);
106 
107  void addToGridLayout(QGridLayout* gridLayout, int row);
108  void setRange(const DoubleRange& range);
109  void setDecimals(int decimals);
110  std::pair<double,double> getValue() const;
111  bool setValue(double lower, double upper);
112 
113 signals:
114  void valueChanged(double lower, double upper);
115 
116 private slots:
117  void doubleSpanChangedSlot(double lower, double upper);
118  void textEditedSlot();
119  void dataChanged();
120 
121 private:
123  void init(QGridLayout *gridLayout, int row);
124  void updateGuiRange();
125  QLabel* mLabel;
126  QDoubleSpinBox* mLowerEdit;
127  QDoubleSpinBox* mUpperEdit;
128  DoubleSpanSlider* mSpanSlider;
129 
131 };
132 
133 
134 } // namespace cx
135 
136 #endif /* CXDOUBLESPANSLIDER_H_ */
void setDoubleSpan(double lower, double upper)
double getDoubleLowerValue() const
double getDoubleUpperValue() const
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
void setDoubleTickInterval(double interval)
boost::shared_ptr< DoublePairPropertyBase > DoublePairPropertyBasePtr
Custom widget for display of double-valued data.Use the double-named methods instead of qslider&#39;s int...
DoubleRange getDoubleRange() const
Interface for all classes following the modified/prepaint paradigm.
DoubleSpanSlider(QWidget *parent=0)
void setDoubleRange(const DoubleRange &range)
void setDoubleUpperValue(double val)
void setDoubleLowerValue(double val)
Namespace for all CustusX production code.