Salome HOME
Issue #1005: To improve user-friendship of error-messages for features and attributes
authordbv <dbv@opencascade.com>
Tue, 29 Nov 2016 14:08:22 +0000 (17:08 +0300)
committerdbv <dbv@opencascade.com>
Fri, 2 Dec 2016 12:45:28 +0000 (15:45 +0300)
Improved translation mechanism.

29 files changed:
src/Config/Config_Translator.cpp
src/Config/Config_Translator.h
src/Config/Config_WidgetAPI.cpp
src/Config/Config_WidgetAPI.h
src/Model/Model_Validator.cpp
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/ModuleBase/ModuleBase_ActionInfo.cpp
src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/ModuleBase/ModuleBase_WidgetAction.cpp
src/ModuleBase/ModuleBase_WidgetAction.h
src/ModuleBase/ModuleBase_WidgetBoolValue.cpp
src/ModuleBase/ModuleBase_WidgetChoice.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.cpp
src/ModuleBase/ModuleBase_WidgetIntValue.cpp
src/ModuleBase/ModuleBase_WidgetLabel.cpp
src/ModuleBase/ModuleBase_WidgetLineEdit.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/XGUI/XGUI_ErrorDialog.cpp

index 420319988ed605a0e501c3272c04e0855af2bb8c..40980d113b10dc13f002773bbc352e8761e564cb 100644 (file)
@@ -135,7 +135,7 @@ std::string insertParameters(const std::string& theString, const std::list<std::
 }
 
 std::string Config_Translator::translate(const std::string& theContext,
-                                         const std::string& theMessage, 
+                                         const std::string& theMessage,
                                          const std::list<std::string>& 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
index 158091be3f6a79c96745b679e14507f3006e8184..9359085fa4e6f75c536058c7e60259b08993de5f 100644 (file)
@@ -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();
index e8dcbf4be98df31111a8965313a46475d6ffccff..c95c03b4d01a00e793852234cbbc66547f5d1c94 100644 (file)
@@ -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);
index e9531e49fb7af27c9615c666c2e172a0a7af2df9..1801f2de6c31ce376e66451727d9518f8026c62f 100644 (file)
@@ -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;
 };
index d34681a13a2c5c9e4a7115d8c72ab9d5478ad282..9bf909d8b203c3599e0b01840821d602dc36612b 100644 (file)
@@ -16,6 +16,8 @@
 #include <ModelAPI_Result.h>
 #include <Model_Data.h>
 
+#include <Config_Translator.h>
+
 #include <Events_InfoMessage.h>
 
 void Model_ValidatorsFactory::registerValidator(const std::string& theID,
@@ -184,8 +186,10 @@ bool Model_ValidatorsFactory::validate(const std::shared_ptr<ModelAPI_Feature>&
         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<ModelAPI_Feature>&
     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;
     }
index b3b60c7926d9207da78aa997b1e827c4fc826284..73e0428d257012d02c765a953b48970cf390f769 100644 (file)
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Session.h>
 #include <Events_Loop.h>
+#include <Config_Translator.h>
+
+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<std::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results()
 {
index b993ea254eb5b22430670cdef19eca1ea8a52fa8..71bd251d8802d78f6717193f34659fa367ddac7a 100644 (file)
@@ -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 {
index d444524752d4f50aaa1bf68d7a6059945c588981..bf1c5a1da6908332aa4be3a9cf4adf9922204e46 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <ModuleBase_ActionInfo.h>
 #include <ModuleBase_IconFactory.h>
+#include <ModuleBase_Tools.h>
 
 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
 {
@@ -57,8 +58,8 @@ void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> 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);
index a96d676e5fb28ea55f560b954a9d06ecaaedf8d1..7a90b5f2690fe43077d4c71cec1eae726841ce3c 100644 (file)
@@ -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();
 }
 
index fdfffa34389b7df51a34a367975047e4141ebec0..db9908a41da042ddfb9ca90f48b5799b48ddf1e5 100644 (file)
@@ -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<QWidget*> 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);
+}
index 91c83708ba3768d4d5c1690037fdb7a3d2ea8bf7..25db7bcfce3ca4be4388b04609374bb89eeebc8d 100644 (file)
@@ -16,6 +16,7 @@
 #include <memory>
 
 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;
 
index 099d42b6fc282dd0aa6c0a9ba782fa260136be53..a2c03e0b2b1719e9d1fff4a72102884e455bb1c2 100755 (executable)
@@ -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();
 }
 
index d8bd656751fceb6eba0465c80f2f5cd67d771b62..41b19a1f4d5c6600bbeaa4d8d6a24f63f853d2cc 100755 (executable)
@@ -1212,15 +1212,34 @@ void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& 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)
index 44e492df369412e4ec02a1b8043cf0cff1dd34f7..ab5b63073466ece1c3f9187527356f72f12f75c9 100755 (executable)
@@ -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<FeaturePtr>& 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
index b0206a5a5a0921e924ee2dccbe4e35e3fb08ea47..a5ddbbe9660e1a88905316cee155c71e50a7d362 100755 (executable)
 
 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);
index b6e8b72f0614e427f1e71b64f9e73da38beec85a..9003a91a41e798c722aa5a442391cd470e4e9116 100755 (executable)
@@ -36,6 +36,11 @@ Q_OBJECT
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
+  /// \return Context for translation
+  virtual std::string context() const {
+    return myFeature->getKind() + ":" + myActionID;
+  }
+
 protected:
   /// Do nothing
   /// \return True in success
index b0ff0d2a10343f2a15d929598b7824557acb5f62..44676ec5172b62db65968a73e52b421ba1f2556f 100644 (file)
@@ -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);
index 49e73a24301f10aced4c5b06bfaf4711c15cd52f..3c23cbf482d28422acb26c908fbfbd2d2b189f0e 100644 (file)
@@ -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;
 }
 
index a490c4d2515b1cf0fd8d104f489817e296723fe4..f868e04bcc82ac12c04890e3b522d98da44edb4b 100644 (file)
@@ -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);
 
index f7bbe4e783d3ffccf64f1a518f9da95921b823d3..4dcbecf714aac75d12b8fc0ab17c9c7228ec3bcf 100644 (file)
@@ -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);
index d0d00aebb5ad0d1d3b7a148e411e2e79830a93ba..534c7c8c44c7925b66433eec8315d88d4f9db9c7 100644 (file)
@@ -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"));
 
index 8b69bac5638e5a8566509d85b2d31b300d57c71b..3755b6a64e8c75885006eee6612a93ead97a6eff 100644 (file)
@@ -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);
 
index e111aa8838c745fa9f2855b8ad20657a03bbbe1c..8c4cd1467c3d723d818fb3d45588cdf8487671de 100644 (file)
@@ -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;
 }
index e8da69f1745cd679ff589506e1a44e0d636030d5..7572a4a865641413213dd1461a9ed43e78374fc5 100644 (file)
@@ -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())
index 2e8e7a6cb36e6eda6433a2413fdb0210e70e5a63..fe5e99ecc75774a09de5d31c28f4b29f7b17edd5 100755 (executable)
@@ -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
index b2e6ad5a4bf044c730460b3f266652043f88d17c..73a80de18221689321085d338c922d40927d3ca1 100755 (executable)
@@ -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);
index 8b07d585103bc4bfa081025d1275d10307b767f8..46fc98370adee4d886d1cd61bee8afb68bb1dc78 100644 (file)
@@ -16,6 +16,7 @@
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_IconFactory.h>
 
+#include <Config_Translator.h>
 #include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
 #include <Events_Message.h>
@@ -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);
index 32a636598fa3dcc26caabb5a33918ae4add34d36..54619b476044b6e0216116e73ced2f04bf7cdcc5 100755 (executable)
@@ -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()
index 511d1f578efdfa131d81cb16bfc24098b6ce344c..6c278f9d75a71457ab7c48c13dd881f2dfb71056 100644 (file)
@@ -61,7 +61,7 @@ void XGUI_ErrorDialog::clear()
 void XGUI_ErrorDialog::addError(std::shared_ptr<Events_InfoMessage> 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();