1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_ParamSpinBox_H
21 #define ModuleBase_ParamSpinBox_H
23 #include "ModuleBase.h"
25 #include <QAbstractSpinBox>
29 class QStringListModel;
34 * An extension of a double spin box which let to use parameters and expressions for value definition
36 class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public QAbstractSpinBox
40 enum State { Invalid = 0, NoVariable, Incompatible, Acceptable };
46 Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,
47 a step value of 1.0 and a precision of 2 decimal places.
48 The value is initially set to 0.00.
50 \param theParent a parent object
51 \param thePrecision a precision of values display
53 ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = 12 );
55 /// Set list of completion strings
56 void setCompletionList(QStringList&);
58 virtual ~ModuleBase_ParamSpinBox();
60 virtual void stepBy(int);
62 // virtual double valueFromText(const QString&) const;
63 // virtual QString textFromValue (double value) const;
65 virtual QValidator::State validate(QString&, int&) const;
67 virtual void setValue(double);
71 virtual void setText(const QString&);
73 QString text() const { return lineEdit()->text(); }
75 /// Set a flag about accepted variable
76 void setAcceptVariables(const bool);
78 /// Returns accepted variables flag
79 bool isAcceptVariables() const;
81 /// Returns True if the input value contains variable
82 bool hasVariable() const;
84 double minimum() const { return myMinimum; }
85 double maximum() const { return myMaximum; }
87 void setMinimum(double theMin) { myMinimum = theMin; myValidator->setBottom(theMin); }
88 void setMaximum(double theMax) { myMaximum = theMax; myValidator->setTop(theMax); }
90 int decimals() const { return myValidator->decimals(); }
91 void setDecimals(int thePrecision) { myValidator->setDecimals(thePrecision); }
93 double singleStep() const { return mySingleStep; }
94 void setSingleStep(double theStep) { mySingleStep = theStep; }
96 void setValueEnabled(bool theEnable);
100 \brief This function is called when the spinbox receives key release event.
102 virtual void keyReleaseEvent(QKeyEvent *event);
104 virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
106 /// The virtual function is reimplemented in order to avoid extra increasing of value by StepBy
108 virtual void timerEvent(QTimerEvent *event) {}
110 virtual StepEnabled stepEnabled() const { return StepUpEnabled | StepDownEnabled; }
112 /// Returns True if the given text contains variable
113 /// \param theText a text string
114 bool hasVariable(const QString& theText) const;
116 // /// Returns state of the control
117 // State isValid(const QString&, double&) const;
119 // /// Returns True if the given value is within min and max of the control
120 // bool checkRange(const double) const;
122 // /// Finds a variable by its name. Returns true in success
123 // /// \param theName a name of variable
124 // /// \param outValue an output value of the variable
125 // bool findVariable(const QString& theName, double& outValue) const;
128 void textChanged(const QString&);
131 // virtual void showEvent(QShowEvent*);
134 // /// A slot called on text change
135 // void onTextChanged(const QString&);
138 // void connectSignalsAndSlots();
141 void insertCompletion(const QString&);
143 void onTextChanged(const QString&);
146 QString getPrefix(int& theStart, int& theEnd) const;
147 void showCompletion(bool checkPrefix);
150 bool myAcceptVariables;
152 QStringListModel* myCompleterModel;
153 QCompleter* myCompleter;
162 /// Cashed color of active base palette
163 QColor myEnabledBaseColor;
165 QDoubleValidator* myValidator;