Skip to content
Permalink
Browse files

QgsBinaryWidgetWrapper: fix focus-related crash (fixes #30210)

  • Loading branch information
rouault committed May 26, 2020
1 parent f9bfbe7 commit 46c9d1f583e07abb5344a9517440213f95f2e569
Showing with 27 additions and 10 deletions.
  1. +27 −10 src/gui/editorwidgets/qgsbinarywidgetwrapper.cpp
@@ -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"
@@ -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;
@@ -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() )
{
@@ -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();

0 comments on commit 46c9d1f

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