Skip to content

Save window geometry of several dialogs

Igor Kushnir requested to merge work/save-dialog-window-geometry into master

Each of the touched dialogs can use extra space. Remember user's resizing and moving of a dialog, because its customized size is likely to be preferable to the default size the next time the dialog is shown.

The added utility can be easily applied to other dialogs if needed.

Cannot use KWindowConfig::saveWindowSize() in place of QWidget::saveGeometry(), because the former takes a QWindow* parameter, but QWindow* QWidget::windowHandle() returns nullptr for each dialog affected by this commit.

Connect saving geometry to QDialog::finished rather than QObject::destroyed signal to be on the safe side. Besides the finished signal, the added utility KDevelop::restoreAndAutoSaveGeometry() uses only QWidget API. Connecting to QObject::destroyed signal instead would make the utility applicable to non-dialog widgets and therefore more universal. However, connecting to the destroyed signal only happens to work in Qt 5 because widget objects emit this signal in ~QWidget() instead of ~QObject(). Relying on this only indirectly documented Qt behavior is too risky for my liking. Besides, top-level widgets that do not inherit from QDialog might return non-null from QWidget::windowHandle(), and so use KWindowConfig::saveWindowSize() instead of QWidget::saveGeometry().

Another downside of connecting saving geometry to QDialog::finished is that this signal is not emitted in some circumstances. Quote from the documentation for QDialog::finished():

Note that this signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible.

Fortunately, the finished signal is normally emitted in practice. All the affected dialogs, except for VCS History, are shown via exec(), which makes them modal. Therefore, currently the only way to exit KDevelop normally while not saving a dialog's geometry is to open the VCS History dialog and quit KDevelop without closing the dialog first. This downside is unfortunate, but I don't know how to safely eliminate it without significantly complicating usage of the added utility by requiring the dialogs to invoke saving geometry from their destructors.

Edited by Igor Kushnir

Merge request reports