Don't connect to QObject::objectNameChanged

Connect to the view's signal instead.
Decouples a bit more from QObject
This commit is contained in:
Sergio Martins
2022-06-28 20:22:58 +01:00
parent 2eb72114d7
commit 269e062609
4 changed files with 12 additions and 2 deletions

View File

@@ -32,5 +32,9 @@ public:
/// @brief signal emitted when the view's parent has changed
KDBindings::Signal<> parentChanged;
/// @brief signal emitted when the view's debug name has changed
/// Used for debug only
KDBindings::Signal<> debugNameChanged;
};
}

View File

@@ -185,6 +185,7 @@ void Item::setGuestView(View *guest)
m_guest = guest;
m_parentChangedConnection->disconnect();
m_guestDebugNameChangedConnection->disconnect();
if (m_guest) {
m_guest->setParent(m_hostWidget);
@@ -205,7 +206,8 @@ void Item::setGuestView(View *guest)
setMaxSizeHint(guest->maxSizeHint());
}
connect(newWidget, &QObject::objectNameChanged, this, &Item::updateObjectName);
m_guestDebugNameChangedConnection = m_guest->d->debugNameChanged.connect(&Item::updateObjectName, this);
connect(newWidget, &QObject::destroyed, this, &Item::onWidgetDestroyed);
m_layoutInvalidatedConnection->disconnect();
@@ -805,6 +807,7 @@ void Item::onWidgetDestroyed()
{
m_guest = nullptr;
m_parentChangedConnection->disconnect();
m_guestDebugNameChangedConnection->disconnect();
if (m_refCount) {
turnIntoPlaceholder();

View File

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

View File

@@ -55,8 +55,10 @@ QObject *View_qt::thisObject() const
void View_qt::setObjectName(const QString &name)
{
if (m_thisObj)
if (m_thisObj) {
m_thisObj->setObjectName(name);
d->debugNameChanged.emit();
}
}
/*static*/