2 #ifndef ModuleBase_ParamSpinBox_H
3 #define ModuleBase_ParamSpinBox_H
5 #include "ModuleBase.h"
7 #include <ModuleBase_DoubleSpinBox.h>
11 class QStringListModel;
16 * An extension of a double spin box which let to use parameters and expressions for value definition
18 class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public ModuleBase_DoubleSpinBox
22 enum State { Invalid = 0, NoVariable, Incompatible, Acceptable };
28 Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,
29 a step value of 1.0 and a precision of 2 decimal places.
30 The value is initially set to 0.00.
32 \param theParent a parent object
33 \param thePrecision a precision of values display
35 explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
37 /// Set list of completion strings
38 void setCompletionList(QStringList&);
40 virtual ~ModuleBase_ParamSpinBox();
42 virtual void stepBy(int);
44 virtual double valueFromText(const QString&) const;
45 virtual QString textFromValue (double value) const;
47 virtual QValidator::State validate(QString&, int&) const;
49 virtual void setValue(double);
51 virtual void setText(const QString&);
53 /// Set a flag about accepted variable
54 void setAcceptVariables(const bool);
56 /// Returns accepted variables flag
57 bool isAcceptVariables() const;
59 /// Returns True if the input value contains variable
60 bool hasVariable() const;
63 /// Returns True if the given text contains variable
64 /// \param theText a text string
65 bool hasVariable(const QString& theText) const;
67 /// Returns state of the control
68 State isValid(const QString&, double&) const;
70 /// Returns True if the given value is within min and max of the control
71 bool checkRange(const double) const;
73 /// Finds a variable by its name. Returns true in success
74 /// \param theName a name of variable
75 /// \param outValue an output value of the variable
76 bool findVariable(const QString& theName, double& outValue) const;
79 virtual void showEvent(QShowEvent*);
82 /// A slot called on text change
83 void onTextChanged(const QString&);
86 void connectSignalsAndSlots();
91 bool myAcceptVariables;
93 QStringListModel* myCompleterModel;
94 QCompleter* myCompleter;