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