From 007f92c6eef6191c48da0c44916591d48813ae62 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 15 Aug 2016 10:52:10 +0200 Subject: [PATCH] Dialogs: don't create platform helpers unconditionally No matter if Qt::AA_DontUseNativeDialogs was set, both QFileDialog and QColorDialog were always unconditionally creating the platform helper at construction time: QFooDialog() -> QFooDialogPrivate::init() -> QFooDialogPrivate::platformFooHelper() -> QDialogPrivate::platformHelper() Only QFontDialog had the platformHelper() calls guarded with canBeNativeDialog(). => Move the canBeNativeDialog() check inside QDialogPrivate::platformHelper() where the platform helper instance is created. Task-number: QTBUG-55276 Change-Id: I84b595fbd009c70a3a1976ddbb32a835270c5203 Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qdialog.cpp | 2 +- src/widgets/dialogs/qfiledialog.cpp | 2 +- src/widgets/dialogs/qfontdialog.cpp | 12 ++++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index bfc943966f..8a26e1b2a7 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -95,7 +95,7 @@ QPlatformDialogHelper *QDialogPrivate::platformHelper() const { // Delayed creation of the platform, ensuring that // that qobject_cast<> on the dialog works in the plugin. - if (!m_platformHelperCreated) { + if (!m_platformHelperCreated && canBeNativeDialog()) { m_platformHelperCreated = true; QDialogPrivate *ncThis = const_cast(this); QDialog *dialog = ncThis->q_func(); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index acda6bac3e..bee73c6649 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -2800,7 +2800,7 @@ void QFileDialogPrivate::init(const QUrl &directory, const QString &nameFilter, } q->setAcceptMode(QFileDialog::AcceptOpen); - nativeDialogInUse = (canBeNativeDialog() && platformFileDialogHelper() != 0); + nativeDialogInUse = platformFileDialogHelper() != 0; if (!nativeDialogInUse) createWidgets(); q->setFileMode(QFileDialog::AnyFile); diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index 2a500d3a08..c373bcf1df 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -824,10 +824,8 @@ void QFontDialog::setCurrentFont(const QFont &font) d->strikeout->setChecked(font.strikeOut()); d->underline->setChecked(font.underline()); d->updateFamilies(); - if (d->canBeNativeDialog()) { - if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) - helper->setCurrentFont(font); - } + if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) + helper->setCurrentFont(font); } /*! @@ -840,10 +838,8 @@ void QFontDialog::setCurrentFont(const QFont &font) QFont QFontDialog::currentFont() const { Q_D(const QFontDialog); - if (d->canBeNativeDialog()) { - if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) - return helper->currentFont(); - } + if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) + return helper->currentFont(); return d->sampleEdit->font(); }