#include <QRadioButton>
#include <QToolButton>
+static QMap<std::string, int> defaultValues;
+
ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData)//, myCombo(0), myButtons(0)
+: ModuleBase_ModelWidget(theParent, theData), myIsFirst(true)
{
+ myHasValue = defaultValues.contains(myFeatureId + attributeID());
+ if (myHasValue)
+ myDefValue = defaultValues[myFeatureId + attributeID()];
+ else
+ myDefValue = 0;
+
QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
std::string aTypes = theData->getProperty("string_list");
QHBoxLayout* aLayout = new QHBoxLayout(this);
myChoiceCtrl = new ModuleBase_ChoiceCtrl(this, aList, aIconList,
- (aWgtType == "radiobuttons")? ModuleBase_ChoiceCtrl::RadioButtons : ModuleBase_ChoiceCtrl::ComboBox,
+ (aWgtType == "radiobuttons")? ModuleBase_ChoiceCtrl::RadioButtons :
+ ModuleBase_ChoiceCtrl::ComboBox,
(aWgtDir == "horizontal")? Qt::Horizontal : Qt::Vertical);
myChoiceCtrl->setLabel(aLabelText);
DataPtr aData = myFeature->data();
std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
- aIntAttr->setValue(myChoiceCtrl->value());
+ int aCase = 0;
+ if (myIsFirst)
+ aCase = myHasValue? myDefValue : myChoiceCtrl->value();
+ else
+ aCase = myChoiceCtrl->value();
+
+ aIntAttr->setValue(aCase);
+ myDefValue = aCase;
+ myIsFirst = false;
+
updateObject(myFeature);
return true;
}
myChoiceCtrl->setChoiceList(aChoiceList);
}
}
- if (aIntAttr->isInitialized())
+ if (aIntAttr->isInitialized()) {
myChoiceCtrl->setValue(aIntAttr->value());
+
+ myChoiceCtrl->blockSignals(isBlocked);
+ emit itemSelected(this, aIntAttr->value());
+ myDefValue = aIntAttr->value();
+ }
else {
bool aHasDefaultValue;
int aDefaultVal = QString::fromStdString(getDefaultValue()).toInt(&aHasDefaultValue);
- myChoiceCtrl->setValue(aHasDefaultValue ? aDefaultVal : 0);
+ int aVal = aHasDefaultValue ? aDefaultVal : 0;
+ myChoiceCtrl->setValue(aVal);
+
+ myChoiceCtrl->blockSignals(isBlocked);
+ emit itemSelected(this, aVal);
+ myDefValue = aVal;
}
- myChoiceCtrl->blockSignals(isBlocked);
- emit itemSelected(this, aIntAttr->value());
+ myIsFirst = false;
}
return true;
}
emit itemSelected(this, theIndex);
}
+
+void ModuleBase_WidgetChoice::onFeatureAccepted()
+{
+ defaultValues[myFeatureId + attributeID()] = myDefValue;
+}