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