Skip to content
Permalink
Browse files

Fix extensions not automatically added to new filenames in QgsFileWidget

Fixes a UX regression introduced by swapping dialogs to use
QgsFileWidget, where on some platforms the extension is not
automatically added for selected file names
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent 128e37e commit 7c8f4c3e12065cddce7371861613fe020314e4e8
Showing with 12 additions and 3 deletions.
  1. +11 −3 src/gui/qgsfilewidget.cpp
  2. +1 −0 tests/src/python/CMakeLists.txt
@@ -29,6 +29,7 @@
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsapplication.h"
#include "qgsfileutils.h"

QgsFileWidget::QgsFileWidget( QWidget *parent )
: QWidget( parent )
@@ -263,16 +264,23 @@ void QgsFileWidget::openFileDialog()
fileName = QFileDialog::getExistingDirectory( this, title, QFileInfo( oldPath ).absoluteFilePath(), QFileDialog::ShowDirsOnly );
break;
case SaveFile:
{
QString filter;
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Create or select a file" );
if ( !confirmOverwrite() )
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, nullptr, QFileDialog::DontConfirmOverwrite );
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &filter, QFileDialog::DontConfirmOverwrite );
}
else
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter );
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &filter );
}
break;

// make sure filename ends with filter. This isn't automatically done by
// getSaveFileName on some platforms (e.g. gnome)
fileName = QgsFileUtils::addExtensionFromFilter( fileName, filter );
}
break;
}

if ( fileName.isEmpty() && fileNames.isEmpty( ) )
@@ -65,6 +65,7 @@ ADD_PYTHON_TEST(PyQgsFeatureIterator test_qgsfeatureiterator.py)
ADD_PYTHON_TEST(PyQgsFeedback test_qgsfeedback.py)
ADD_PYTHON_TEST(PyQgsFields test_qgsfields.py)
ADD_PYTHON_TEST(PyQgsFieldModel test_qgsfieldmodel.py)
ADD_PYTHON_TEST(PyQgsFileUtils test_qgsfileutils.py)
ADD_PYTHON_TEST(PyQgsFilterLineEdit test_qgsfilterlineedit.py)
ADD_PYTHON_TEST(PyQgsFloatingWidget test_qgsfloatingwidget.py)
ADD_PYTHON_TEST(PyQgsFontButton test_qgsfontbutton.py)

0 comments on commit 7c8f4c3

Please sign in to comment.
You can’t perform that action at this time.