Get rid of QSignalMapper

Use lambdas instead.

Differential Revision: https://phabricator.kde.org/D7361
This commit is contained in:
Kai Uwe Broulik 2017-08-18 11:53:10 +02:00
parent cf8ae465e4
commit 1419135a5d
4 changed files with 8 additions and 37 deletions

View File

@ -24,7 +24,6 @@
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QIcon> #include <QIcon>
#include <QSignalMapper>
#include <QTimer> #include <QTimer>
#include <kactioncollection.h> #include <kactioncollection.h>
@ -49,7 +48,6 @@ Q_DECLARE_METATYPE(AppletInterface *)
AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariantList &args, QQuickItem *parent) AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariantList &args, QQuickItem *parent)
: AppletQuickItem(script->applet(), parent), : AppletQuickItem(script->applet(), parent),
m_actionSignals(0),
m_configuration(0), m_configuration(0),
m_appletScriptEngine(script), m_appletScriptEngine(script),
m_toolTipTextFormat(0), m_toolTipTextFormat(0),
@ -450,14 +448,9 @@ void AppletInterface::setAction(const QString &name, const QString &text, const
Q_ASSERT(!m_actions.contains(name)); Q_ASSERT(!m_actions.contains(name));
m_actions.append(name); m_actions.append(name);
if (!m_actionSignals) { connect(action, &QAction::triggered, this, [this, name] {
m_actionSignals = new QSignalMapper(this); executeAction(name);
connect(m_actionSignals, static_cast<void(QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped), });
appletScript(), &DeclarativeAppletScript::executeAction);
}
connect(action, &QAction::triggered, m_actionSignals, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
m_actionSignals->setMapping(action, name);
} }
if (!icon.isEmpty()) { if (!icon.isEmpty()) {
@ -475,15 +468,7 @@ void AppletInterface::removeAction(const QString &name)
{ {
Plasma::Applet *a = applet(); Plasma::Applet *a = applet();
QAction *action = a->actions()->action(name); QAction *action = a->actions()->action(name);
if (action) {
if (m_actionSignals) {
m_actionSignals->removeMappings(action);
}
delete action; delete action;
}
m_actions.removeAll(name); m_actions.removeAll(name);
} }

View File

@ -33,7 +33,6 @@
class QAction; class QAction;
class QmlAppletScript; class QmlAppletScript;
class QSignalMapper;
class QSizeF; class QSizeF;
namespace KDeclarative namespace KDeclarative
@ -454,7 +453,6 @@ private Q_SLOTS:
private: private:
QStringList m_actions; QStringList m_actions;
QSignalMapper *m_actionSignals;
KDeclarative::ConfigPropertyMap *m_configuration; KDeclarative::ConfigPropertyMap *m_configuration;
DeclarativeAppletScript *m_appletScriptEngine; DeclarativeAppletScript *m_appletScriptEngine;

View File

@ -31,7 +31,6 @@
#include <QQmlExpression> #include <QQmlExpression>
#include <QQmlContext> #include <QQmlContext>
#include <QQmlProperty> #include <QQmlProperty>
#include <QSignalMapper>
#include <Plasma/PluginLoader> #include <Plasma/PluginLoader>
#include <kpackage/packageloader.h> #include <kpackage/packageloader.h>
@ -43,8 +42,7 @@ WallpaperInterface::WallpaperInterface(ContainmentInterface *parent)
m_containmentInterface(parent), m_containmentInterface(parent),
m_qmlObject(0), m_qmlObject(0),
m_configuration(0), m_configuration(0),
m_configLoader(0), m_configLoader(0)
m_actionSignals(0)
{ {
m_actions = new KActionCollection(this); m_actions = new KActionCollection(this);
@ -220,13 +218,9 @@ void WallpaperInterface::setAction(const QString &name, const QString &text, con
action = new QAction(text, this); action = new QAction(text, this);
m_actions->addAction(name, action); m_actions->addAction(name, action);
if (!m_actionSignals) { connect(action, &QAction::triggered, this, [this, name] {
m_actionSignals = new QSignalMapper(this); executeAction(name);
connect(m_actionSignals, static_cast<void(QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped), });
this, &WallpaperInterface::executeAction);
}
connect(action, &QAction::triggered, m_actionSignals, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
m_actionSignals->setMapping(action, name);
} }
if (!icon.isEmpty()) { if (!icon.isEmpty()) {
@ -246,11 +240,7 @@ void WallpaperInterface::removeAction(const QString &name)
QAction *action = m_actions->action(name); QAction *action = m_actions->action(name);
if (action) { if (action) {
if (m_actionSignals) {
m_actionSignals->removeMappings(action);
}
m_actions->removeAction(action); m_actions->removeAction(action);
delete action; delete action;
} }
setProperty("contextualActions", QVariant::fromValue(contextualActions())); setProperty("contextualActions", QVariant::fromValue(contextualActions()));

View File

@ -29,7 +29,6 @@ class KConfigLoader;
class KActionCollection; class KActionCollection;
class ContainmentInterface; class ContainmentInterface;
class QSignalMapper;
namespace KDeclarative namespace KDeclarative
{ {
@ -104,7 +103,6 @@ private:
KDeclarative::ConfigPropertyMap *m_configuration; KDeclarative::ConfigPropertyMap *m_configuration;
KConfigLoader *m_configLoader; KConfigLoader *m_configLoader;
KActionCollection *m_actions; KActionCollection *m_actions;
QSignalMapper *m_actionSignals;
static QHash<QObject *, WallpaperInterface *> s_rootObjects; static QHash<QObject *, WallpaperInterface *> s_rootObjects;
}; };