Don't connect to QObject::destroyed directly

Connect to View::beingDestroyed instead.
Decouples more from QObject and allows to remove some asQbject()
calls
This commit is contained in:
Sergio Martins
2022-06-28 20:33:02 +01:00
parent 269e062609
commit 558eef792f
2 changed files with 5 additions and 9 deletions

View File

@@ -176,16 +176,12 @@ int Item::mapFromRoot(int p, Qt::Orientation o) const
void Item::setGuestView(View *guest)
{
Q_ASSERT(!guest || !m_guest);
QObject *newWidget = guest ? guest->asQObject() : nullptr;
QObject *oldWidget = m_guest ? m_guest->asQObject() : nullptr;
if (oldWidget) {
disconnect(oldWidget, nullptr, this, nullptr);
}
m_guest = guest;
m_parentChangedConnection->disconnect();
m_guestDebugNameChangedConnection->disconnect();
m_guestDestroyedConnection->disconnect();
m_layoutInvalidatedConnection->disconnect();
if (m_guest) {
m_guest->setParent(m_hostWidget);
@@ -207,10 +203,8 @@ void Item::setGuestView(View *guest)
}
m_guestDebugNameChangedConnection = m_guest->d->debugNameChanged.connect(&Item::updateObjectName, this);
m_guestDestroyedConnection = m_guest->d->beingDestroyed.connect(&Item::onWidgetDestroyed, this);
connect(newWidget, &QObject::destroyed, this, &Item::onWidgetDestroyed);
m_layoutInvalidatedConnection->disconnect();
m_layoutInvalidatedConnection = guest->d->layoutInvalidated.connect(&Item::onWidgetLayoutRequested, this);
if (m_sizingInfo.geometry.isEmpty()) {
@@ -808,6 +802,7 @@ void Item::onWidgetDestroyed()
m_guest = nullptr;
m_parentChangedConnection->disconnect();
m_guestDebugNameChangedConnection->disconnect();
m_guestDestroyedConnection->disconnect();
if (m_refCount) {
turnIntoPlaceholder();

View File

@@ -394,6 +394,7 @@ private:
KDBindings::ScopedConnection m_layoutInvalidatedConnection;
KDBindings::ScopedConnection m_parentChangedConnection;
KDBindings::ScopedConnection m_guestDebugNameChangedConnection;
KDBindings::ScopedConnection m_guestDestroyedConnection;
};
/// @brief And Item which can contain other Items