Skip to content

Commit 9ecdf61

Browse files
author
Hugo Mercier
committedOct 28, 2016
Don't delete QgsAttributeDialog too early. Fixes #15737
1 parent ea2e68b commit 9ecdf61

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed
 

‎src/app/qgsfeatureaction.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
102102

103103
QgsAttributeDialog *dialog = newDialog( true );
104104
dialog->setHighlight( h );
105-
dialog->show(); // will also delete the dialog on close (show() is overridden)
105+
// delete the dialog when it is closed
106+
dialog->setAttribute( Qt::WA_DeleteOnClose );
107+
dialog->show();
106108

107109
return true;
108110
}
@@ -112,22 +114,27 @@ bool QgsFeatureAction::editFeature( bool showModal )
112114
if ( !mLayer )
113115
return false;
114116

115-
QgsAttributeDialog *dialog = newDialog( false );
116-
117-
if ( !mFeature->isValid() )
118-
dialog->setMode( QgsAttributeForm::AddFeatureMode );
119-
120117
if ( showModal )
121118
{
122-
dialog->setAttribute( Qt::WA_DeleteOnClose );
123-
int rv = dialog->exec();
119+
QScopedPointer<QgsAttributeDialog> dialog( newDialog( false ) );
120+
121+
if ( !mFeature->isValid() )
122+
dialog->setMode( QgsAttributeForm::AddFeatureMode );
124123

124+
int rv = dialog->exec();
125125
mFeature->setAttributes( dialog->feature()->attributes() );
126126
return rv;
127127
}
128128
else
129129
{
130-
dialog->show(); // will also delete the dialog on close (show() is overridden)
130+
QgsAttributeDialog* dialog = newDialog( false );
131+
132+
if ( !mFeature->isValid() )
133+
dialog->setMode( QgsAttributeForm::AddFeatureMode );
134+
135+
// delete the dialog when it is closed
136+
dialog->setAttribute( Qt::WA_DeleteOnClose );
137+
dialog->show();
131138
}
132139

133140
return true;
@@ -204,6 +211,8 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
204211
else
205212
{
206213
QgsAttributeDialog *dialog = newDialog( false );
214+
// delete the dialog when it is closed
215+
dialog->setAttribute( Qt::WA_DeleteOnClose );
207216
dialog->setMode( QgsAttributeForm::AddFeatureMode );
208217
dialog->setEditCommandMessage( text() );
209218

@@ -212,12 +221,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
212221
if ( !showModal )
213222
{
214223
setParent( dialog ); // keep dialog until the dialog is closed and destructed
215-
dialog->show(); // will also delete the dialog on close (show() is overridden)
224+
dialog->show();
216225
mFeature = nullptr;
217226
return true;
218227
}
219228

220-
dialog->setAttribute( Qt::WA_DeleteOnClose );
221229
dialog->exec();
222230
}
223231

‎src/gui/qgsattributedialog.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ void QgsAttributeDialog::accept()
6969
QDialog::accept();
7070
}
7171

72-
void QgsAttributeDialog::show( bool autoDelete )
72+
void QgsAttributeDialog::show()
7373
{
74-
if ( autoDelete )
75-
setAttribute( Qt::WA_DeleteOnClose );
76-
7774
QDialog::show();
7875
raise();
7976
activateWindow();

‎src/gui/qgsattributedialog.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
106106
void accept() override;
107107
void reject() override;
108108

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

113112
private:
114113
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons );

0 commit comments

Comments
 (0)
Please sign in to comment.