X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FModuleBase%2FModuleBase_WidgetFileSelector.cpp;h=7191889876c70c5b4b58ceb8083e761ea6b35781;hb=2632fd4da93042ee9d7787467aed233f4d272fff;hp=ca7ee5de1a7f29e16f59b81e3aa547fa9183d16e;hpb=bd8c3462c2a97a58228917a4dca039060a954330;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index ca7ee5de1..719188987 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -42,13 +41,19 @@ #include #include + +/// Default path +static QString myDefaultPath; + + ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, const Config_WidgetAPI* theData) : ModuleBase_ModelWidget(theParent, theData), myFileDialog(0) { myTitle = translate(theData->getProperty("title")); myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN; - myDefaultPath = QString::fromStdString(theData->getProperty("path")); + if (myDefaultPath.isNull() || myDefaultPath.isEmpty()) + myDefaultPath = QString::fromStdString(theData->getProperty("path")); if (myDefaultPath.isEmpty()) myDefaultPath = Config_PropManager::string("Plugins", "import_initial_path").c_str(); @@ -60,6 +65,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); @@ -88,7 +94,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; } @@ -101,11 +107,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); + char16_t* aStr = aStringAttr->valueU(); + QString aNewText = QString::fromUtf16(aStr); + if (myPathField->text() != aNewText) { + bool isBlocked = myPathField->blockSignals(true); + myPathField->setText(aNewText); + myPathField->blockSignals(isBlocked); + } return true; } @@ -139,6 +147,7 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn() ? myDefaultPath : QFileInfo(myPathField->text()).absolutePath(); QString aFilter = filterString(); + // use Option prohibited native dialog using to have both lower/upper extensions of files // satisfied to dialog filter on Linux(Calibre) Issue #2055 myFileDialog = new QFileDialog(this, myTitle, aDefaultPath, aFilter); @@ -155,7 +164,8 @@ 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); } } @@ -236,7 +246,7 @@ QString ModuleBase_WidgetFileSelector::applyExtension(const QString& theFileName bool hasExtension = false; QStringList anExtensions = filterToExtensions(theFilter); foreach(const QString& anExtension, anExtensions) { - if (theFileName.endsWith(anExtension.section(".", 1, 1), Qt::CaseInsensitive)) { + if (theFileName.endsWith(QString(".") + anExtension.section(".", 1, 1), Qt::CaseInsensitive)) { hasExtension = true; break; }