Skip to content

Commit

Permalink
Don't delete QgsAttributeDialog too early. Fixes #15737
Browse files Browse the repository at this point in the history
(cherry picked from commit 9ecdf61)
  • Loading branch information
Hugo Mercier committed Oct 28, 2016
1 parent 66a213b commit 9f228d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
32 changes: 20 additions & 12 deletions src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )

QgsAttributeDialog *dialog = newDialog( true );
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;
}
Expand All @@ -108,24 +110,29 @@ bool QgsFeatureAction::editFeature( bool showModal )
if ( !mLayer )
return false;

QgsAttributeDialog *dialog = newDialog( false );

if ( !mFeature->isValid() )
dialog->setIsAddDialog( true );

if ( showModal )
{
dialog->setAttribute( Qt::WA_DeleteOnClose );
int rv = dialog->exec();
QScopedPointer<QgsAttributeDialog> dialog( newDialog( false ) );

if ( !mFeature->isValid() )
dialog->setIsAddDialog( true );

int rv = dialog->exec();
mFeature->setAttributes( dialog->feature()->attributes() );
return rv;
}
else
{
dialog->show(); // will also delete the dialog on close (show() is overridden)
}
QgsAttributeDialog* dialog = newDialog( false );

if ( !mFeature->isValid() )
dialog->setIsAddDialog( true );

// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->show();
}

return true;
}

Expand Down Expand Up @@ -193,6 +200,8 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
else
{
QgsAttributeDialog *dialog = newDialog( false );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setIsAddDialog( true );
dialog->setEditCommandMessage( text() );

Expand All @@ -201,12 +210,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
if ( !showModal )
{
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;
return true;
}

dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->exec();
}

Expand Down
5 changes: 1 addition & 4 deletions src/gui/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ void QgsAttributeDialog::accept()
QDialog::accept();
}

void QgsAttributeDialog::show( bool autoDelete )
void QgsAttributeDialog::show()
{
if ( autoDelete )
setAttribute( Qt::WA_DeleteOnClose );

QDialog::show();
raise();
activateWindow();
Expand Down
5 changes: 2 additions & 3 deletions src/gui/qgsattributedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
public slots:
void accept() override;

//! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form and is deleted when
//! closed.
void show( bool autoDelete = true );
//! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form
void show();

private:
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context );
Expand Down

0 comments on commit 9f228d4

Please sign in to comment.