Don't delete QgsAttributeDialog too early. Fixes #15737

This commit is contained in:
Hugo Mercier 2016-10-28 11:17:46 +02:00
parent ea2e68b8ae
commit 9ecdf61014
3 changed files with 22 additions and 18 deletions

View File

@ -102,7 +102,9 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
QgsAttributeDialog *dialog = newDialog( true ); QgsAttributeDialog *dialog = newDialog( true );
dialog->setHighlight( h ); dialog->setHighlight( h );
dialog->show(); // will also delete the dialog on close (show() is overridden) // delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->show();
return true; return true;
} }
@ -112,22 +114,27 @@ bool QgsFeatureAction::editFeature( bool showModal )
if ( !mLayer ) if ( !mLayer )
return false; return false;
QgsAttributeDialog *dialog = newDialog( false ); if ( showModal )
{
QScopedPointer<QgsAttributeDialog> dialog( newDialog( false ) );
if ( !mFeature->isValid() ) if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode ); dialog->setMode( QgsAttributeForm::AddFeatureMode );
if ( showModal )
{
dialog->setAttribute( Qt::WA_DeleteOnClose );
int rv = dialog->exec(); int rv = dialog->exec();
mFeature->setAttributes( dialog->feature()->attributes() ); mFeature->setAttributes( dialog->feature()->attributes() );
return rv; return rv;
} }
else else
{ {
dialog->show(); // will also delete the dialog on close (show() is overridden) QgsAttributeDialog* dialog = newDialog( false );
if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->show();
} }
return true; return true;
@ -204,6 +211,8 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
else else
{ {
QgsAttributeDialog *dialog = newDialog( false ); QgsAttributeDialog *dialog = newDialog( false );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setMode( QgsAttributeForm::AddFeatureMode ); dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setEditCommandMessage( text() ); dialog->setEditCommandMessage( text() );
@ -212,12 +221,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
if ( !showModal ) if ( !showModal )
{ {
setParent( dialog ); // keep dialog until the dialog is closed and destructed setParent( dialog ); // keep dialog until the dialog is closed and destructed
dialog->show(); // will also delete the dialog on close (show() is overridden) dialog->show();
mFeature = nullptr; mFeature = nullptr;
return true; return true;
} }
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->exec(); dialog->exec();
} }

View File

@ -69,11 +69,8 @@ void QgsAttributeDialog::accept()
QDialog::accept(); QDialog::accept();
} }
void QgsAttributeDialog::show( bool autoDelete ) void QgsAttributeDialog::show()
{ {
if ( autoDelete )
setAttribute( Qt::WA_DeleteOnClose );
QDialog::show(); QDialog::show();
raise(); raise();
activateWindow(); activateWindow();

View File

@ -106,9 +106,8 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
void accept() override; void accept() override;
void reject() override; void reject() override;
//! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form and is deleted when //! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form
//! closed. void show();
void show( bool autoDelete = true );
private: private:
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons ); void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons );