diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-11-10 14:18:12 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-11-11 17:48:50 +0100 |
commit | b7f621ccadbac0f329c773913769e68db5efef38 (patch) | |
tree | 47e6ea1002070d37cdf944d50788ba9f9fc60102 /src/widgets/dialogs/qfiledialog.cpp | |
parent | fb0a96f185464b39a7d4976f45751b98f395cc99 (diff) |
QFileDialog: Decouple nativeDialogInUse from QPlatformDialogHelper
The QDialogPrivate::nativeDialogInUse member is used to track whether
a native dialog will be used down the line when the dialog is shown,
or if a native dialog is actively showing or has been shown once.
The former case applies to QFileDialog and QColorDialog, which both
set nativeDialogInUse based on the result of creating a platform
dialog helper in Q(File|Color)DialogPrivate::init(), and then use
that information to avoid creating a widget hierarchy if not needed.
The latter case applies when the native dialog is attempted to be
shown(), where failure to show the native dialog results in the
nativeDialogInUse member being set to false.
The QFontDialog and QMessageBox subclasses do not rely on the former
mechanism, and will only have nativeDialogInUse set to true if the
native dialog has been actively shown at least once.
The QPlatformDialogHelper on the other hand, tracked by the member
QDialogPrivate::m_platformHelper, does not map 1:1 to the state of
nativeDialogInUse, as in the case of QPlatformFileDialogHelper
there is also functionality in the helper to give hints to the
widget-based non-native dialog on how to behave. As a result,
we can have a valid m_platformHelper, but with nativeDialogInUse
being false.
To decouple this and simplify the code we let QFileDialog::setOption()
reset the nativeDialogInUse based on QDialog::DontUseNativeDialog,
just like QColorDialog does, and let QFileDialogPrivate::createWidgets()
proceed without having to delete the platform helper, which would
otherwise be necessary to reset nativeDialogInUse.
The only side effect of this is that a widget-based non-native
dialog will still have a QPlatformFileDialogHelper alive, but
since this dialog is not going to be shown this should not be
an issue in practice.
Task-number: QTBUG-108153
Change-Id: I96af6cfa715717c0907fe840aa86d4e5b280d54c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/dialogs/qfiledialog.cpp')
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index d301eaa7ea..e2f81c22a1 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -531,7 +531,6 @@ void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h) QObject::connect(h, SIGNAL(directoryEntered(QUrl)), d, SLOT(_q_nativeEnterDirectory(QUrl))); QObject::connect(h, SIGNAL(filterSelected(QString)), d, SIGNAL(filterSelected(QString))); static_cast<QPlatformFileDialogHelper *>(h)->setOptions(options); - nativeDialogInUse = true; } void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) @@ -765,8 +764,10 @@ void QFileDialog::setOptions(Options options) d->options->setOptions(QFileDialogOptions::FileDialogOptions(int(options))); - if ((options & DontUseNativeDialog) && !d->usingWidgets()) + if (options & DontUseNativeDialog) { + d->nativeDialogInUse = false; d->createWidgets(); + } if (d->usingWidgets()) { if (changed & DontResolveSymlinks) @@ -2963,8 +2964,6 @@ void QFileDialogPrivate::createWidgets() model->setNameFilterDisables(helper->defaultNameFilterDisables()); else model->setNameFilterDisables(false); - if (nativeDialogInUse) - deletePlatformHelper(); model->d_func()->disableRecursiveSort = true; QFileDialog::connect(model, SIGNAL(fileRenamed(QString,QString,QString)), q, SLOT(_q_fileRenamed(QString,QString,QString))); QFileDialog::connect(model, SIGNAL(rootPathChanged(QString)), |