Add Controller::setParentView()

Controllers need to know when the view changes parent. Until know
they listen to event filter's QEvent::ParentChange, which isn't portable
to non-Qt platforms. Instead, always go through the controller.
Then each controller can override setParentView(), which is virtual,
to intercept parent changes without any Qt specific events.

In a followup will inherit from setParentView() in a few controllers
This commit is contained in:
Sergio Martins
2022-07-19 18:54:45 +01:00
parent d99b842ae1
commit 26acf4dab4
3 changed files with 14 additions and 1 deletions

View File

@@ -124,3 +124,12 @@ void Controller::show() const
{
return view()->show();
}
void Controller::setParentView(View *parent)
{
if (auto v = view()) {
v->setParent(parent);
} else {
qWarning() << Q_FUNC_INFO << "No view()";
}
}

View File

@@ -80,6 +80,10 @@ public:
void show() const;
bool inDtor() const;
/// Sets the parent view
/// In Qt this would be equivalent to calling view()->setParent(parent);
virtual void setParentView(View *parent);
private:
void setParent(QObject *) = delete;
View *m_view = nullptr;

View File

@@ -185,7 +185,7 @@ void Item::setGuestView(View *guest)
m_layoutInvalidatedConnection->disconnect();
if (m_guest) {
m_guest->setParent(m_hostWidget);
m_guest->controller()->setParentView(m_hostWidget);
if (Controllers::Group *group = asGroupController())
group->setLayoutItem(this);