qtquick: Implement View::rootView()

This commit is contained in:
Sergio Martins
2022-05-01 23:00:19 +01:00
parent fff3adf967
commit 0d02be6387
3 changed files with 15 additions and 7 deletions

View File

@@ -11,9 +11,11 @@
#include "View_qtquick.h"
#include "private/Utils_p.h"
#include "ViewWrapper_qtquick.h"
#include <QGuiApplication>
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<ViewWrapper> View_qtquick::rootView() const
{
if (Window::Ptr window = windowHandle())
return window->rootView();
qWarning() << Q_FUNC_INFO << "No window present";
return {};
}
#include "View_qtquick.moc"

View File

@@ -413,11 +413,7 @@ public:
return child ? asQQuickWrapper(child) : nullptr;
}
std::shared_ptr<ViewWrapper> rootView() const override
{
return {};
}
std::shared_ptr<ViewWrapper> rootView() const override;
std::shared_ptr<ViewWrapper> parentView() const override
{
auto p = QQuickItem::parentItem();

View File

@@ -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));