Skip to content

Commit 9f228d4

Browse files
author
Hugo Mercier
committedOct 28, 2016
Don't delete QgsAttributeDialog too early. Fixes #15737
(cherry picked from commit 9ecdf61)
1 parent 66a213b commit 9f228d4

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed
 

‎src/app/qgsfeatureaction.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
9898

9999
QgsAttributeDialog *dialog = newDialog( true );
100100
dialog->setHighlight( h );
101-
dialog->show(); // will also delete the dialog on close (show() is overridden)
101+
// delete the dialog when it is closed
102+
dialog->setAttribute( Qt::WA_DeleteOnClose );
103+
dialog->show();
102104

103105
return true;
104106
}
@@ -108,24 +110,29 @@ bool QgsFeatureAction::editFeature( bool showModal )
108110
if ( !mLayer )
109111
return false;
110112

111-
QgsAttributeDialog *dialog = newDialog( false );
112-
113-
if ( !mFeature->isValid() )
114-
dialog->setIsAddDialog( true );
115-
116113
if ( showModal )
117114
{
118-
dialog->setAttribute( Qt::WA_DeleteOnClose );
119-
int rv = dialog->exec();
115+
QScopedPointer<QgsAttributeDialog> dialog( newDialog( false ) );
116+
117+
if ( !mFeature->isValid() )
118+
dialog->setIsAddDialog( true );
120119

120+
int rv = dialog->exec();
121121
mFeature->setAttributes( dialog->feature()->attributes() );
122122
return rv;
123123
}
124124
else
125125
{
126-
dialog->show(); // will also delete the dialog on close (show() is overridden)
127-
}
126+
QgsAttributeDialog* dialog = newDialog( false );
127+
128+
if ( !mFeature->isValid() )
129+
dialog->setIsAddDialog( true );
128130

131+
// delete the dialog when it is closed
132+
dialog->setAttribute( Qt::WA_DeleteOnClose );
133+
dialog->show();
134+
}
135+
129136
return true;
130137
}
131138

@@ -193,6 +200,8 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
193200
else
194201
{
195202
QgsAttributeDialog *dialog = newDialog( false );
203+
// delete the dialog when it is closed
204+
dialog->setAttribute( Qt::WA_DeleteOnClose );
196205
dialog->setIsAddDialog( true );
197206
dialog->setEditCommandMessage( text() );
198207

@@ -201,12 +210,11 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
201210
if ( !showModal )
202211
{
203212
setParent( dialog ); // keep dialog until the dialog is closed and destructed
204-
dialog->show(); // will also delete the dialog on close (show() is overridden)
213+
dialog->show();
205214
mFeature = nullptr;
206215
return true;
207216
}
208217

209-
dialog->setAttribute( Qt::WA_DeleteOnClose );
210218
dialog->exec();
211219
}
212220

‎src/gui/qgsattributedialog.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ void QgsAttributeDialog::accept()
8787
QDialog::accept();
8888
}
8989

90-
void QgsAttributeDialog::show( bool autoDelete )
90+
void QgsAttributeDialog::show()
9191
{
92-
if ( autoDelete )
93-
setAttribute( Qt::WA_DeleteOnClose );
94-
9592
QDialog::show();
9693
raise();
9794
activateWindow();

‎src/gui/qgsattributedialog.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
130130
public slots:
131131
void accept() override;
132132

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.