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