From c32548441d97dcb7dbed5a0a0dffaecdbb45f657 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Tue, 11 Jul 2017 13:49:36 +0100 Subject: [PATCH] Simplify Alternatives Dialog code Summary: Replace QObject::sender() and tracking objects in a list with a simple lambda. Test Plan: Opened and closed dialog. Reviewers: #plasma, mart Reviewed By: #plasma, mart Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D6615 --- shell/shellcorona.cpp | 44 +++++++++++++++---------------------------- shell/shellcorona.h | 2 -- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index cfa949531..72a4a471c 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -38,6 +38,8 @@ #include #include #include +#include + #include #include #include @@ -820,42 +822,26 @@ void ShellCorona::showAlternativesForApplet(Plasma::Applet *applet) AlternativesHelper *helper = new AlternativesHelper(applet, qmlObj); qmlObj->rootContext()->setContextProperty(QStringLiteral("alternativesHelper"), helper); - m_alternativesObjects << qmlObj; qmlObj->completeInitialization(); - connect(qmlObj->rootObject(), SIGNAL(visibleChanged(bool)), - this, SLOT(alternativesVisibilityChanged(bool))); - connect(applet, &Plasma::Applet::destroyedChanged, this, [this, qmlObj] (bool destroyed) { + auto dialog = qobject_cast(qmlObj->rootObject()); + if (!dialog) { + qWarning() << "Alternatives UI does not inherit from Dialog"; + delete qmlObj; + return; + } + connect(applet, &Plasma::Applet::destroyedChanged, qmlObj, [qmlObj] (bool destroyed) { if (!destroyed) { return; } - QMutableListIterator it(m_alternativesObjects); - while (it.hasNext()) { - KDeclarative::QmlObject *obj = it.next(); - if (obj == qmlObj) { - it.remove(); - obj->deleteLater(); - } - } + qmlObj->deleteLater(); }); -} - -void ShellCorona::alternativesVisibilityChanged(bool visible) -{ - if (visible) { - return; - } - - QObject *root = sender(); - - QMutableListIterator it(m_alternativesObjects); - while (it.hasNext()) { - KDeclarative::QmlObject *obj = it.next(); - if (obj->rootObject() == root) { - it.remove(); - obj->deleteLater(); + connect(dialog, &PlasmaQuick::Dialog::visibleChanged, qmlObj, [qmlObj](bool visible) { + if (visible) { + return; } - } + qmlObj->deleteLater(); + }); } void ShellCorona::unload() diff --git a/shell/shellcorona.h b/shell/shellcorona.h index 00690b693..9435ee360 100644 --- a/shell/shellcorona.h +++ b/shell/shellcorona.h @@ -202,7 +202,6 @@ private Q_SLOTS: void panelContainmentDestroyed(QObject* cont); void desktopContainmentDestroyed(QObject*); void showOpenGLNotCompatibleWarning(); - void alternativesVisibilityChanged(bool visible); void interactiveConsoleVisibilityChanged(bool visible); void screenRemoved(QScreen* screen); @@ -242,7 +241,6 @@ private: QMenu *m_addPanelsMenu; KPackage::Package m_lookAndFeelPackage; QSet m_redundantOutputs; - QList m_alternativesObjects; KDeclarative::QmlObject *m_interactiveConsole; QTimer m_waitingPanelsTimer;