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

View File

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

View File

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

View File

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