Salome HOME
Update copyrights
[modules/shaper.git] / src / ModuleBase / ModuleBase_ParamIntSpinBox.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_ParamIntSpinBox_H
21 #define ModuleBase_ParamIntSpinBox_H
22
23 #include "ModuleBase.h"
24
25 #include <ModuleBase_IntSpinBox.h>
26
27 #include <QValidator>
28
29 /**
30 * \ingroup GUI
31 * An extension of a double spin box which let to use parameters and expressions for value definition
32 */
33 class MODULEBASE_EXPORT ModuleBase_ParamIntSpinBox : public ModuleBase_IntSpinBox
34 {
35   Q_OBJECT
36
37   enum State { Invalid = 0, NoVariable, Incompatible, Acceptable };
38
39 public:
40   /*!
41    \brief Constructor.
42
43    Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,
44    a step value of 1.0 and a precision of 2 decimal places.
45    The value is initially set to 0.00.
46
47    \param theParent a parent object
48    */
49   explicit ModuleBase_ParamIntSpinBox(QWidget* theParent = 0);
50   virtual ~ModuleBase_ParamIntSpinBox();
51
52   virtual void stepBy(int);
53
54   /// Convert Int value from text string
55   virtual int valueFromText(const QString&) const;
56
57   /// Convert text string from int value
58   virtual QString textFromValue(int) const;
59
60   /// Validate the value
61   virtual QValidator::State validate(QString&, int&) const;
62
63   /// Set current int value
64   virtual void setValue(int);
65
66   /// Set current text value
67   virtual void setText(const QString&);
68
69   /// Set a flag about accepted variable
70   void setAcceptVariables(const bool);
71
72   /// Returns accepted variables flag
73   bool isAcceptVariables() const;
74
75   /// Returns True if the input value contains variable
76   bool hasVariable() const;
77
78  protected:
79    /// Returns True if the given text contains variable
80    /// \param theText a text string
81   bool hasVariable(const QString& theText) const;
82
83   /// Returns state of the control
84   State isValid(const QString&, double&) const;
85
86   /// Returns True if the given value is within min and max of the control
87   bool checkRange(const double) const;
88
89   /// Finds a variable by its name. Returns true in success
90   /// \param theName a name of variable
91   /// \param outValue an output value of the variable
92   bool findVariable(const QString& theName, double& outValue) const;
93
94  protected:
95   virtual void showEvent(QShowEvent*);
96
97  protected slots:
98    /// A slot called on text change
99   void onTextChanged(const QString&);
100
101  private:
102   void connectSignalsAndSlots();
103
104  private:
105   QString myTextValue;
106
107   bool myAcceptVariables;
108 };
109
110 #endif