OpenHantek
sispinbox.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #pragma once
4 
5 #include <QDoubleSpinBox>
6 #include <QStringList>
7 
8 #include "utils/printutils.h"
9 
14 class SiSpinBox : public QDoubleSpinBox {
15  Q_OBJECT
16 
17  public:
18  explicit SiSpinBox(QWidget *parent = nullptr);
19  SiSpinBox(Unit unit, QWidget *parent = nullptr);
20  ~SiSpinBox();
21 
22  QValidator::State validate(QString &input, int &pos) const;
23  double valueFromText(const QString &text) const;
24  QString textFromValue(double val) const;
25  void fixup(QString &input) const;
26  void stepBy(int steps);
27  bool setUnit(Unit unit);
28  void setUnitPostfix(const QString &postfix);
29  void setSteps(const QList<double> &steps);
30  void setMode(const int mode);
31 
32  private:
33  void init();
34  void setBackground();
35 
37  QString unitPostfix;
38  QList<double> steps;
39  int mode;
40 
41  bool steppedTo;
42  int stepId;
43 
44  signals:
45 
46  private slots:
47  void resetSteppedTo();
48 };
void resetSteppedTo()
Resets the ::steppedTo flag after the value has been changed.
Definition: sispinbox.cpp:181
bool steppedTo
true, if the current value was reached using stepBy
Definition: sispinbox.h:41
QString unitPostfix
Shown after the unit.
Definition: sispinbox.h:37
void fixup(QString &input) const
Fixes the text after the user finished changing it.
Definition: sispinbox.cpp:79
void setBackground()
Definition: sispinbox.cpp:184
void setMode(const int mode)
Set the mode.
Definition: sispinbox.cpp:161
void init()
Generic initializations.
Definition: sispinbox.cpp:164
void setUnitPostfix(const QString &postfix)
Set the unit postfix for this spin box.
Definition: sispinbox.cpp:151
SiSpinBox(QWidget *parent=nullptr)
Initializes the SiSpinBox internals.
Definition: sispinbox.cpp:35
double valueFromText(const QString &text) const
Parse value from input text.
Definition: sispinbox.cpp:70
int stepId
The index of the last step reached using stepBy.
Definition: sispinbox.h:42
void stepBy(int steps)
Increase/decrease the values in fixed steps.
Definition: sispinbox.cpp:90
QList< double > steps
The steps, begins from start after last element.
Definition: sispinbox.h:38
Unit unit
The SI unit used for this spin box.
Definition: sispinbox.h:36
A spin box with SI prefix support. This spin box supports the SI prefixes (k/M/G/T) after its value a...
Definition: sispinbox.h:14
Unit
The various units supported by valueToString.
Definition: printutils.h:12
int mode
The mode, fixed or constant.
Definition: sispinbox.h:39
void setSteps(const QList< double > &steps)
Set the steps the spin box will take.
Definition: sispinbox.cpp:156
QString textFromValue(double val) const
Get string representation of value.
Definition: sispinbox.cpp:75
QValidator::State validate(QString &input, int &pos) const
Validates the text after user input.
Definition: sispinbox.cpp:55
bool setUnit(Unit unit)
Set the unit for this spin box.
Definition: sispinbox.cpp:142
~SiSpinBox()
Cleans up the main window.
Definition: sispinbox.cpp:49