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