Tulip  5.7.4
Large graphs analysis and drawing
ScientificDoubleSpinBox.h
1 /*
2  *
3  * This file is part of Tulip (https://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 ///@cond DOXYGEN_HIDDEN
25 
26 #ifndef SCIENTIFICDOUBLESPINBOX_H
27 #define SCIENTIFICDOUBLESPINBOX_H
28 
29 #include <tulip/tulipconf.h>
30 
31 #include <QDoubleSpinBox>
32 #include <QValidator>
33 
34 namespace tlp {
35 
36 /**
37  * @brief Utility class used to validate that a QString contains a valid representation of a
38  * floating point number
39  * including scientific notation
40  *
41  * @since Tulip 5.0
42  */
43 class TLP_QT_SCOPE FloatValidator : public QValidator {
44 
45 public:
46  State validate(QString &input, int &pos) const override;
47 
48  void fixup(QString &text) const override;
49 };
50 
51 /**
52  * @brief Utility class implementing a QDoubleSpinBox supporting scientific notation
53  *
54  * @since Tulip 5.0
55  */
56 class TLP_QT_SCOPE ScientificDoubleSpinBox : public QDoubleSpinBox {
57 
58 public:
59  ScientificDoubleSpinBox(QWidget *parent = nullptr);
60 
61  QValidator::State validate(QString &input, int &pos) const override;
62 
63  void fixup(QString &input) const override;
64 
65  double valueFromText(const QString &text) const override;
66 
67  QString textFromValue(double value) const override;
68 
69  void stepBy(int steps) override;
70 };
71 } // namespace tlp
72 
73 #endif // SCIENTIFICDOUBLESPINBOX_H
74 
75 ///@endcond