X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ModelWidget.cpp;h=db9908a41da042ddfb9ca90f48b5799b48ddf1e5;hb=3e6012473696e5fd94e3c8240e2e1eda8def1743;hp=77d58959b1bd322e45e6c5b51ae41e5309c3e09a;hpb=ded1e8998ec9d6d57f5a5a122c4abced86874273;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 77d58959b..db9908a41 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -32,6 +32,7 @@ //#define DEBUG_VALUE_STATE //#define DEBUG_WIDGET_INSTANCE +//#define DEBUG_ENABLE_SKETCH_INPUT_FIELDS ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData) @@ -46,6 +47,8 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, qDebug("ModuleBase_ModelWidget::ModuleBase_ModelWidget"); #endif + myFeatureId = theData->featureId(); + myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false); myDefaultValue = theData->getProperty(ATTR_DEFAULT); @@ -90,7 +93,12 @@ bool ModuleBase_ModelWidget::isValueEnabled() const { bool anEnabled = true; if (myIsValueEnabled == DefinedInPreferences) { - bool aCanDisable = Config_PropManager::boolean("Sketch planes", "disable_input_fields", "true"); +#ifdef DEBUG_ENABLE_SKETCH_INPUT_FIELDS + bool aCanDisable = false; +#else + //Config_PropManager::boolean(SKETCH_TAB_NAME, "disable_input_fields", "true"); + bool aCanDisable = true; +#endif if (aCanDisable) anEnabled = false; } @@ -105,22 +113,23 @@ void ModuleBase_ModelWidget::processValueState() storeValue(); } -QString ModuleBase_ModelWidget::getValueStateError() const +Events_InfoMessage ModuleBase_ModelWidget::getValueStateError() const { - QString anError = ""; + Events_InfoMessage aMessage; ModuleBase_ModelWidget::ValueState aState = getValueState(); if (aState != ModuleBase_ModelWidget::Stored) { AttributePtr anAttr = feature()->attribute(attributeID()); if (anAttr.get()) { - QString anAttributeName = anAttr->id().c_str(); + const std::string& anAttributeName = anAttr->id(); switch (aState) { case ModuleBase_ModelWidget::ModifiedInViewer: - anError = "Attribute \"" + anAttributeName + - "\" is locked by modification value in the viewer."; + aMessage = "Attribute \"%1\" is locked by modification value in the viewer."; + aMessage.addParameter(anAttributeName); break; case ModuleBase_ModelWidget::Reset: - anError = "Attribute \"" + anAttributeName + "\" is not initialized."; + aMessage = "Attribute \"%1\" is not initialized."; + aMessage.addParameter(anAttributeName); break; case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode default: @@ -128,7 +137,7 @@ QString ModuleBase_ModelWidget::getValueStateError() const } } } - return anError; + return aMessage; } QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const @@ -138,6 +147,7 @@ QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const if (!feature().get()) return anError; + std::string aFeatureID = feature()->getKind(); std::string anAttributeID = attributeID(); AttributePtr anAttribute = feature()->attribute(anAttributeID); if (!anAttribute.get()) @@ -149,36 +159,24 @@ QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) { if (anErrorMsg.empty()) - anErrorMsg = "unknown error."; - anErrorMsg = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg.messageString(); + anErrorMsg = "Unknown error."; + + if (anErrorMsg.context().empty()) { + anErrorMsg.setContext(aFeatureID + ":" + anAttributeID + ":" + aValidatorID); + } } - if (!anErrorMsg.empty()) { - std::string aStr = Config_Translator::translate(anErrorMsg); - std::string aCodec = Config_Translator::codec(anErrorMsg.context()); - anError = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()); + if (anErrorMsg.empty() && theValueStateChecked) { + anErrorMsg = getValueStateError(); } - if (anError.isEmpty() && theValueStateChecked) - anError = getValueStateError(); + if (!anErrorMsg.empty()) { + anError = ModuleBase_Tools::translate(anErrorMsg); + } - anError = translateString(anError); return anError; } - -QString ModuleBase_ModelWidget::translateString(const QString& theMsg) const -{ - if (!theMsg.isEmpty()) { - std::string aContext = feature()->getKind(); - std::string aStr = Config_Translator::translate(aContext, theMsg.toStdString().c_str()); - std::string aCodec = Config_Translator::codec(aContext); - return QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()); - } - return theMsg; -} - - void ModuleBase_ModelWidget::enableFocusProcessing() { QList aMyControls = getControls(); @@ -445,3 +443,8 @@ void ModuleBase_ModelWidget::onWidgetValuesModified() { setValueState(ModifiedInPP); } + +QString ModuleBase_ModelWidget::translate(const std::string& theStr) const +{ + return ModuleBase_Tools::translate(context(), theStr); +}