1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef ModuleBase_ParamSpinBox_H
4 #define ModuleBase_ParamSpinBox_H
6 #include "ModuleBase.h"
8 #include <ModuleBase_DoubleSpinBox.h>
12 class QStringListModel;
17 * An extension of a double spin box which let to use parameters and expressions for value definition
19 class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public ModuleBase_DoubleSpinBox
23 enum State { Invalid = 0, NoVariable, Incompatible, Acceptable };
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.
33 \param theParent a parent object
34 \param thePrecision a precision of values display
36 explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
38 /// Set list of completion strings
39 void setCompletionList(QStringList&);
41 virtual ~ModuleBase_ParamSpinBox();
43 virtual void stepBy(int);
45 virtual double valueFromText(const QString&) const;
46 virtual QString textFromValue (double value) const;
48 virtual QValidator::State validate(QString&, int&) const;
50 virtual void setValue(double);
52 virtual void setText(const QString&);
54 /// Set a flag about accepted variable
55 void setAcceptVariables(const bool);
57 /// Returns accepted variables flag
58 bool isAcceptVariables() const;
60 /// Returns True if the input value contains variable
61 bool hasVariable() const;
64 /// Returns True if the given text contains variable
65 /// \param theText a text string
66 bool hasVariable(const QString& theText) const;
68 /// Returns state of the control
69 State isValid(const QString&, double&) const;
71 /// Returns True if the given value is within min and max of the control
72 bool checkRange(const double) const;
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;
80 void textChanged(const QString& theText);
83 virtual void showEvent(QShowEvent*);
86 /// A slot called on text change
87 void onTextChanged(const QString&);
90 void connectSignalsAndSlots();
95 bool myAcceptVariables;
97 QStringListModel* myCompleterModel;
98 QCompleter* myCompleter;