Skip to content

Commit 1e6b5eb

Browse files
author
Hugo Mercier
committedOct 28, 2016
Don't delete QgsAttributeDialog too early. Fixes #15737
1 parent 032a954 commit 1e6b5eb

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
@@ -100,7 +100,9 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
100100

101101
QgsAttributeDialog *dialog = newDialog( true );
102102
dialog->setHighlight( h );
103-
dialog->show(); // will also delete the dialog on close (show() is overridden)
103+
// delete the dialog when it is closed
104+
dialog->setAttribute( Qt::WA_DeleteOnClose );
105+
dialog->show();
104106

105107
return true;
106108
}
@@ -110,22 +112,27 @@ bool QgsFeatureAction::editFeature( bool showModal )
110112
if ( !mLayer )
111113
return false;
112114

113-
QgsAttributeDialog *dialog = newDialog( false );
114-
115-
if ( !mFeature->isValid() )
116-
dialog->setMode( QgsAttributeForm::AddFeatureMode );
117-
118115
if ( showModal )
119116
{
120-
dialog->setAttribute( Qt::WA_DeleteOnClose );
121-
int rv = dialog->exec();
117+
QScopedPointer<QgsAttributeDialog> dialog( newDialog( false ) );
118+
119+
if ( !mFeature->isValid() )
120+
dialog->setMode( QgsAttributeForm::AddFeatureMode );
122121

122+
int rv = dialog->exec();
123123
mFeature->setAttributes( dialog->feature()->attributes() );
124124
return rv;
125125
}
126126
else
127127
{
128-
dialog->show(); // will also delete the dialog on close (show() is overridden)
128+
QgsAttributeDialog* dialog = newDialog( false );
129+
130+
if ( !mFeature->isValid() )
131+
dialog->setMode( QgsAttributeForm::AddFeatureMode );
132+
133+
// delete the dialog when it is closed
134+
dialog->setAttribute( Qt::WA_DeleteOnClose );
135+
dialog->show();
129136
}
130137

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

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

221-
dialog->setAttribute( Qt::WA_DeleteOnClose );
222230
dialog->exec();
223231
}
224232

‎src/gui/qgsattributedialog.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ void QgsAttributeDialog::accept()
8181
QDialog::accept();
8282
}
8383

84-
void QgsAttributeDialog::show( bool autoDelete )
84+
void QgsAttributeDialog::show()
8585
{
86-
if ( autoDelete )
87-
setAttribute( Qt::WA_DeleteOnClose );
88-
8986
QDialog::show();
9087
raise();
9188
activateWindow();

‎src/gui/qgsattributedialog.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
139139
void accept() override;
140140
void reject() override;
141141

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.