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>bb10
parent
fb0a96f185
commit
b7f621ccad
|
|
@ -199,14 +199,6 @@ QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const
|
|||
return QPlatformDialogHelper::defaultStyleHint(hint);
|
||||
}
|
||||
|
||||
void QDialogPrivate::deletePlatformHelper()
|
||||
{
|
||||
delete m_platformHelper;
|
||||
m_platformHelper = nullptr;
|
||||
m_platformHelperCreated = false;
|
||||
nativeDialogInUse = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QDialog
|
||||
\brief The QDialog class is the base class of dialog windows.
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ public:
|
|||
QWindow *transientParentWindow() const;
|
||||
bool setNativeDialogVisible(bool visible);
|
||||
QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const;
|
||||
void deletePlatformHelper();
|
||||
|
||||
#if QT_CONFIG(pushbutton)
|
||||
QPointer<QPushButton> mainDef;
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
Loading…
Reference in New Issue