Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: correction for the...
[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    \param thePrecision a precision of values display
31    */
32   explicit ModuleBase_ParamIntSpinBox(QWidget* theParent = 0);
33   virtual ~ModuleBase_ParamIntSpinBox();
34
35   virtual void stepBy(int);
36
37   virtual int valueFromText(const QString&) const;
38   virtual QString textFromValue(int value) const;
39
40   virtual QValidator::State validate(QString&, int&) const;
41
42   virtual void setValue(int);
43
44   virtual void setText(const QString&);
45
46   /// Set a flag about accepted variable
47   void setAcceptVariables(const bool);
48
49   /// Returns accepted variables flag
50   bool isAcceptVariables() const;
51
52   /// Returns True if the input value contains variable
53   bool hasVariable() const;
54
55  protected:
56    /// Returns True if the given text contains variable
57    /// \param theText a text string
58   bool hasVariable(const QString& theText) const;
59
60   /// Returns state of the control
61   State isValid(const QString&, double&) const;
62
63   /// Returns True if the given value is within min and max of the control
64   bool checkRange(const double) const;
65
66   /// Finds a variable by its name. Returns true in success
67   /// \param theName a name of variable
68   /// \param outValue an output value of the variable
69   bool findVariable(const QString& theName, double& outValue) const;
70
71  protected:
72   virtual void showEvent(QShowEvent*);
73
74  protected slots:
75    /// A slot called on text change
76   void onTextChanged(const QString&);
77
78  private:
79   void connectSignalsAndSlots();
80
81  private:
82   QString myTextValue;
83
84   bool myAcceptVariables;
85 };
86
87 #endif