Skip to content

Commit 38c2eeb

Browse files
committed
Attribute dialog: save/restore window geometry
Fix #8784
1 parent b3bda8b commit 38c2eeb

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/gui/qgsattributedialog.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ QgsAttributeDialog::~QgsAttributeDialog()
6060
delete mHighlight;
6161
}
6262

63-
saveGeometry();
6463
delete mDialog;
6564
}
6665

@@ -116,6 +115,7 @@ void QgsAttributeDialog::show()
116115
mDialog->raise();
117116
mDialog->activateWindow();
118117
mDialog->installEventFilter( this );
118+
setParent( mDialog );
119119
}
120120
}
121121

@@ -141,6 +141,12 @@ bool QgsAttributeDialog::eventFilter( QObject* obj, QEvent* e )
141141
return false;
142142
}
143143

144+
void QgsAttributeDialog::onDialogFinished( int result )
145+
{
146+
Q_UNUSED( result )
147+
saveGeometry();
148+
}
149+
144150
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, QgsAttributeEditorContext& context, QWidget* parent )
145151
{
146152
mDialog = new QDialog( parent );
@@ -152,4 +158,6 @@ void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, QgsAt
152158
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
153159
connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( reject() ) );
154160
connect( buttonBox, SIGNAL( accepted() ), mDialog, SLOT( accept() ) );
161+
connect( mDialog, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
162+
restoreGeometry();
155163
}

src/gui/qgsattributedialog.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsattributeform.h"
2323

2424
#include <QDialog>
25+
#include <QPointer>
2526

2627
class QLayout;
2728

@@ -114,16 +115,25 @@ class GUI_EXPORT QgsAttributeDialog : public QObject
114115
public slots:
115116
void accept();
116117

118+
//! Show the dialog and block the application until the dialog is closed. Ownership of this object is not changed.
117119
int exec();
120+
121+
//! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form and is deleted when
122+
//! closed.
118123
void show();
119124

120125
protected:
121126
bool eventFilter( QObject *obj, QEvent *e );
122127

128+
private slots:
129+
void onDialogFinished( int result );
130+
123131
private:
124132
void init( QgsVectorLayer* layer, QgsFeature* feature, QgsAttributeEditorContext& context, QWidget* parent );
125133

126-
QDialog *mDialog;
134+
// Using a guarded pointer we can savely delete the dialog in the destructor even
135+
// when the dialog is this object's parent
136+
QPointer<QDialog> mDialog;
127137
QString mSettingsPath;
128138
// Used to sync multiple widgets for the same field
129139
QgsHighlight *mHighlight;

0 commit comments

Comments
 (0)