From: vsv Date: Fri, 15 Feb 2019 08:14:46 +0000 (+0300) Subject: Issue #2863: Use Utf8 string for file selector X-Git-Tag: V9_3_0a1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d3b52be3c4baef3776ee87bf5c194d33b0d4aa4d;p=modules%2Fshaper.git Issue #2863: Use Utf8 string for file selector --- diff --git a/src/Model/Model_AttributeString.cpp b/src/Model/Model_AttributeString.cpp index 2b97d891a..0297c8e1b 100644 --- a/src/Model/Model_AttributeString.cpp +++ b/src/Model/Model_AttributeString.cpp @@ -41,12 +41,29 @@ void Model_AttributeString::setValue(const std::string& theValue) } } +void Model_AttributeString::setValue(const std::wstring& theValue) +{ + TCollection_ExtendedString aValue(theValue.c_str()); + if (!myIsInitialized || myString->Get() != aValue) { + if (myString.IsNull()) + myString = TDataStd_Name::Set(myLab, TCollection_ExtendedString()); + myString->Set(aValue); + owner()->data()->sendAttributeUpdated(this); + } +} + std::string Model_AttributeString::value() { if (myString.IsNull()) return ""; // not initialized return TCollection_AsciiString(myString->Get()).ToCString(); } +std::wstring Model_AttributeString::valueW() +{ + if (myString.IsNull()) + return std::wstring(L""); // not initialized + return std::wstring((wchar_t*)(myString->Get().ToExtString())); +} Model_AttributeString::Model_AttributeString(TDF_Label& theLabel) { diff --git a/src/Model/Model_AttributeString.h b/src/Model/Model_AttributeString.h index deabf7788..b424bc935 100644 --- a/src/Model/Model_AttributeString.h +++ b/src/Model/Model_AttributeString.h @@ -41,9 +41,13 @@ class Model_AttributeString : public ModelAPI_AttributeString public: /// Defines the std::string value MODEL_EXPORT virtual void setValue(const std::string& theValue); + /// Defines the std::wstring value + MODEL_EXPORT virtual void setValue(const std::wstring& theValue); /// Returns the std::string value MODEL_EXPORT virtual std::string value(); + /// Returns the std::wstring value + MODEL_EXPORT virtual std::wstring valueW(); protected: /// Initializes attibutes diff --git a/src/ModelAPI/ModelAPI_AttributeString.h b/src/ModelAPI/ModelAPI_AttributeString.h index 93c7ca9c7..803b0966a 100644 --- a/src/ModelAPI/ModelAPI_AttributeString.h +++ b/src/ModelAPI/ModelAPI_AttributeString.h @@ -35,9 +35,13 @@ class ModelAPI_AttributeString : public ModelAPI_Attribute public: /// Defines the string value MODELAPI_EXPORT virtual void setValue(const std::string& theValue) = 0; + /// Defines the wstring value + MODELAPI_EXPORT virtual void setValue(const std::wstring& theValue) = 0; /// Returns the string value MODELAPI_EXPORT virtual std::string value() = 0; + /// Returns the wstring value + MODELAPI_EXPORT virtual std::wstring valueW() = 0; /// Returns the type of this class of attributes MODELAPI_EXPORT static std::string typeId() diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index 85b1772b0..ca0166eae 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -66,6 +66,7 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, aMainLay->addWidget(aTitleLabel, 0, 0); myPathField = new QLineEdit(this); aMainLay->addWidget(myPathField, 1, 0); + QPushButton* aSelectPathBtn = new QPushButton("...", this); aSelectPathBtn->setToolTip(tr("Select file...")); aSelectPathBtn->setMaximumWidth(20); @@ -94,7 +95,7 @@ bool ModuleBase_WidgetFileSelector::storeValueCustom() DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); QString aWidgetValue = myPathField->text(); - aStringAttr->setValue(aWidgetValue.toStdString()); + aStringAttr->setValue(aWidgetValue.toStdWString()); updateObject(myFeature); return true; } @@ -107,11 +108,13 @@ bool ModuleBase_WidgetFileSelector::restoreValueCustom() DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); - bool isBlocked = myPathField->blockSignals(true); - QString aNewText = QString::fromStdString(aStringAttr->value()); - if( myPathField->text() != aNewText ) - myPathField->setText( aNewText ); - myPathField->blockSignals(isBlocked); + std::wstring aUtfStr = aStringAttr->valueW(); + QString aNewText = QString::fromStdWString(aUtfStr); + if (myPathField->text() != aNewText) { + bool isBlocked = myPathField->blockSignals(true); + myPathField->setText(aNewText); + myPathField->blockSignals(isBlocked); + } return true; } @@ -162,7 +165,7 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn() if (!aFileName.isEmpty()) { if (myType == WFS_SAVE) aFileName = applyExtension(aFileName, mySelectedFilter); - myPathField->setText(aFileName); + myPathField->setText(aFileName.toUtf8()); myDefaultPath = QFileInfo(aFileName).absolutePath(); emit focusOutWidget(this); }