-
Notifications
You must be signed in to change notification settings - Fork 20
/
SciNotationDoubleSpinbox.h
54 lines (42 loc) · 1.29 KB
/
SciNotationDoubleSpinbox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef SCINOTDOUBLESPINBOX_H
#define SCINOTDOUBLESPINBOX_H
#include <QObject>
#include <QDoubleSpinBox>
class SciNotationDoubleSpinbox : public QDoubleSpinBox
{
Q_OBJECT
public:
explicit SciNotationDoubleSpinbox(QWidget *parent = 0) : QDoubleSpinBox(parent) {}
// Change the way we read the user input
double valueFromText(const QString & text) const
{
double numFromStr = text.toDouble(); return numFromStr; }
// Change the way we show the internal number
QString textFromValue(double value) const
{
return QString::number(value, 'E', 6);
}
// Change the way we validate user input (if validate => valueFromText)
QValidator::State validate(QString &text, int&) const
{
// Try to convert the string to double
bool ok;
text.toDouble(&ok);
// See if it's a valid Double
QValidator::State validationState;
if(ok)
{
// If string conversion was valid, set as ascceptable
validationState = QValidator::Acceptable;
}
else
{
// If string conversion was invalid, set as invalid
validationState = QValidator::Invalid;
}
return validationState;
}
signals:
public slots:
};
#endif // SCINOTDOUBLESPINBOX_H