From 41e66ea6daa47d940365a458e7a12977bb32c690 Mon Sep 17 00:00:00 2001
From: Shawn Rutledge <shawn.rutledge@digia.com>
Date: Thu, 30 Oct 2014 15:29:13 +0100
Subject: [PATCH] Dialogs: FileDialog can only be modal on Windows

The autotest has been failing on Windows because of this.

Change-Id: I6ec42a256455d7a71a522fa7e75dc44f93b741ea
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
---
 src/dialogs/qquickplatformfiledialog.cpp | 15 +++++++++++++++
 src/dialogs/qquickplatformfiledialog_p.h |  1 +
 tests/auto/dialogs/tst_dialogs.cpp       |  4 ++++
 3 files changed, 20 insertions(+)

diff --git a/src/dialogs/qquickplatformfiledialog.cpp b/src/dialogs/qquickplatformfiledialog.cpp
index 7ed4e3fbc..141f701d1 100644
--- a/src/dialogs/qquickplatformfiledialog.cpp
+++ b/src/dialogs/qquickplatformfiledialog.cpp
@@ -172,6 +172,21 @@ QQuickPlatformFileDialog::~QQuickPlatformFileDialog()
     delete m_dlgHelper;
 }
 
+void QQuickPlatformFileDialog::setModality(Qt::WindowModality m)
+{
+#ifdef Q_OS_WIN
+    // A non-modal native file dialog is not possible on Windows, so
+    // be stubborn about it.  Emit modalityChanged() whether it changed
+    // or not, to ensure that anything which depends on the property
+    // will re-read the actual current value.
+    if (m != Qt::ApplicationModal)
+        m = Qt::ApplicationModal;
+    if (m == m_modality)
+        emit modalityChanged();
+#endif
+    QQuickAbstractFileDialog::setModality(m);
+}
+
 QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper()
 {
     QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
diff --git a/src/dialogs/qquickplatformfiledialog_p.h b/src/dialogs/qquickplatformfiledialog_p.h
index 411a78242..f21d01406 100644
--- a/src/dialogs/qquickplatformfiledialog_p.h
+++ b/src/dialogs/qquickplatformfiledialog_p.h
@@ -56,6 +56,7 @@ class QQuickPlatformFileDialog : public QQuickAbstractFileDialog
 public:
     QQuickPlatformFileDialog(QObject *parent = 0);
     virtual ~QQuickPlatformFileDialog();
+    virtual void setModality(Qt::WindowModality m) Q_DECL_OVERRIDE;
 
 protected:
     QPlatformFileDialogHelper *helper();
diff --git a/tests/auto/dialogs/tst_dialogs.cpp b/tests/auto/dialogs/tst_dialogs.cpp
index 34af7e0c0..acf04c5c1 100644
--- a/tests/auto/dialogs/tst_dialogs.cpp
+++ b/tests/auto/dialogs/tst_dialogs.cpp
@@ -124,7 +124,11 @@ void tst_dialogs::fileDialogNonModal()
     QTest::mouseClick(window, Qt::LeftButton, 0, QPoint(1000, 100));  // hide
     QTRY_VERIFY(spyVisibilityChanged.count() > visibilityChangedCount);
     QCOMPARE(dlg->property("visible").toBool(), false);
+#ifdef Q_OS_WIN
+    QCOMPARE(dlg->property("modality").toInt(), (int)Qt::ApplicationModal);
+#else
     QCOMPARE(dlg->property("modality").toInt(), (int)Qt::NonModal);
+#endif
 }
 
 void tst_dialogs::fileDialogNameFilters()
-- 
GitLab