Tulip  5.0.0
Large graphs analysis and drawing
ScientificDoubleSpinBox.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 https://jdreaver.com/posts/2014-07-28-scientific-notation-spin-box-pyside.html
21 // see also https://gist.github.com/jdreaver/0be2e44981159d0854f5
22 
23 #ifndef SCIENTIFICDOUBLESPINBOX_H
24 #define SCIENTIFICDOUBLESPINBOX_H
25 
26 #include <tulip/tulipconf.h>
27 
28 #include <QDoubleSpinBox>
29 #include <QValidator>
30 
31 namespace tlp {
32 
33 /**
34  * @brief Utility class used to validate that a QString contains a valid representation of a floating point number
35  * including scientific notation
36  *
37  * @since Tulip 5.0
38  */
39 class TLP_QT_SCOPE FloatValidator : public QValidator {
40 
41 public:
42 
43  State validate(QString &input, int &pos) const;
44 
45  void fixup(QString &text) const;
46 
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 
58  ScientificDoubleSpinBox(QWidget *parent=0);
59 
60  QValidator::State validate(QString &input, int &pos) const;
61 
62  void fixup(QString &input) const;
63 
64  double valueFromText(const QString &text) const;
65 
66  QString textFromValue(double value) const;
67 
68  void stepBy(int steps);
69 
70 };
71 
72 }
73 
74 #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...