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:
@@ -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()";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user