From 0d02be6387d8af7e7bdca61e74e17d339afc2a46 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Sun, 1 May 2022 23:00:19 +0100 Subject: [PATCH] qtquick: Implement View::rootView() --- src/qtquick/views/View_qtquick.cpp | 10 ++++++++++ src/qtquick/views/View_qtquick.h | 6 +----- tests/tst_view.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/qtquick/views/View_qtquick.cpp b/src/qtquick/views/View_qtquick.cpp index 059058ec..33523166 100644 --- a/src/qtquick/views/View_qtquick.cpp +++ b/src/qtquick/views/View_qtquick.cpp @@ -11,9 +11,11 @@ #include "View_qtquick.h" #include "private/Utils_p.h" +#include "ViewWrapper_qtquick.h" #include +using namespace KDDockWidgets; using namespace KDDockWidgets::Views; namespace KDDockWidgets::Views { @@ -347,5 +349,13 @@ void View_qtquick::setSize(int w, int h) QQuickItem::setSize(QSizeF(w, h)); } +std::shared_ptr View_qtquick::rootView() const +{ + if (Window::Ptr window = windowHandle()) + return window->rootView(); + + qWarning() << Q_FUNC_INFO << "No window present"; + return {}; +} #include "View_qtquick.moc" diff --git a/src/qtquick/views/View_qtquick.h b/src/qtquick/views/View_qtquick.h index e8a033d8..72350975 100644 --- a/src/qtquick/views/View_qtquick.h +++ b/src/qtquick/views/View_qtquick.h @@ -413,11 +413,7 @@ public: return child ? asQQuickWrapper(child) : nullptr; } - std::shared_ptr rootView() const override - { - return {}; - } - + std::shared_ptr rootView() const override; std::shared_ptr parentView() const override { auto p = QQuickItem::parentItem(); diff --git a/tests/tst_view.cpp b/tests/tst_view.cpp index aa344970..65780423 100644 --- a/tests/tst_view.cpp +++ b/tests/tst_view.cpp @@ -68,14 +68,16 @@ TEST_CASE("View::setParent()") delete rootView2; } -TEST_CASE("View::windowHandle(),Window::rootView()") +TEST_CASE("View::windowHandle,rootView,Window::rootView") { auto rootView = Platform::instance()->tests_createView(); - auto childView = Platform::instance()->tests_createView(false, rootView); + auto childView = Platform::instance()->tests_createView(true, rootView); auto window = rootView->windowHandle(); REQUIRE(window); CHECK_EQ(window->handle(), childView->windowHandle()->handle()); + CHECK(rootView->rootView()->equals(rootView)); + CHECK(childView->rootView()->equals(rootView)); REQUIRE(window->rootView()); CHECK(window->rootView()->equals(rootView));