Skip to content

Commit

Permalink
QgsBinaryWidgetWrapper: fix focus-related crash (fixes #30210)
Browse files Browse the repository at this point in the history
(cherry picked from commit 46c9d1f)
  • Loading branch information
rouault authored and nyalldawson committed Jun 19, 2020
1 parent af28b42 commit 33db5e7
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/gui/editorwidgets/qgsbinarywidgetwrapper.cpp
Expand Up @@ -17,6 +17,7 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsfileutils.h"
#include "qgsfocuskeeper.h"
#include "qgssettings.h"
#include "qgsmessagebar.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -135,10 +136,16 @@ void QgsBinaryWidgetWrapper::updateValues( const QVariant &value, const QVariant
void QgsBinaryWidgetWrapper::saveContent()
{
QgsSettings s;
QString file = QFileDialog::getSaveFileName( nullptr,
tr( "Save Contents to File" ),
defaultPath(),
tr( "All files" ) + " (*.*)" );

QString file;
{
QgsFocusKeeper focusKeeper;

file = QFileDialog::getSaveFileName( nullptr,
tr( "Save Contents to File" ),
defaultPath(),
tr( "All files" ) + " (*.*)" );
}
if ( file.isEmpty() )
{
return;
Expand All @@ -160,10 +167,17 @@ void QgsBinaryWidgetWrapper::saveContent()
void QgsBinaryWidgetWrapper::setContent()
{
QgsSettings s;
QString file = QFileDialog::getOpenFileName( nullptr,
tr( "Embed File" ),
defaultPath(),
tr( "All files" ) + " (*.*)" );

QString file;
{
QgsFocusKeeper focusKeeper;

file = QFileDialog::getOpenFileName( nullptr,
tr( "Embed File" ),
defaultPath(),
tr( "All files" ) + " (*.*)" );
}

QFileInfo fi( file );
if ( file.isEmpty() || !fi.exists() )
{
Expand All @@ -184,8 +198,11 @@ void QgsBinaryWidgetWrapper::setContent()

void QgsBinaryWidgetWrapper::clear()
{
if ( QMessageBox::question( nullptr, tr( "Clear Contents" ), tr( "Are you sure you want the clear this field's content?" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;
{
QgsFocusKeeper focusKeeper;
if ( QMessageBox::question( nullptr, tr( "Clear Contents" ), tr( "Are you sure you want the clear this field's content?" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;
}

updateValues( QByteArray() );
emitValueChanged();
Expand Down

0 comments on commit 33db5e7

Please sign in to comment.