From: nds Date: Tue, 7 Nov 2017 12:03:56 +0000 (+0300) Subject: Key_Escape processing in File selector widget. Otherwise, crash happens if file dialo... X-Git-Tag: V_2.10.0RC~172 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1e63ae393cf1ce1923329c90aa66fa33f957f268;p=modules%2Fshaper.git Key_Escape processing in File selector widget. Otherwise, crash happens if file dialog is opened. --- diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index c7e1c0df9..ae84af37e 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -44,7 +44,7 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData) +: ModuleBase_ModelWidget(theParent, theData), myFileDialog(0) { myTitle = translate(theData->getProperty("title")); myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN; @@ -123,6 +123,16 @@ bool ModuleBase_WidgetFileSelector::isCurrentPathValid() 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() @@ -131,17 +141,25 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn() 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 - QString aFileName = (myType == WFS_SAVE) - ? QFileDialog::getSaveFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter, - QFileDialog::DontUseNativeDialog) - : QFileDialog::getOpenFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter, - QFileDialog::DontUseNativeDialog); - if (!aFileName.isEmpty()) { - if (myType == WFS_SAVE) - aFileName = applyExtension(aFileName, mySelectedFilter); - myPathField->setText(aFileName); - emit focusOutWidget(this); + 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); + emit focusOutWidget(this); + } + } } + myFileDialog = 0; } void ModuleBase_WidgetFileSelector::onPathChanged() diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.h b/src/ModuleBase/ModuleBase_WidgetFileSelector.h index 8cfbe91ff..be59f13b4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.h @@ -28,8 +28,9 @@ #include #include -class QWidget; +class QFileDialog; class QLineEdit; +class QWidget; /** * \ingroup GUI @@ -65,7 +66,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelW /// exists and has supported format bool isCurrentPathValid(); - public slots: + /// Reject the current editor dialog if it is shown and returns true. + virtual bool processEscape(); + +public slots: /// Processing of path selection button press void onPathSelectionBtn(); @@ -104,6 +108,7 @@ protected: protected: /// A control for path input QLineEdit* myPathField; + QFileDialog* myFileDialog; ///< started dialog /// A title of open file dialog box QString myTitle;