1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetIntValue.cpp
4 // Created: 04 June 2014
5 // Author: Vitaly Smetannikov
7 #include <ModuleBase_WidgetIntValue.h>
8 #include <ModuleBase_ParamSpinBox.h>
9 #include <ModuleBase_Tools.h>
10 #include <ModuleBase_IntSpinBox.h>
12 #include <ModelAPI_AttributeInteger.h>
13 #include <ModelAPI_Data.h>
15 #include <Config_Keywords.h>
16 #include <Config_WidgetAPI.h>
18 #include <Events_Loop.h>
19 #include <ModelAPI_Events.h>
22 #include <QFormLayout>
30 #define INT_MAX 2147483647
37 ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent,
38 const Config_WidgetAPI* theData,
39 const std::string& theParentId)
40 : ModuleBase_ModelWidget(theParent, theData, theParentId)
42 QFormLayout* aControlLay = new QFormLayout(this);
43 ModuleBase_Tools::adjustMargins(aControlLay);
45 QString aLabelText = QString::fromStdString(theData->widgetLabel());
46 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
47 myLabel = new QLabel(aLabelText, this);
48 if (!aLabelIcon.isEmpty())
49 myLabel->setPixmap(QPixmap(aLabelIcon));
51 mySpinBox = new ModuleBase_IntSpinBox(this);
52 QString anObjName = QString::fromStdString(attributeID());
53 mySpinBox->setObjectName(anObjName);
56 std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
57 int aMinVal = QString::fromStdString(aProp).toInt(&isOk);
59 mySpinBox->setMinimum(aMinVal);
61 mySpinBox->setMinimum(-INT_MAX);
64 aProp = theData->getProperty(DOUBLE_WDG_MAX);
65 int aMaxVal = QString::fromStdString(aProp).toInt(&isOk);
67 mySpinBox->setMaximum(aMaxVal);
69 mySpinBox->setMaximum(INT_MAX);
72 aProp = theData->getProperty(DOUBLE_WDG_STEP);
73 int aStepVal = QString::fromStdString(aProp).toInt(&isOk);
75 mySpinBox->setSingleStep(aStepVal);
78 int aDefVal = QString::fromStdString(getDefaultValue()).toInt(&isOk);
80 mySpinBox->setValue(aDefVal);
83 QString aTTip = QString::fromStdString(theData->widgetTooltip());
84 mySpinBox->setToolTip(aTTip);
85 myLabel->setToolTip(aTTip);
87 aControlLay->addRow(myLabel, mySpinBox);
88 connect(mySpinBox, SIGNAL(valueChanged(int)), this, SIGNAL(valuesModified()));
91 ModuleBase_WidgetIntValue::~ModuleBase_WidgetIntValue()
95 bool ModuleBase_WidgetIntValue::resetCustom()
98 if (!isUseReset() || isComputedDefault()) {
102 int aDefValue = QString::fromStdString(getDefaultValue()).toInt(&isOk);
103 // reset the value just if there is a default value definition in the XML definition
104 // if the double value can not be found by the default value, do nothing
106 bool isBlocked = mySpinBox->blockSignals(true);
107 mySpinBox->setValue(isOk ? aDefValue : 0);
108 mySpinBox->blockSignals(isBlocked);
116 bool ModuleBase_WidgetIntValue::storeValueCustom() const
118 DataPtr aData = myFeature->data();
119 AttributeIntegerPtr aIntVal = aData->integer(attributeID());
120 int aVal = mySpinBox->value();
121 aIntVal->setValue(mySpinBox->value());
122 updateObject(myFeature);
126 bool ModuleBase_WidgetIntValue::restoreValueCustom()
128 DataPtr aData = myFeature->data();
129 AttributeIntegerPtr aRef = aData->integer(attributeID());
130 bool isBlocked = mySpinBox->blockSignals(true);
131 mySpinBox->setValue(aRef->value());
132 mySpinBox->blockSignals(isBlocked);
136 QList<QWidget*> ModuleBase_WidgetIntValue::getControls() const
138 QList<QWidget*> aList;
139 aList.append(mySpinBox);
143 bool ModuleBase_WidgetIntValue::processEnter()
145 bool isModified = getValueState() == ModifiedInPP;
146 //bool isModified = mySpinBox->isModified();
148 emit valuesChanged();
149 //mySpinBox->clearModified();
150 mySpinBox->selectAll();