Salome HOME
Translation of sketch operations
[modules/shaper.git] / src / ModuleBase / ModuleBase_ParamIntSpinBox.h
1
2 #ifndef ModuleBase_ParamIntSpinBox_H
3 #define ModuleBase_ParamIntSpinBox_H
4
5 #include "ModuleBase.h"
6
7 #include <ModuleBase_IntSpinBox.h>
8
9 #include <QValidator>
10
11 /**
12 * \ingroup GUI
13 * An extension of a double spin box which let to use parameters and expressions for value definition
14 */
15 class MODULEBASE_EXPORT ModuleBase_ParamIntSpinBox : public ModuleBase_IntSpinBox
16 {
17   Q_OBJECT
18
19   enum State { Invalid = 0, NoVariable, Incompatible, Acceptable };
20
21 public:
22   /*!
23    \brief Constructor.
24
25    Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,
26    a step value of 1.0 and a precision of 2 decimal places.
27    The value is initially set to 0.00.
28
29    \param theParent a parent object
30    */
31   explicit ModuleBase_ParamIntSpinBox(QWidget* theParent = 0);
32   virtual ~ModuleBase_ParamIntSpinBox();
33
34   virtual void stepBy(int);
35
36   /// Convert Int value from text string
37   virtual int valueFromText(const QString&) const;
38
39   /// Convert text string from int value
40   virtual QString textFromValue(int) const;
41
42   /// Validate the value
43   virtual QValidator::State validate(QString&, int&) const;
44
45   /// Set current int value
46   virtual void setValue(int);
47
48   /// Set current text value
49   virtual void setText(const QString&);
50
51   /// Set a flag about accepted variable
52   void setAcceptVariables(const bool);
53
54   /// Returns accepted variables flag
55   bool isAcceptVariables() const;
56
57   /// Returns True if the input value contains variable
58   bool hasVariable() const;
59
60  protected:
61    /// Returns True if the given text contains variable
62    /// \param theText a text string
63   bool hasVariable(const QString& theText) const;
64
65   /// Returns state of the control
66   State isValid(const QString&, double&) const;
67
68   /// Returns True if the given value is within min and max of the control
69   bool checkRange(const double) const;
70
71   /// Finds a variable by its name. Returns true in success
72   /// \param theName a name of variable
73   /// \param outValue an output value of the variable
74   bool findVariable(const QString& theName, double& outValue) const;
75
76  protected:
77   virtual void showEvent(QShowEvent*);
78
79  protected slots:
80    /// A slot called on text change
81   void onTextChanged(const QString&);
82
83  private:
84   void connectSignalsAndSlots();
85
86  private:
87   QString myTextValue;
88
89   bool myAcceptVariables;
90 };
91
92 #endif