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
wilder-5.14
David Edmundson 9 years ago
parent e3bbe82ebf
commit c32548441d
  1. 44
      shell/shellcorona.cpp
  2. 2
      shell/shellcorona.h

@ -38,6 +38,8 @@
#include <klocalizedstring.h> #include <klocalizedstring.h>
#include <Plasma/Package> #include <Plasma/Package>
#include <Plasma/PluginLoader> #include <Plasma/PluginLoader>
#include <PlasmaQuick/Dialog>
#include <kactivities/controller.h> #include <kactivities/controller.h>
#include <kactivities/consumer.h> #include <kactivities/consumer.h>
#include <ksycoca.h> #include <ksycoca.h>
@ -820,42 +822,26 @@ void ShellCorona::showAlternativesForApplet(Plasma::Applet *applet)
AlternativesHelper *helper = new AlternativesHelper(applet, qmlObj); AlternativesHelper *helper = new AlternativesHelper(applet, qmlObj);
qmlObj->rootContext()->setContextProperty(QStringLiteral("alternativesHelper"), helper); qmlObj->rootContext()->setContextProperty(QStringLiteral("alternativesHelper"), helper);
m_alternativesObjects << qmlObj;
qmlObj->completeInitialization(); 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<PlasmaQuick::Dialog*>(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) { if (!destroyed) {
return; return;
} }
QMutableListIterator<KDeclarative::QmlObject *> it(m_alternativesObjects); qmlObj->deleteLater();
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
if (obj == qmlObj) {
it.remove();
obj->deleteLater();
}
}
}); });
} connect(dialog, &PlasmaQuick::Dialog::visibleChanged, qmlObj, [qmlObj](bool visible) {
if (visible) {
void ShellCorona::alternativesVisibilityChanged(bool visible) return;
{
if (visible) {
return;
}
QObject *root = sender();
QMutableListIterator<KDeclarative::QmlObject *> it(m_alternativesObjects);
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
if (obj->rootObject() == root) {
it.remove();
obj->deleteLater();
} }
} qmlObj->deleteLater();
});
} }
void ShellCorona::unload() void ShellCorona::unload()

@ -202,7 +202,6 @@ private Q_SLOTS:
void panelContainmentDestroyed(QObject* cont); void panelContainmentDestroyed(QObject* cont);
void desktopContainmentDestroyed(QObject*); void desktopContainmentDestroyed(QObject*);
void showOpenGLNotCompatibleWarning(); void showOpenGLNotCompatibleWarning();
void alternativesVisibilityChanged(bool visible);
void interactiveConsoleVisibilityChanged(bool visible); void interactiveConsoleVisibilityChanged(bool visible);
void screenRemoved(QScreen* screen); void screenRemoved(QScreen* screen);
@ -242,7 +241,6 @@ private:
QMenu *m_addPanelsMenu; QMenu *m_addPanelsMenu;
KPackage::Package m_lookAndFeelPackage; KPackage::Package m_lookAndFeelPackage;
QSet<QScreen*> m_redundantOutputs; QSet<QScreen*> m_redundantOutputs;
QList<KDeclarative::QmlObject *> m_alternativesObjects;
KDeclarative::QmlObject *m_interactiveConsole; KDeclarative::QmlObject *m_interactiveConsole;
QTimer m_waitingPanelsTimer; QTimer m_waitingPanelsTimer;

Loading…
Cancel
Save