-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-/*
- * ModuleBase_WidgetFileSelector.cpp
- *
- * Created on: Aug 28, 2014
- * Author: sbh
- */
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModuleBase_WidgetFileSelector.h>
#include <ModuleBase_Tools.h>
+#include <Config_PropManager.h>
#include <Config_WidgetAPI.h>
#include <QFileDialog>
#include <memory>
#include <string>
+
+/// Default path
+static QString myDefaultPath;
+
+
ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent,
- const Config_WidgetAPI* theData,
- const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId)
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData), myFileDialog(0)
{
- 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"));
+ if (myDefaultPath.isNull() || myDefaultPath.isEmpty())
+ myDefaultPath = QString::fromStdString(theData->getProperty("path"));
+
+ if (myDefaultPath.isEmpty())
+ myDefaultPath = Config_PropManager::string("Plugins", "import_initial_path").c_str();
QGridLayout* aMainLay = new QGridLayout(this);
ModuleBase_Tools::adjustMargins(aMainLay);
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);
{
}
-bool ModuleBase_WidgetFileSelector::storeValueCustom() const
+bool ModuleBase_WidgetFileSelector::storeValueCustom()
{
- // A rare case when plugin was not loaded.
+ // A rare case when plugin was not loaded.
if (!myFeature)
return false;
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;
}
bool ModuleBase_WidgetFileSelector::restoreValueCustom()
{
- // A rare case when plugin was not loaded.
+ // A rare case when plugin was not loaded.
if (!myFeature)
return false;
DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
- bool isBlocked = myPathField->blockSignals(true);
- myPathField->setText(QString::fromStdString(aStringAttr->value()));
- 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;
}
return aFile.exists();
}
+bool ModuleBase_WidgetFileSelector::processEscape()
+{
+ if (myFileDialog) {
+ myFileDialog->reject();
+ return true;
+ }
+ return ModuleBase_ModelWidget::processEscape();
+}
+
+
void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
{
QString aDefaultPath = myPathField->text().isEmpty()
? myDefaultPath
: QFileInfo(myPathField->text()).absolutePath();
QString aFilter = filterString();
- QString aFileName = (myType == WFS_SAVE)
- ? QFileDialog::getSaveFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter)
- : QFileDialog::getOpenFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter);
- if (!aFileName.isEmpty()) {
- if (myType == WFS_SAVE)
- aFileName = applyExtension(aFileName, mySelectedFilter);
- myPathField->setText(aFileName);
+
+ // 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);
+ myFileDialog->setNameFilter(aFilter);
+ myFileDialog->setOptions(QFileDialog::DontUseNativeDialog);
+ myFileDialog->setAcceptMode(myType == WFS_SAVE ? QFileDialog::AcceptSave
+ : QFileDialog::AcceptOpen);
+ if (myFileDialog->exec() == QDialog::Accepted)
+ {
+ mySelectedFilter = myFileDialog->selectedNameFilter();
+ QStringList aFileNames = myFileDialog->selectedFiles();
+ if (!aFileNames.empty()) {
+ QString aFileName = aFileNames.first();
+ if (!aFileName.isEmpty()) {
+ if (myType == WFS_SAVE)
+ aFileName = applyExtension(aFileName, mySelectedFilter);
+ myPathField->setText(aFileName.toUtf8());
+ myDefaultPath = QFileInfo(aFileName).absolutePath();
+ emit focusOutWidget(this);
+ }
+ }
}
+ myFileDialog = 0;
}
void ModuleBase_WidgetFileSelector::onPathChanged()