From 36ef2b73fb5b8ba75ec0926dc3ffde2f0487c5d5 Mon Sep 17 00:00:00 2001 From: Balazs Egedi Date: Fri, 9 Jul 2021 16:58:24 +0200 Subject: Reintroduce File Picker control - Using FileDialog from QuickDialogs2 - Enabled the UIDelegates test Task-number: QTBUG-93666 Change-Id: I8438a2498e864bc93abf26f2527d7883ac26ca9b Reviewed-by: Michal Klocek (cherry picked from commit 47d57eaa2756a108ae28d9e6226577fe66868cee) Reviewed-by: Qt Cherry-pick Bot --- .../customdialogs/doc/images/customdialogs-file1.png | Bin 0 -> 18540 bytes .../webengine/customdialogs/doc/src/customdialogs.qdoc | 6 +++--- src/core/file_picker_controller.cpp | 4 ++++ src/core/file_picker_controller.h | 3 +++ src/webenginequick/ui/FilePicker.qml | 16 +++++----------- tests/auto/quick/uidelegates/tst_uidelegates.cpp | 6 ++---- 6 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 examples/webengine/customdialogs/doc/images/customdialogs-file1.png diff --git a/examples/webengine/customdialogs/doc/images/customdialogs-file1.png b/examples/webengine/customdialogs/doc/images/customdialogs-file1.png new file mode 100644 index 000000000..5023ced6f Binary files /dev/null and b/examples/webengine/customdialogs/doc/images/customdialogs-file1.png differ diff --git a/examples/webengine/customdialogs/doc/src/customdialogs.qdoc b/examples/webengine/customdialogs/doc/src/customdialogs.qdoc index a07c92153..15207904b 100644 --- a/examples/webengine/customdialogs/doc/src/customdialogs.qdoc +++ b/examples/webengine/customdialogs/doc/src/customdialogs.qdoc @@ -294,7 +294,7 @@ \section2 File Dialog Requests - Currently, Qt WebEngine does not provide File Dialog, a custom dialog should be implemented. + \image customdialogs-file1.png \l [QML]{FileDialogRequest} is a request object that is passed as a parameter of the WebEngineView::fileDialogRequested signal: @@ -309,8 +309,8 @@ \printuntil } We use the \c onFileDialogRequested signal handler to check whether - we should use the default file picker dialog (which currently is not provided). - If not, we accept the request and switch the view to show the \c FilePickerForm: + we should use the default file picker dialog. If not, we accept the request + and switch the view to show the \c FilePickerForm: \image customdialogs-file2.png diff --git a/src/core/file_picker_controller.cpp b/src/core/file_picker_controller.cpp index 537a01508..051b877a4 100644 --- a/src/core/file_picker_controller.cpp +++ b/src/core/file_picker_controller.cpp @@ -92,6 +92,9 @@ FilePickerController::FilePickerController(FilePickerControllerPrivate *priv, QO FilePickerController::~FilePickerController() { + if (!m_isHandled) { + rejected(); + } delete d_ptr; } @@ -241,6 +244,7 @@ void FilePickerController::filesSelectedInChooser(const QStringList &filesList) else d_ptr->fileSystemAccessDialogListener->MultiFilesSelected(files, nullptr); } + m_isHandled = true; } QStringList FilePickerController::acceptedMimeTypes() const diff --git a/src/core/file_picker_controller.h b/src/core/file_picker_controller.h index bba0bae37..ec3b5ba1d 100644 --- a/src/core/file_picker_controller.h +++ b/src/core/file_picker_controller.h @@ -85,6 +85,9 @@ public Q_SLOTS: private: void filesSelectedInChooser(const QStringList &filesList); FilePickerControllerPrivate *d_ptr; + // Using Quick, the FileSelectListenerImpl destructor may crash in debug mode + // if the browser window is closed and the FilePicker is still open + bool m_isHandled = false; }; } // namespace QtWebEngineCore diff --git a/src/webenginequick/ui/FilePicker.qml b/src/webenginequick/ui/FilePicker.qml index e6c4e2598..e84ff2265 100644 --- a/src/webenginequick/ui/FilePicker.qml +++ b/src/webenginequick/ui/FilePicker.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -37,21 +37,15 @@ ** ****************************************************************************/ -/* -import QtQuick.Dialogs 1.1 +import QtQuick.Dialogs FileDialog { + id: fileDialog + objectName: "fileDialog" signal filesSelected(var fileList) onAccepted: { - filesSelected(fileUrls); + filesSelected(selectedFiles) } } -*/ - -import QtQuick.Controls - -Dialog { - // TODO -} diff --git a/tests/auto/quick/uidelegates/tst_uidelegates.cpp b/tests/auto/quick/uidelegates/tst_uidelegates.cpp index 31ce3401a..4c2fa3b3c 100644 --- a/tests/auto/quick/uidelegates/tst_uidelegates.cpp +++ b/tests/auto/quick/uidelegates/tst_uidelegates.cpp @@ -143,7 +143,6 @@ void tst_UIDelegates::javaScriptDialog() void tst_UIDelegates::fileDialog() { - QSKIP("There is no FilePicker Control in Quick Controls 2."); m_window->show(); QTRY_VERIFY(qApp->focusObject()); QQuickWebEngineView *view = webEngineView(); @@ -152,11 +151,10 @@ void tst_UIDelegates::fileDialog() "" ""); QVERIFY(waitForLoadSucceeded(view)); - QString filePickerStr = QStringLiteral("filePicker"); - QPoint filePickerCenter = elementCenter(view, filePickerStr); + QPoint filePickerCenter = elementCenter(view, QStringLiteral("filePicker")); QTest::mouseClick(view->window(), Qt::LeftButton, {}, filePickerCenter); - QTRY_VERIFY(view->findChild(filePickerStr)); + QTRY_VERIFY(view->findChild(QStringLiteral("fileDialog"))); } void tst_UIDelegates::contextMenu() -- cgit v1.2.3