DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
QString aCaseId;
- if (myIsEditing)
- aCaseId = QString::fromStdString(aStringAttr->value());
- else
- aCaseId = QString::fromStdString(aDefVal.empty()? aStringAttr->value() : aDefVal);
-
- myIsFirst = false;
- int idx = myCaseIds.indexOf(aCaseId);
- if (idx == -1)
- idx = currentPageIndex();
- setCurrentPageIndex(idx);
+ if (aStringAttr->isInitialized()) {
+ if (myIsEditing)
+ aCaseId = QString::fromStdString(aStringAttr->value());
+ else
+ aCaseId = QString::fromStdString(aDefVal.empty() ? aStringAttr->value() : aDefVal);
+ myIsFirst = false;
+ int idx = myCaseIds.indexOf(aCaseId);
+ if (idx == -1)
+ idx = currentPageIndex();
+ setCurrentPageIndex(idx);
+ }
+ else {
+ // It is added because if user edits the feature created from Python
+ // and switches his choice
+ // it will not be stored in the attribute while apply not pressed.
+ // But this button will be disabled because of not initialized attribute
+ aStringAttr->setValue(myCaseIds.at(0).toStdString());
+ setCurrentPageIndex(0);
+ }
return true;
}
{
QString aText = translate(theData->widgetLabel());
QString aToolTip = translate(theData->widgetTooltip());
- bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
+ myDefVal = theData->getBooleanAttribute(ATTR_DEFAULT, false);
myCheckBox = new QCheckBox(aText, this);
myCheckBox->setToolTip(aToolTip);
- myCheckBox->setChecked(isChecked);
+ myCheckBox->setChecked(myDefVal);
QVBoxLayout* aMainLayout = new QVBoxLayout(this);
ModuleBase_Tools::adjustMargins(aMainLayout);
std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
bool isBlocked = myCheckBox->blockSignals(true);
- myCheckBox->setChecked(aRef->value());
+ if (aRef->isInitialized()) {
+ myCheckBox->setChecked(aRef->value());
+ }
+ else {
+ myCheckBox->setChecked(myDefVal);
+ aRef->setValue(myDefVal);
+ }
myCheckBox->blockSignals(isBlocked);
-
return true;
}
private:
/// The check box
QCheckBox* myCheckBox;
+
+ bool myDefVal;
};
#endif
mySpinBox->setSingleStep(aStepVal);
}
- double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
- if (isOk) {
- mySpinBox->setValue(aDefVal);
- }
+ myDefaultVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
+ if (isOk)
+ mySpinBox->setValue(myDefaultVal);
+ else
+ myDefaultVal = 0;
QString aTTip = translate(theData->widgetTooltip());
mySpinBox->setToolTip(aTTip);
// aText += aExprAttr->value().c_str();
//}
ModuleBase_Tools::setSpinText(mySpinBox, aText);
- } else {
- ModuleBase_Tools::setSpinValue(mySpinBox, aRef->isInitialized() ? aRef->value() : 0);
+ }
+ else {
+ ModuleBase_Tools::setSpinValue(mySpinBox, aRef->isInitialized() ? aRef->value() : myDefaultVal);
if (aRef->isInitialized() && aRef->expressionInvalid()) {
aRef->setExpressionError("");
aRef->setExpressionInvalid(false);
}
+ if (!aRef->isInitialized())
+ aRef->setValue(myDefaultVal);
}
return true;
}
ModuleBase_ParamSpinBox* mySpinBox;
FeaturePtr myParameter;
+
+ double myDefaultVal;
};
#endif
mySpinBox->setSingleStep(aStepVal);
}
- int aDefVal = QString::fromStdString(getDefaultValue()).toInt(&isOk);
- if (isOk) {
- mySpinBox->setValue(aDefVal);
- }
+ myDefVal = QString::fromStdString(getDefaultValue()).toInt(&isOk);
+ if (isOk)
+ mySpinBox->setValue(myDefVal);
+ else
+ myDefVal = 0;
QString aTTip = translate(theData->widgetTooltip());
mySpinBox->setToolTip(aTTip);
anAttribute->setExpressionError("");
anAttribute->setExpressionInvalid(false);
}
+ if (!anAttribute->isInitialized())
+ anAttribute->setValue(myDefVal);
}
return true;
}
ModuleBase_ParamSpinBox* mySpinBox;
FeaturePtr myParameter;
+
+ int myDefVal;
};
#endif
bool ModuleBase_WidgetPointInput::restoreValueCustom()
{
AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
- if (aAttr.get() && aAttr->isInitialized()) {
- std::string aXText = aAttr->textX();
- if (aXText.empty()) {
- myXSpin->setValue(aAttr->x());
- } else {
- myXSpin->setText(aXText.c_str());
- }
- std::string aYText = aAttr->textY();
- if (aYText.empty()) {
- myYSpin->setValue(aAttr->y());
- } else {
- myYSpin->setText(aYText.c_str());
+ if (aAttr.get()) {
+ if (aAttr->isInitialized()) {
+ std::string aXText = aAttr->textX();
+ if (aXText.empty()) {
+ myXSpin->setValue(aAttr->x());
+ }
+ else {
+ myXSpin->setText(aXText.c_str());
+ }
+ std::string aYText = aAttr->textY();
+ if (aYText.empty()) {
+ myYSpin->setValue(aAttr->y());
+ }
+ else {
+ myYSpin->setText(aYText.c_str());
+ }
+ std::string aZText = aAttr->textZ();
+ if (aZText.empty()) {
+ myZSpin->setValue(aAttr->z());
+ }
+ else {
+ myZSpin->setText(aZText.c_str());
+ }
}
- std::string aZText = aAttr->textZ();
- if (aZText.empty()) {
- myZSpin->setValue(aAttr->z());
- } else {
- myZSpin->setText(aZText.c_str());
+ else {
+ aAttr->setValue(myDefaultValue[0], myDefaultValue[1], myDefaultValue[2]);
+ myXSpin->setValue(myDefaultValue[0]);
+ myYSpin->setValue(myDefaultValue[1]);
+ myZSpin->setValue(myDefaultValue[2]);
}
return true;
}