Skip to content
Permalink
Browse files

QgsFileWidget: use QgsFocusKeeper added per PR #36722

  • Loading branch information
rouault authored and nyalldawson committed May 26, 2020
1 parent 59282b0 commit 160c6bfc9d8bfc9239b271049242a70663f94896
@@ -141,10 +141,6 @@ is set to QgsFileWidget.RelativeDefaultPath.
emitteed as soon as the current document changes
%End

protected:
virtual bool eventFilter( QObject *watched, QEvent *event );


};

/************************************************************************
@@ -204,7 +204,6 @@ the appearance and behavior of the line edit portion of the widget.
Emitted whenever the current file or directory ``path`` is changed.
%End


};


@@ -55,17 +55,6 @@ QgsExternalResourceWidget::QgsExternalResourceWidget( QWidget *parent )

connect( mFileWidget, &QgsFileWidget::fileChanged, this, &QgsExternalResourceWidget::loadDocument );
connect( mFileWidget, &QgsFileWidget::fileChanged, this, &QgsExternalResourceWidget::valueChanged );
connect( mFileWidget, &QgsFileWidget::blockEvents, this, [this]( bool block )
{
if ( block )
{
installEventFilter( this );
}
else
{
removeEventFilter( this );
}
} );
}

QVariant QgsExternalResourceWidget::documentPath( QVariant::Type type ) const
@@ -205,15 +194,6 @@ void QgsExternalResourceWidget::setDefaultRoot( const QString &defaultRoot )
mDefaultRoot = defaultRoot;
}

bool QgsExternalResourceWidget::eventFilter( QObject *watched, QEvent *event )
{
if ( watched == this && event && ( event->type() == QEvent::FocusOut || event->type() == QEvent::FocusAboutToChange ) )
{
return true;
}
return QWidget::eventFilter( watched, event );
}

QgsFileWidget::RelativeStorage QgsExternalResourceWidget::relativeStorage() const
{
return mRelativeStorage;
@@ -147,10 +147,6 @@ class GUI_EXPORT QgsExternalResourceWidget : public QWidget
//! emitteed as soon as the current document changes
void valueChanged( const QString & );

protected:
// Needed to block events when showing a dialog
bool eventFilter( QObject *watched, QEvent *event ) override;

private slots:
void loadDocument( const QString &path );

@@ -25,6 +25,7 @@

#include "qgssettings.h"
#include "qgsfilterlineedit.h"
#include "qgsfocuskeeper.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsapplication.h"
@@ -310,40 +311,41 @@ void QgsFileWidget::openFileDialog()
QStringList fileNames;
QString title;

emit blockEvents( true );
switch ( mStorageMode )
{
case GetFile:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a file" );
fileName = QFileDialog::getOpenFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions );
break;
case GetMultipleFiles:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select one or more files" );
fileNames = QFileDialog::getOpenFileNames( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions );
break;
case GetDirectory:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a directory" );
fileName = QFileDialog::getExistingDirectory( this, title, QFileInfo( oldPath ).absoluteFilePath(), mOptions | QFileDialog::ShowDirsOnly );
break;
case SaveFile:
QgsFocusKeeper focusKeeper;
switch ( mStorageMode )
{
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Create or select a file" );
if ( !confirmOverwrite() )
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions | QFileDialog::DontConfirmOverwrite );
}
else
case GetFile:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a file" );
fileName = QFileDialog::getOpenFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions );
break;
case GetMultipleFiles:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select one or more files" );
fileNames = QFileDialog::getOpenFileNames( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions );
break;
case GetDirectory:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a directory" );
fileName = QFileDialog::getExistingDirectory( this, title, QFileInfo( oldPath ).absoluteFilePath(), mOptions | QFileDialog::ShowDirsOnly );
break;
case SaveFile:
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions );
}
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Create or select a file" );
if ( !confirmOverwrite() )
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions | QFileDialog::DontConfirmOverwrite );
}
else
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, &mSelectedFilter, mOptions );
}

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

if ( fileName.isEmpty() && fileNames.isEmpty( ) )
return;
@@ -202,14 +202,6 @@ class GUI_EXPORT QgsFileWidget : public QWidget
*/
void fileChanged( const QString &path );

/**
* Emitted before and after showing the file dialog.
*
* \note not available in Python bindings
* \since QGIS 3.10
*/
void blockEvents( bool ) SIP_SKIP;

private slots:
void openFileDialog();
void textEdited( const QString &path );

0 comments on commit 160c6bf

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