diff options
author | Balazs Egedi <egedib@inf.u-szeged.hu> | 2021-07-09 16:58:24 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-10 05:17:31 +0000 |
commit | 36ef2b73fb5b8ba75ec0926dc3ffde2f0487c5d5 (patch) | |
tree | 3896d1495aa1b9da02ba087c55745c33a13258ad | |
parent | 297d086de02ff1babe792b96e02cb760f7a26a0e (diff) |
Reintroduce File Picker control
- Using FileDialog from QuickDialogs2
- Enabled the UIDelegates test
Task-number: QTBUG-93666
Change-Id: I8438a2498e864bc93abf26f2527d7883ac26ca9b
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
(cherry picked from commit 47d57eaa2756a108ae28d9e6226577fe66868cee)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/webengine/customdialogs/doc/images/customdialogs-file1.png | bin | 0 -> 18540 bytes | |||
-rw-r--r-- | examples/webengine/customdialogs/doc/src/customdialogs.qdoc | 6 | ||||
-rw-r--r-- | src/core/file_picker_controller.cpp | 4 | ||||
-rw-r--r-- | src/core/file_picker_controller.h | 3 | ||||
-rw-r--r-- | src/webenginequick/ui/FilePicker.qml | 16 | ||||
-rw-r--r-- | tests/auto/quick/uidelegates/tst_uidelegates.cpp | 6 |
6 files changed, 17 insertions, 18 deletions
diff --git a/examples/webengine/customdialogs/doc/images/customdialogs-file1.png b/examples/webengine/customdialogs/doc/images/customdialogs-file1.png Binary files differnew file mode 100644 index 000000000..5023ced6f --- /dev/null +++ b/examples/webengine/customdialogs/doc/images/customdialogs-file1.png 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() "<input type='file' id='filePicker'/>" "</body></html>"); 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<QObject *>(filePickerStr)); + QTRY_VERIFY(view->findChild<QObject *>(QStringLiteral("fileDialog"))); } void tst_UIDelegates::contextMenu() |