#include <ModelAPI_Document.h>
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Tools.h>
#include <QKeyEvent>
#include <QLineEdit>
#include <QRegExp>
#include <string>
+#include <iostream>
/*!
\class ModuleBase_ParamSpinBox
*/
void ModuleBase_ParamSpinBox::connectSignalsAndSlots()
{
- connect(this, SIGNAL(editingFinished()),
- this, SLOT(onEditingFinished()));
-
connect(this, SIGNAL(valueChanged(const QString&)),
this, SLOT(onTextChanged(const QString&)));
-
- //connect(lineEdit(), SIGNAL(textChanged(const QString&)),
- // this, SLOT(onTextChanged(const QString&)));
-
- //connect(lineEdit(), SIGNAL(textChanged(const QString&)),
- // this, SIGNAL(textChanged(const QString&)));
-}
-
-/*!
- \brief This function is called when editing is finished.
- */
-void ModuleBase_ParamSpinBox::onEditingFinished()
-{
- if (myTextValue.isNull())
- myTextValue = text();
-
- setText(myTextValue);
}
/*!
void ModuleBase_ParamSpinBox::onTextChanged(const QString& text)
{
myTextValue = text;
-
- double value = 0;
- if (isValid(text, value) == Acceptable) {
- myCorrectValue = text;
- }
}
/*!
return aValue;
}
+QString ModuleBase_ParamSpinBox::textFromValue (double theValue) const
+{
+ if (hasVariable(myTextValue)){
+ return myTextValue;
+ }
+ return ModuleBase_DoubleSpinBox::textFromValue(theValue);
+}
+
/*!
\brief This function is used to determine whether input is valid.
\param str currently entered value
{
ModuleBase_DoubleSpinBox::setValue(value);
- myCorrectValue = ModuleBase_DoubleSpinBox::textFromValue(value);
- myTextValue = myCorrectValue;
+ myTextValue = ModuleBase_DoubleSpinBox::textFromValue(value);
}
/*!
bool ModuleBase_ParamSpinBox::hasVariable() const
{
- return hasVariable(text());
+ return hasVariable(myTextValue);
}
bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const
double& outValue) const
{
- SessionPtr aSession = ModelAPI_Session::get();
- DocumentPtr aDocument = aSession->activeDocument();
- ObjectPtr aParamObj = aDocument->objectByName(ModelAPI_ResultParameter::group(),
- theName.toStdString());
- ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
- if(!aParam.get())
- return false;
- AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
- outValue = aValueAttribute->value();
- return true;
+ return ModelAPI_Tools::findVariable(theName.toStdString(), outValue);
}
/*!
void ModuleBase_ParamSpinBox::showEvent(QShowEvent* theEvent)
{
ModuleBase_DoubleSpinBox::showEvent(theEvent);
- //setText(myTextValue);
+ if (hasVariable(myTextValue)) {
+ setText(myTextValue);
+ }
}