Tulip  5.3.0
Large graphs analysis and drawing
ScientificDoubleSpinBox.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 // original code is written in Python and is taken from
21 // https://jdreaver.com/posts/2014-07-28-scientific-notation-spin-box-pyside.html
22 // see also https://gist.github.com/jdreaver/0be2e44981159d0854f5
23 
24 #ifndef SCIENTIFICDOUBLESPINBOX_H
25 #define SCIENTIFICDOUBLESPINBOX_H
26 
27 #include <tulip/tulipconf.h>
28 
29 #include <QDoubleSpinBox>
30 #include <QValidator>
31 
32 namespace tlp {
33 
34 /**
35  * @brief Utility class used to validate that a QString contains a valid representation of a
36  * floating point number
37  * including scientific notation
38  *
39  * @since Tulip 5.0
40  */
41 class TLP_QT_SCOPE FloatValidator : public QValidator {
42 
43 public:
44  State validate(QString &input, int &pos) const override;
45 
46  void fixup(QString &text) const override;
47 };
48 
49 /**
50  * @brief Utility class implementing a QDoubleSpinBox supporting scientific notation
51  *
52  * @since Tulip 5.0
53  */
54 class TLP_QT_SCOPE ScientificDoubleSpinBox : public QDoubleSpinBox {
55 
56 public:
57  ScientificDoubleSpinBox(QWidget *parent = nullptr);
58 
59  QValidator::State validate(QString &input, int &pos) const override;
60 
61  void fixup(QString &input) const override;
62 
63  double valueFromText(const QString &text) const override;
64 
65  QString textFromValue(double value) const override;
66 
67  void stepBy(int steps) override;
68 };
69 } // namespace tlp
70 
71 #endif // SCIENTIFICDOUBLESPINBOX_H
Utility class implementing a QDoubleSpinBox supporting scientific notation.
Utility class used to validate that a QString contains a valid representation of a floating point num...