1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_ParamSpinBox_H
22 #define ModuleBase_ParamSpinBox_H
24 #include "ModuleBase.h"
26 #include <ModuleBase_DoubleSpinBox.h>
30 class QStringListModel;
35 * An extension of a double spin box which let to use parameters and expressions for value definition
37 class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public ModuleBase_DoubleSpinBox
41 enum State { Invalid = 0, NoVariable, Incompatible, Acceptable };
47 Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,
48 a step value of 1.0 and a precision of 2 decimal places.
49 The value is initially set to 0.00.
51 \param theParent a parent object
52 \param thePrecision a precision of values display
54 explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
56 /// Set list of completion strings
57 void setCompletionList(QStringList&);
59 virtual ~ModuleBase_ParamSpinBox();
61 virtual void stepBy(int);
63 virtual double valueFromText(const QString&) const;
64 virtual QString textFromValue (double value) const;
66 virtual QValidator::State validate(QString&, int&) const;
68 virtual void setValue(double);
70 virtual void setText(const QString&);
72 /// Set a flag about accepted variable
73 void setAcceptVariables(const bool);
75 /// Returns accepted variables flag
76 bool isAcceptVariables() const;
78 /// Returns True if the input value contains variable
79 bool hasVariable() const;
82 /// Returns True if the given text contains variable
83 /// \param theText a text string
84 bool hasVariable(const QString& theText) const;
86 /// Returns state of the control
87 State isValid(const QString&, double&) const;
89 /// Returns True if the given value is within min and max of the control
90 bool checkRange(const double) const;
92 /// Finds a variable by its name. Returns true in success
93 /// \param theName a name of variable
94 /// \param outValue an output value of the variable
95 bool findVariable(const QString& theName, double& outValue) const;
98 void textChanged(const QString& theText);
101 virtual void showEvent(QShowEvent*);
104 /// A slot called on text change
105 void onTextChanged(const QString&);
108 void connectSignalsAndSlots();
113 bool myAcceptVariables;
115 QStringListModel* myCompleterModel;
116 QCompleter* myCompleter;