From efe17b3c886ebdac71a0090714db258ce15bd45a Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 29 Nov 2016 17:08:22 +0300 Subject: [PATCH] Issue #1005: To improve user-friendship of error-messages for features and attributes Improved translation mechanism. --- src/Config/Config_Translator.cpp | 6 +- src/Config/Config_Translator.h | 8 ++- src/Config/Config_WidgetAPI.cpp | 6 ++ src/Config/Config_WidgetAPI.h | 3 + src/Model/Model_Validator.cpp | 14 +++-- src/ModelAPI/ModelAPI_Feature.cpp | 10 ++++ src/ModelAPI/ModelAPI_Feature.h | 6 +- src/ModuleBase/ModuleBase_ActionInfo.cpp | 5 +- src/ModuleBase/ModuleBase_IModule.cpp | 3 +- src/ModuleBase/ModuleBase_ModelWidget.cpp | 55 +++++++++---------- src/ModuleBase/ModuleBase_ModelWidget.h | 23 +++++++- .../ModuleBase_OperationFeature.cpp | 2 +- src/ModuleBase/ModuleBase_Tools.cpp | 23 +++++++- src/ModuleBase/ModuleBase_Tools.h | 11 +++- src/ModuleBase/ModuleBase_WidgetAction.cpp | 14 ++--- src/ModuleBase/ModuleBase_WidgetAction.h | 5 ++ src/ModuleBase/ModuleBase_WidgetBoolValue.cpp | 4 +- src/ModuleBase/ModuleBase_WidgetChoice.cpp | 12 ++-- .../ModuleBase_WidgetDoubleValue.cpp | 4 +- .../ModuleBase_WidgetFeatureSelector.cpp | 4 +- .../ModuleBase_WidgetFileSelector.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetIntValue.cpp | 4 +- src/ModuleBase/ModuleBase_WidgetLabel.cpp | 6 +- src/ModuleBase/ModuleBase_WidgetLineEdit.cpp | 2 +- .../ModuleBase_WidgetMultiSelector.cpp | 5 +- .../ModuleBase_WidgetOptionalBox.cpp | 4 +- .../ModuleBase_WidgetShapeSelector.cpp | 5 +- src/PartSet/PartSet_SketcherMgr.cpp | 11 ++-- src/XGUI/XGUI_ErrorDialog.cpp | 2 +- 29 files changed, 171 insertions(+), 88 deletions(-) diff --git a/src/Config/Config_Translator.cpp b/src/Config/Config_Translator.cpp index 420319988..40980d113 100644 --- a/src/Config/Config_Translator.cpp +++ b/src/Config/Config_Translator.cpp @@ -135,7 +135,7 @@ std::string insertParameters(const std::string& theString, const std::list& theParams) { if (myTranslator.count(theContext) > 0) { @@ -166,6 +166,10 @@ std::string Config_Translator::codec(const std::string& theContext) return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8"; } +std::string Config_Translator::codec(const Events_InfoMessage& theInfo) +{ + return codec(theInfo.context()); +} #ifdef _DEBUG #ifdef MISSED_TRANSLATION diff --git a/src/Config/Config_Translator.h b/src/Config/Config_Translator.h index 158091be3..9359085fa 100644 --- a/src/Config/Config_Translator.h +++ b/src/Config/Config_Translator.h @@ -15,7 +15,7 @@ /// The definition provides collection and writing of missed translations -//#define MISSED_TRANSLATION +#define MISSED_TRANSLATION /** * \class Config_Translator @@ -65,6 +65,12 @@ public: */ static CONFIG_EXPORT std::string codec(const std::string& theContext); + /** + * Returns codec for the context + * \param theInfo the info + */ + static CONFIG_EXPORT std::string codec(const Events_InfoMessage& theInfo); + #ifdef _DEBUG #ifdef MISSED_TRANSLATION static CONFIG_EXPORT void saveMissedTranslations(); diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index e8dcbf4be..c95c03b4d 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -20,6 +20,7 @@ Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml) { myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str()); myCurrentNode = xmlDocGetRootElement(myDoc); + myFeatureId = getProperty(_ID); } Config_WidgetAPI::~Config_WidgetAPI() @@ -101,6 +102,11 @@ bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool th return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault); } +std::string Config_WidgetAPI::featureId() const +{ + return myFeatureId; +} + std::string Config_WidgetAPI::widgetId() const { return getProperty(_ID); diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index e9531e49f..1801f2de6 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -45,6 +45,8 @@ class CONFIG_EXPORT Config_WidgetAPI //! Page is container widget with combo box control to switch between pages bool isPagedWidget() const; + //! Returns id of current feature + std::string featureId() const; //! Returns id of current widget std::string widgetId() const; //! Returns icon of current widget @@ -78,6 +80,7 @@ class CONFIG_EXPORT Config_WidgetAPI private: xmlDocPtr myDoc; //!< Pointer to the root of widget's xml definition xmlNodePtr myCurrentNode; //!< Pointer to the current node in the widget's xml definition + std::string myFeatureId; friend class ModuleBase_WidgetFactory; }; diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index d34681a13..9bf909d8b 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -16,6 +16,8 @@ #include #include +#include + #include void Model_ValidatorsFactory::registerValidator(const std::string& theID, @@ -184,8 +186,10 @@ bool Model_ValidatorsFactory::validate(const std::shared_ptr& if (!aFValidator->isValid(theFeature, anArguments, anError)) { if (anError.empty()) anError = "Unknown error."; - anError = aValidatorID + ": " + anError.messageString(); - theFeature->setError(anError.messageString(), false); + if (anError.context().empty()) { + anError.setContext(theFeature->getKind() + ":" + aValidatorID); + } + theFeature->setError(Config_Translator::translate(anError), false, false); theFeature->data()->execState(ModelAPI_StateInvalidArgument); return false; } @@ -228,8 +232,10 @@ bool Model_ValidatorsFactory::validate(const std::shared_ptr& if (!validate(anAttribute, aValidatorID, anError)) { if (anError.empty()) anError = "Unknown error."; - anError = anAttributeID + " - " + aValidatorID + ": " + anError.messageString(); - theFeature->setError(anError.messageString(), false); + if (anError.context().empty()) { + anError.setContext(theFeature->getKind() + ":" + anAttributeID + ":" + aValidatorID); + } + theFeature->setError(anError.messageString(), false, false); theFeature->data()->execState(ModelAPI_StateInvalidArgument); return false; } diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index b3b60c792..73e0428d2 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -11,6 +11,16 @@ #include #include #include +#include + +void ModelAPI_Feature::setError(const std::string& theError, + bool isSend, + bool isTranslate) +{ + std::string anError = isTranslate ? Config_Translator::translate(getKind(), theError) + : theError; + data()->setError(anError, isSend); +} const std::list >& ModelAPI_Feature::results() { diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index b993ea254..71bd251d8 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -63,9 +63,9 @@ class ModelAPI_Feature : public ModelAPI_Object virtual bool compute(const std::string& theAttributeId) { return false; }; /// Registers error during the execution, causes the ExecutionFailed state - virtual void setError(const std::string& theError, bool isSend = true) { - data()->setError(theError, isSend); - } + MODELAPI_EXPORT virtual void setError(const std::string& theError, + bool isSend = true, + bool isTranslate = true); /// Returns error, arose during the execution virtual std::string error() const { diff --git a/src/ModuleBase/ModuleBase_ActionInfo.cpp b/src/ModuleBase/ModuleBase_ActionInfo.cpp index d44452475..bf1c5a1da 100644 --- a/src/ModuleBase/ModuleBase_ActionInfo.cpp +++ b/src/ModuleBase/ModuleBase_ActionInfo.cpp @@ -8,6 +8,7 @@ #include #include +#include ModuleBase_ActionInfo::ModuleBase_ActionInfo() { @@ -57,8 +58,8 @@ void ModuleBase_ActionInfo::initFrom(std::shared_ptr theM if (!iconFile.isEmpty()) { icon = ModuleBase_IconFactory::loadIcon(iconFile); } - text = QString::fromStdString(theMessage->text()); - toolTip = QString::fromStdString(theMessage->tooltip()); + text = ModuleBase_Tools::translate(theMessage->id(), theMessage->text()); + toolTip = ModuleBase_Tools::translate(theMessage->id(), theMessage->tooltip()); QString aShortcutStr = QString::fromStdString(theMessage->keysequence()); if (!aShortcutStr.isEmpty()) { shortcut = QKeySequence(aShortcutStr); diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index a96d676e5..7a90b5f26 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -103,9 +103,8 @@ bool ModuleBase_IModule::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature) { + // Error already translated. std::string aMsg = ModelAPI_Tools::getFeatureError(theFeature); - ModuleBase_Tools::translate(theFeature->getKind(), aMsg); - return aMsg.c_str(); } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index fdfffa343..db9908a41 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -47,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); @@ -111,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: @@ -134,7 +137,7 @@ QString ModuleBase_ModelWidget::getValueStateError() const } } } - return anError; + return aMessage; } QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const @@ -144,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()) @@ -155,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(); @@ -451,3 +443,8 @@ void ModuleBase_ModelWidget::onWidgetValuesModified() { setValueState(ModifiedInPP); } + +QString ModuleBase_ModelWidget::translate(const std::string& theStr) const +{ + return ModuleBase_Tools::translate(context(), theStr); +} diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 91c83708b..25db7bcfc 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -16,6 +16,7 @@ #include class Config_WidgetAPI; +class Events_InfoMessage; class ModuleBase_IWorkshop; class ModuleBase_ViewerPrs; class ModuleBase_WidgetValidator; @@ -101,7 +102,7 @@ Q_OBJECT /// Returns an attribute error according to the value state /// It exists in all cases excepring the "Store" case - QString getValueStateError() const; + Events_InfoMessage getValueStateError() const; /// Defines if it is supposed that the widget should interact with the viewer. virtual bool isViewerSelector() { return false; } @@ -195,6 +196,18 @@ Q_OBJECT return myFeature; } + /// \return Context for translation + virtual std::string context() const { + + std::string aContext = myFeatureId; + if(!aContext.empty() && !myAttributeID.empty()) { + aContext += ":"; + } + aContext += myAttributeID; + + return aContext; + } + /// Set feature which is processing by active operation /// \param theFeature a feature object /// \param theToStoreValue a value about necessity to store the widget value to the feature @@ -222,6 +235,9 @@ Q_OBJECT /// \param theObj is object for moving static void moveObject(ObjectPtr theObj); + /// Translate passed string with widget context() + virtual QString translate(const std::string& theStr) const; + signals: /// The signal about widget values are to be changed void beforeValuesChanged(); @@ -300,8 +316,6 @@ protected: /// The method called when widget is activated virtual void activateCustom() {}; - QString translateString(const QString& theMsg) const; - protected slots: /// Processing of values changed in model widget by store the current value to the feature void onWidgetValuesChanged(); @@ -319,6 +333,9 @@ protected slots: /// A feature which is processing by active operation FeaturePtr myFeature; + /// A feature ID + std::string myFeatureId; + /// Flag which shows that current operation is in editing mode bool myIsEditing; diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 099d42b6f..a2c03e0b2 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -102,7 +102,7 @@ bool ModuleBase_OperationFeature::isValid() const return true; std::string anError = ModelAPI_Tools::getFeatureError(myFeature); - ModuleBase_Tools::translate(myFeature->getKind(), anError); + //ModuleBase_Tools::translate(myFeature->getKind(), anError); return anError.empty(); } diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index d8bd65675..41b19a1f4 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -1212,15 +1212,34 @@ void convertToFeatures(const QObjectPtrList& theObjects, std::set& t } } -void translate(const std::string& theContext, std::string& theMessage) +QString translate(const Events_InfoMessage& theMessage) { + QString aMessage; + + if (!theMessage.empty()) { + std::string aStr = Config_Translator::translate(theMessage); + if (!aStr.empty()) { + std::string aCodec = Config_Translator::codec(theMessage); + aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()); + } + } + + return aMessage; +} + +QString translate(const std::string& theContext, const std::string& theMessage) +{ + QString aMessage; + if (!theMessage.empty()) { std::string aStr = Config_Translator::translate(theContext, theMessage); if (!aStr.empty()) { std::string aCodec = Config_Translator::codec(theContext); - theMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()).toStdString(); + aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()); } } + + return aMessage; } void setPointBallHighlighting(AIS_Shape* theAIS) diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 44e492df3..ab5b63073 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -38,6 +38,8 @@ class ModuleBase_IWorkshop; class GeomAPI_Shape; +class Events_InfoMessage; + namespace ModuleBase_Tools { /// Methods to adjust margins and spacings. @@ -316,13 +318,18 @@ void MODULEBASE_EXPORT convertToFeatures(const QObjectPtrList& theObjects, std::set& theFeatures); +/// Returns translation from the given data. +/// If translation is not exists then it returns a string +/// from the info data without translation +/// \param theMessage a message which dave to be translated +QString MODULEBASE_EXPORT translate(const Events_InfoMessage& theMessage); + /// Returns translation from the given data. /// If translation is not exists then it returns a string /// from the info data without translation /// \param theContext context of the message (Feature Id) /// \param theMessage a message which dave to be translated -/// \param theParams a list of parameters (can be empty) -void MODULEBASE_EXPORT translate(const std::string& theContext, std::string& theMessage); +QString MODULEBASE_EXPORT translate(const std::string& theContext, const std::string& theMessage); /// Set Highlighting of points as a Ball shape /// \param theAIS - the presentation diff --git a/src/ModuleBase/ModuleBase_WidgetAction.cpp b/src/ModuleBase/ModuleBase_WidgetAction.cpp index b0206a5a5..a5ddbbe96 100755 --- a/src/ModuleBase/ModuleBase_WidgetAction.cpp +++ b/src/ModuleBase/ModuleBase_WidgetAction.cpp @@ -18,18 +18,18 @@ ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) +: ModuleBase_ModelWidget(theParent, theData), + myActionID(attributeID()) { + setAttributeID(""); // To prevent errors. Action not stored as attribtue in feature. QHBoxLayout* aControlLay = new QHBoxLayout(this); ModuleBase_Tools::adjustMargins(aControlLay); - myActionID = attributeID(); - setAttributeID(""); - myButton = new QToolButton(this); - QString aText = QString::fromStdString(theData->widgetLabel()); - QString aToolTip = ModuleBase_Tools::wrapTextByWords( - QString::fromStdString(theData->widgetTooltip()), myButton, DEFAULT_TOOL_TIP_WIDTH); + QString aText = translate(theData->widgetLabel()); + QString aToolTip = ModuleBase_Tools::wrapTextByWords(translate(theData->widgetTooltip()), + myButton, + DEFAULT_TOOL_TIP_WIDTH); myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); aControlLay->addWidget(myButton); diff --git a/src/ModuleBase/ModuleBase_WidgetAction.h b/src/ModuleBase/ModuleBase_WidgetAction.h index b6e8b72f0..9003a91a4 100755 --- a/src/ModuleBase/ModuleBase_WidgetAction.h +++ b/src/ModuleBase/ModuleBase_WidgetAction.h @@ -36,6 +36,11 @@ Q_OBJECT /// \return a control list virtual QList getControls() const; + /// \return Context for translation + virtual std::string context() const { + return myFeature->getKind() + ":" + myActionID; + } + protected: /// Do nothing /// \return True in success diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index b0ff0d2a1..44676ec51 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -24,8 +24,8 @@ ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent, theData) { - QString aText = QString::fromStdString(theData->widgetLabel()); - QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + QString aText = translate(theData->widgetLabel()); + QString aToolTip = translate(theData->widgetTooltip()); bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false); myCheckBox = new QCheckBox(aText, this); diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index 49e73a243..3c23cbf48 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -29,13 +29,17 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, QHBoxLayout* aLayout = new QHBoxLayout(this); ModuleBase_Tools::adjustMargins(aLayout); - QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); std::string aTypes = theData->getProperty("string_list"); - QStringList aList = QString(aTypes.c_str()).split(' '); + QStringList aList; + + foreach(QString aType, QString(aTypes.c_str()).split(' ')) { + aList.append(translate(aType.toStdString())); + } if (theData->getBooleanAttribute("use_in_title", false)) - myButtonTitles = QString(aTypes.c_str()).split(" "); + myButtonTitles = aList; // Widget type can be combobox or radiobuttons std::string aWgtType = theData->getProperty("widget_type"); @@ -164,7 +168,7 @@ QString ModuleBase_WidgetChoice::getPropertyPanelTitle(int theIndex) { QString aTitle; if (myButtonTitles.length() > theIndex) - aTitle = tr(myButtonTitles[theIndex].toStdString().c_str()); + aTitle = myButtonTitles[theIndex]; return aTitle; } diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index a490c4d25..f868e04bc 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -41,7 +41,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, QFormLayout* aControlLay = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aControlLay); - QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, this); if (!aLabelIcon.isEmpty()) @@ -86,7 +86,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, mySpinBox->setValue(aDefVal); } - QString aTTip = QString::fromStdString(theData->widgetTooltip()); + QString aTTip = translate(theData->widgetTooltip()); mySpinBox->setToolTip(aTTip); myLabel->setToolTip(aTTip); diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp index f7bbe4e78..4dcbecf71 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp @@ -59,14 +59,14 @@ ModuleBase_WidgetFeatureSelector::ModuleBase_WidgetFeatureSelector(QWidget* theP QFormLayout* aLayout = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aLayout); - QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, this); if (!aLabelIcon.isEmpty()) myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon)); - QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + QString aToolTip = translate(theData->widgetTooltip()); myTextLine = new QLineEdit(this); QString anObjName = QString::fromStdString(attributeID()); myTextLine->setObjectName(anObjName); diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index d0d00aebb..534c7c8c4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -34,7 +34,7 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent, theData) { - myTitle = QString::fromStdString(theData->getProperty("title")); + myTitle = translate(theData->getProperty("title")); myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN; myDefaultPath = QString::fromStdString(theData->getProperty("path")); diff --git a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp index 8b69bac56..3755b6a64 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp @@ -42,7 +42,7 @@ ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent, QFormLayout* aControlLay = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aControlLay); - QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, this); if (!aLabelIcon.isEmpty()) @@ -80,7 +80,7 @@ ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent, mySpinBox->setValue(aDefVal); } - QString aTTip = QString::fromStdString(theData->widgetTooltip()); + QString aTTip = translate(theData->widgetTooltip()); mySpinBox->setToolTip(aTTip); myLabel->setToolTip(aTTip); diff --git a/src/ModuleBase/ModuleBase_WidgetLabel.cpp b/src/ModuleBase/ModuleBase_WidgetLabel.cpp index e111aa883..8c4cd1467 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabel.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLabel.cpp @@ -23,7 +23,7 @@ ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent, theData) { - QString aText = QString::fromStdString(theData->getProperty("title")); + QString aText = translate(theData->getProperty("title")); QString aLabelIcon = QString::fromStdString(theData->getProperty("icon")); myLabel = new QLabel(aText, theParent); if (!aLabelIcon.isEmpty()) { @@ -64,8 +64,8 @@ bool ModuleBase_WidgetLabel::restoreValueCustom() if (aStrAttr.get()) { aMsg = aStrAttr->value(); } - ModuleBase_Tools::translate(myFeature->getKind(), aMsg); - myLabel->setText(aMsg.c_str()); + QString aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg); + myLabel->setText(aText); } return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp index e8da69f17..7572a4a86 100644 --- a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp @@ -81,7 +81,7 @@ ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent, { QFormLayout* aMainLay = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); - QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); QLabel* aLabel = new QLabel(aLabelText, this); if (!aLabelIcon.isEmpty()) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 2e8e7a6cb..fe5e99ecc 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -117,9 +117,8 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myTypeCombo->setVisible(false); } - std::string aLabelText = theData->getProperty("label"); - QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str() - : tr("Selected objects:"), this); + QString aLabelText = translate(theData->getProperty("label")); + QLabel* aListLabel = new QLabel(aLabelText, this); aMainLay->addWidget(aListLabel, 1, 0); // if the xml definition contains one type, an information label // should be shown near to the latest diff --git a/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp b/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp index b2e6ad5a4..73a80de18 100755 --- a/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp @@ -131,11 +131,11 @@ void ModuleBase_WidgetOptionalBox::createControl(const OptionType& theType) if (theType == GroupBox && !myGroupBox) { // group box: more than one model widget is inside myGroupBox = new QGroupBox(this); - myGroupBox->setTitle(QString::fromStdString(myGroupTitle)); + myGroupBox->setTitle(translate(myGroupTitle)); myGroupBox->setVisible(false); myGroupBox->setCheckable(true); myGroupBox->setChecked(getDefaultValue() == "true"); - myGroupBox->setToolTip(QString::fromStdString(myToolTip)); + myGroupBox->setToolTip(translate(myToolTip)); myGroupBoxLayout = new QGridLayout(myGroupBox); ModuleBase_Tools::zeroMargins(myGroupBoxLayout); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 8b07d5851..46fc98370 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -73,14 +74,14 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen QFormLayout* aLayout = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aLayout); - QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelText = translate(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, this); if (!aLabelIcon.isEmpty()) myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon)); - QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + QString aToolTip = translate(theData->widgetTooltip()); myTextLine = new QLineEdit(this); QString anObjName = QString::fromStdString(attributeID()); myTextLine->setObjectName(anObjName); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 32a636598..54619b476 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -699,17 +699,16 @@ bool PartSet_SketcherMgr::sketchSolverError() QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) { - std::string anError = ""; + QString anError; if (!theFeature.get() || !theFeature->data()->isValid()) - return anError.c_str(); + return anError; CompositeFeaturePtr aSketch = activeSketch(); if (aSketch.get() && aSketch == theFeature) { - AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR()); - anError = aAttributeString->value(); - ModuleBase_Tools::translate(aSketch->getKind(), anError); + std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value(); + anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError); } - return anError.c_str(); + return anError; } void PartSet_SketcherMgr::clearClickedFlags() diff --git a/src/XGUI/XGUI_ErrorDialog.cpp b/src/XGUI/XGUI_ErrorDialog.cpp index 511d1f578..6c278f9d7 100644 --- a/src/XGUI/XGUI_ErrorDialog.cpp +++ b/src/XGUI/XGUI_ErrorDialog.cpp @@ -61,7 +61,7 @@ void XGUI_ErrorDialog::clear() void XGUI_ErrorDialog::addError(std::shared_ptr theMsg) { std::string aError = Config_Translator::translate(*theMsg); - std::string aCodec = Config_Translator::codec(theMsg->context()); + std::string aCodec = Config_Translator::codec(*theMsg); QString aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aError.c_str()); myErrors.append(aMsg); refresh(); -- 2.30.2