From fb8639969c66bafeeda6e9ec474bc15e26b9bbad Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Fri, 27 May 2022 13:25:06 +0100 Subject: [PATCH] Delete QObject::setParent() in the controller To find places where we're setting parent on the controller instead of in the view. Fix such case where the dock widget view wasn't being parented to the frame view. --- src/Controller.h | 1 + src/controllers/DockWidget.cpp | 5 +++-- src/controllers/MainWindow.cpp | 2 +- src/qtquick/views/Frame_qtquick.cpp | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Controller.h b/src/Controller.h index 57729fe8..24468863 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -81,6 +81,7 @@ public: bool inDtor() const; private: + void setParent(QObject *) = delete; View *m_view = nullptr; bool m_inDtor = false; const Type m_type; diff --git a/src/controllers/DockWidget.cpp b/src/controllers/DockWidget.cpp index 67daf13e..53adb8a7 100644 --- a/src/controllers/DockWidget.cpp +++ b/src/controllers/DockWidget.cpp @@ -112,7 +112,7 @@ void DockWidget::addDockWidgetAsTab(DockWidget *other, InitialOption option) } } - other->setParent(nullptr); + other->view()->setParent(nullptr); frame->addWidget(other, option); } @@ -384,6 +384,7 @@ QStringList DockWidget::affinities() const void DockWidget::show() { + // TODOv2: show wont be called. move to view instead. if (view()->isRootView() && (d->m_lastPosition->wasFloating() || !d->m_lastPosition->isValid())) { // Create the FloatingWindow already, instead of waiting for the show event. // This reduces flickering on some platforms @@ -734,7 +735,7 @@ void DockWidget::Private::close() // Do some cleaning. Widget is hidden, but we must hide the tab containing it. if (Controllers::Frame *frame = this->frame()) { - q->setParent(nullptr); + q->QObject::setParent(nullptr); q->view()->setParent(nullptr); frame->removeWidget(q); diff --git a/src/controllers/MainWindow.cpp b/src/controllers/MainWindow.cpp index 12a4ae34..8675eb71 100644 --- a/src/controllers/MainWindow.cpp +++ b/src/controllers/MainWindow.cpp @@ -586,7 +586,7 @@ void MainWindow::clearSideBarOverlay(bool deleteFrame) frame->unoverlay(); if (deleteFrame) { - d->m_overlayedDockWidget->setParent(nullptr); + d->m_overlayedDockWidget->QObject::setParent(nullptr); d->m_overlayedDockWidget->view()->setParent(nullptr); Q_EMIT d->m_overlayedDockWidget->isOverlayedChanged(false); d->m_overlayedDockWidget = nullptr; diff --git a/src/qtquick/views/Frame_qtquick.cpp b/src/qtquick/views/Frame_qtquick.cpp index 7ad03fb5..14cd2544 100644 --- a/src/qtquick/views/Frame_qtquick.cpp +++ b/src/qtquick/views/Frame_qtquick.cpp @@ -142,7 +142,8 @@ void Frame_qtquick::insertDockWidget_impl(Controllers::DockWidget *dw, int index { QPointer oldFrame = dw->d->frame(); if (stackView()->insertDockWidget(index, dw, {}, {})) { - dw->setParent(m_stackLayout); + + asView_qtquick(dw->view())->setParent(m_stackLayout); QMetaObject::Connection conn = connect(dw, &Controllers::DockWidget::parentChanged, this, [dw, this] { if (dw->parent() != m_stackLayout)