Skip to content

Commit

Permalink
Merge pull request #2427 from Holzhaus/remove-qsignalmapper
Browse files Browse the repository at this point in the history
Replace deprecated QSignalMapper with lambda expressions
  • Loading branch information
daschuer authored Jan 14, 2020
2 parents 629129a + b5c18f3 commit da3c3af
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 492 deletions.
587 changes: 264 additions & 323 deletions src/controllers/controlpickermenu.cpp

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/controllers/controlpickermenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <QMenu>
#include <QObject>
#include <QSignalMapper>

#include "preferences/usersettings.h"

Expand Down Expand Up @@ -31,8 +30,12 @@ class ControlPickerMenu : public QMenu {

private:
QMenu* addSubmenu(QString title, QMenu* pParent=NULL);
void addSingleControl(QString group, QString control,
QString title, QString description,
QMenu* pMenu,
QString prefix=QString(), QString actionTitle=QString());
void addControl(QString group, QString control, QString title,
QString helpText, QMenu* pMenu, bool addReset=false);
QString helpText, QMenu* pMenu, bool addReset=false, QString prefix=QString());
void addPlayerControl(QString control, QString title, QString helpText,
QMenu* pMenu, bool deckControls, bool samplerControls,
bool previewdeckControls, bool addReset=false);
Expand All @@ -55,11 +58,8 @@ class ControlPickerMenu : public QMenu {
QString helpText, QMenu* pMenu,
bool microphoneControls, bool auxControls,
bool addReset=false);
void addPrefixedControl(QString group, QString control, QString title,
QString menuDescription, QString descriptionPrefix,
QMenu* pMenu, bool addReset=false);

void addAvailableControl(ConfigKey key, QString title, QString description);
int addAvailableControl(ConfigKey key, QString title, QString description);

QString m_effectMasterOutputStr;
QString m_effectHeadphoneOutputStr;
Expand All @@ -75,7 +75,6 @@ class ControlPickerMenu : public QMenu {
QString m_parameterStr;
QString m_libraryStr;

QSignalMapper m_actionMapper;
QList<ConfigKey> m_controlsAvailable;
QHash<ConfigKey, QString> m_descriptionsByKey;
QHash<ConfigKey, QString> m_titlesByKey;
Expand Down
10 changes: 3 additions & 7 deletions src/controllers/dlgprefcontrollers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
setupUi(this);
setupControllerWidgets();

connect(&m_buttonMapper, SIGNAL(mapped(QString)),
this, SLOT(slotOpenLocalFile(QString)));

connect(btnOpenUserPresets, SIGNAL(clicked()),
&m_buttonMapper, SLOT(map()));

m_buttonMapper.setMapping(btnOpenUserPresets, userPresetsPath(m_pConfig));
const QString presetsPath = userPresetsPath(m_pConfig);
connect(btnOpenUserPresets, &QPushButton::clicked,
this, [this, presetsPath] { slotOpenLocalFile(presetsPath); });

// Connections
connect(m_pControllerManager, SIGNAL(devicesChanged()),
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/dlgprefcontrollers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define DLGPREFCONTROLLERS_H

#include <QTreeWidgetItem>
#include <QSignalMapper>

#include "preferences/usersettings.h"
#include "controllers/ui_dlgprefcontrollersdlg.h"
Expand Down Expand Up @@ -43,7 +42,6 @@ class DlgPrefControllers : public DlgPreferencePage, public Ui::DlgPrefControlle
QTreeWidgetItem* m_pControllerTreeItem;
QList<DlgPrefController*> m_controllerWindows;
QList<QTreeWidgetItem*> m_controllerTreeItems;
QSignalMapper m_buttonMapper;
};

#endif /* DLGPREFCONTROLLERS_H */
9 changes: 3 additions & 6 deletions src/effects/effectchainslot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ EffectChainSlot::EffectChainSlot(EffectRack* pRack, const QString& group,
connect(m_pControlChainSelector, SIGNAL(valueChanged(double)),
this, SLOT(slotControlChainSelector(double)));

connect(&m_channelStatusMapper, SIGNAL(mapped(const QString&)),
this, SLOT(slotChannelStatusChanged(const QString&)));

// ControlObjects for skin <-> controller mapping interaction.
// Refer to comment in header for full explanation.
m_pControlChainShowFocus = new ControlPushButton(
Expand Down Expand Up @@ -330,9 +327,9 @@ void EffectChainSlot::registerInputChannel(const ChannelHandleAndGroup& handle_g

ChannelInfo* pInfo = new ChannelInfo(handle_group, pEnableControl);
m_channelInfoByName[handle_group.name()] = pInfo;
m_channelStatusMapper.setMapping(pEnableControl, handle_group.name());
connect(pEnableControl, SIGNAL(valueChanged(double)),
&m_channelStatusMapper, SLOT(map()));
connect(pEnableControl, &ControlPushButton::valueChanged,
this, [this, handle_group] { slotChannelStatusChanged(handle_group.name()); });

}

void EffectChainSlot::slotEffectLoaded(EffectPointer pEffect, unsigned int slotNumber) {
Expand Down
2 changes: 0 additions & 2 deletions src/effects/effectchainslot.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QObject>
#include <QMap>
#include <QList>
#include <QSignalMapper>

#include "engine/channelhandle.h"
#include "util/class.h"
Expand Down Expand Up @@ -167,7 +166,6 @@ class EffectChainSlot : public QObject {
QMap<QString, ChannelInfo*> m_channelInfoByName;

QList<EffectSlotPointer> m_slots;
QSignalMapper m_channelStatusMapper;

DISALLOW_COPY_AND_ASSIGN(EffectChainSlot);
};
Expand Down
14 changes: 4 additions & 10 deletions src/errordialoghandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ void ErrorDialogHandler::setEnabled(bool enabled) {
s_bEnabled = enabled;
}

ErrorDialogHandler::ErrorDialogHandler()
: m_signalMapper(this) {
connect(&m_signalMapper, SIGNAL(mapped(QString)),
this, SLOT(boxClosed(QString)));

ErrorDialogHandler::ErrorDialogHandler() {
m_errorCondition = false;
connect(this, SIGNAL(showErrorDialog(ErrorDialogProperties*)),
this, SLOT(errorDialog(ErrorDialogProperties*)));
Expand Down Expand Up @@ -183,9 +179,8 @@ void ErrorDialogHandler::errorDialog(ErrorDialogProperties* pProps) {

// Signal mapper calls our slot with the key parameter so it knows which to
// remove from the list
connect(msgBox, SIGNAL(finished(int)),
&m_signalMapper, SLOT(map()));
m_signalMapper.setMapping(msgBox, props->m_key);
connect(msgBox, &QMessageBox::finished,
this, [this, &props, &msgBox] { boxClosed(props->m_key, msgBox); });

locker.unlock();

Expand All @@ -212,9 +207,8 @@ void ErrorDialogHandler::errorDialog(ErrorDialogProperties* pProps) {
}
}

void ErrorDialogHandler::boxClosed(QString key) {
void ErrorDialogHandler::boxClosed(QString key, QMessageBox* msgBox) {
QMutexLocker locker(&m_mutex);
QMessageBox* msgBox = (QMessageBox*)m_signalMapper.mapping(key);
locker.unlock();

QMessageBox::StandardButton whichStdButton = msgBox->standardButton(msgBox->clickedButton());
Expand Down
4 changes: 1 addition & 3 deletions src/errordialoghandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <QObject>
#include <QMessageBox>
#include <QSignalMapper>
#include <QMutex>
#include <QString>
#include <QList>
Expand Down Expand Up @@ -166,7 +165,7 @@ class ErrorDialogHandler : public QObject {
private slots:
/** Actually displays the box */
void errorDialog(ErrorDialogProperties* props);
void boxClosed(QString key);
void boxClosed(QString key, QMessageBox* msgBox);

private:
// Private constructor
Expand All @@ -177,7 +176,6 @@ class ErrorDialogHandler : public QObject {

bool m_errorCondition;
QList<QString> m_dialogKeys;
QSignalMapper m_signalMapper;
QMutex m_mutex;

DISALLOW_COPY_AND_ASSIGN(ErrorDialogHandler);
Expand Down
11 changes: 3 additions & 8 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,

// Create context-menu items to allow crates to be added to, and removed
// from, the auto-DJ queue.
connect(&m_crateMapper,
QOverload<int>::of(&QSignalMapper::mapped),
this,
&AutoDJFeature::slotAddCrateToAutoDj);
m_pRemoveCrateFromAutoDj = new QAction(tr("Remove Crate as Track Source"), this);
connect(m_pRemoveCrateFromAutoDj,
&QAction::triggered,
Expand Down Expand Up @@ -305,10 +301,9 @@ void AutoDJFeature::onRightClickChild(const QPoint& globalPos,
Crate crate;
while (nonAutoDjCrates.populateNext(&crate)) {
auto pAction = std::make_unique<QAction>(crate.getName(), &crateMenu);
m_crateMapper.setMapping(pAction.get(), crate.getId().value());
connect(pAction.get(),
&QAction::triggered,
[=](bool) { m_crateMapper.map(); });
int iCrateId = crate.getId().value();
connect(pAction.get(), &QAction::triggered,
this, [this, iCrateId] { slotAddCrateToAutoDj(iCrateId); });
crateMenu.addAction(pAction.get());
pAction.release();
}
Expand Down
4 changes: 0 additions & 4 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <QModelIndex>
#include <QPoint>
#include <QAction>
#include <QSignalMapper>
#include <QPointer>

#include "library/libraryfeature.h"
Expand Down Expand Up @@ -89,9 +88,6 @@ class AutoDJFeature : public LibraryFeature {
// auto-DJ list.
QAction *m_pRemoveCrateFromAutoDj;

// Used to map menu-item signals.
QSignalMapper m_crateMapper;

QIcon m_icon;
QPointer<WLibrarySidebar> m_pSidebarWidget;

Expand Down
8 changes: 1 addition & 7 deletions src/vinylcontrol/vinylcontrolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ VinylControlManager::VinylControlManager(QObject* pParent,
pSoundManager->registerInput(
AudioInput(AudioInput::VINYLCONTROL, 0, 2, i), m_pProcessor);
}

connect(&m_vinylControlEnabledMapper,
QOverload<int>::of(&QSignalMapper::mapped),
this,
&VinylControlManager::slotVinylControlEnabledChanged);
}

VinylControlManager::~VinylControlManager() {
Expand Down Expand Up @@ -91,8 +86,7 @@ void VinylControlManager::slotNumDecksChanged(double dNumDecks) {
QString group = PlayerManager::groupForDeck(i);
ControlProxy* pEnabled = new ControlProxy(group, "vinylcontrol_enabled", this);
m_pVcEnabled.push_back(pEnabled);
pEnabled->connectValueChanged(&m_vinylControlEnabledMapper, QOverload<int>::of(&QSignalMapper::mapped));
m_vinylControlEnabledMapper.setMapping(pEnabled, i);
pEnabled->connectValueChanged(this, [this, i] { slotVinylControlEnabledChanged(i); });

// Default cueing should be off.
ControlObject::set(ConfigKey(group, "vinylcontrol_cueing"),
Expand Down
2 changes: 0 additions & 2 deletions src/vinylcontrol/vinylcontrolmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define VINYLCONTROLMANAGER_H

#include <QObject>
#include <QSignalMapper>
#include <QString>
#include <QTimerEvent>

Expand Down Expand Up @@ -73,7 +72,6 @@ class VinylControlManager : public QObject {
QList<ControlProxy*> m_pVcEnabled;
ControlProxy* m_pNumDecks;
int m_iNumConfiguredDecks;
QSignalMapper m_vinylControlEnabledMapper;
};

#endif // VINYLCONTROLMANAGER_H
38 changes: 15 additions & 23 deletions src/widget/wmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ WMainMenuBar::WMainMenuBar(QWidget* pParent, UserSettingsPointer pConfig,
m_pConfig(pConfig),
m_pKbdConfig(pKbdConfig) {
initialize();
connect(&m_loadToDeckMapper, SIGNAL(mapped(int)),
this, SIGNAL(loadTrackToDeck(int)));
connect(&m_visitUrlMapper, SIGNAL(mapped(QString)),
this, SLOT(slotVisitUrl(QString)));
connect(&m_vinylControlEnabledMapper, SIGNAL(mapped(int)),
this, SIGNAL(toggleVinylControl(int)));
}

void WMainMenuBar::initialize() {
Expand Down Expand Up @@ -90,9 +84,9 @@ void WMainMenuBar::initialize() {
// Visibility of load to deck actions is set in
// WMainMenuBar::onNumberOfDecksChanged.
pFileLoadSongToPlayer->setVisible(false);
connect(pFileLoadSongToPlayer, SIGNAL(triggered()),
&m_loadToDeckMapper, SLOT(map()));
m_loadToDeckMapper.setMapping(pFileLoadSongToPlayer, deck + 1);
connect(pFileLoadSongToPlayer, &QAction::triggered,
this, [this, deck] { loadTrackToDeck(deck + 1); });

pFileMenu->addAction(pFileLoadSongToPlayer);
m_loadToDeckActions.push_back(pFileLoadSongToPlayer);
}
Expand Down Expand Up @@ -314,10 +308,8 @@ void WMainMenuBar::initialize() {
vc_checkbox->setStatusTip(vinylControlText);
vc_checkbox->setWhatsThis(buildWhatsThis(vinylControlTitle,
vinylControlText));

m_vinylControlEnabledMapper.setMapping(vc_checkbox, i);
connect(vc_checkbox, SIGNAL(triggered(bool)),
&m_vinylControlEnabledMapper, SLOT(map()));
connect(vc_checkbox, &QAction::triggered,
this, [this, i] { toggleVinylControl(i); });
pVinylControlMenu->addAction(vc_checkbox);
}
pOptionsMenu->addMenu(pVinylControlMenu);
Expand Down Expand Up @@ -508,8 +500,8 @@ void WMainMenuBar::initialize() {
auto pHelpSupport = new QAction(supportTitle, this);
pHelpSupport->setStatusTip(supportText);
pHelpSupport->setWhatsThis(buildWhatsThis(supportTitle, supportText));
m_visitUrlMapper.setMapping(pHelpSupport, MIXXX_SUPPORT_URL);
connect(pHelpSupport, SIGNAL(triggered()), &m_visitUrlMapper, SLOT(map()));
connect(pHelpSupport, &QAction::triggered,
this, [this] { slotVisitUrl(MIXXX_SUPPORT_URL); });
pHelpMenu->addAction(pHelpSupport);

QDir resourceDir(m_pConfig->getResourcePath());
Expand Down Expand Up @@ -539,35 +531,35 @@ void WMainMenuBar::initialize() {
auto pHelpManual = new QAction(manualTitle, this);
pHelpManual->setStatusTip(manualText);
pHelpManual->setWhatsThis(buildWhatsThis(manualTitle, manualText));
m_visitUrlMapper.setMapping(pHelpManual, qManualUrl.toString());
connect(pHelpManual, SIGNAL(triggered()), &m_visitUrlMapper, SLOT(map()));
connect(pHelpManual, &QAction::triggered,
this, [this, qManualUrl] { slotVisitUrl(qManualUrl.toString()); });
pHelpMenu->addAction(pHelpManual);

QString shortcutsTitle = tr("&Keyboard Shortcuts") + externalLinkSuffix;
QString shortcutsText = tr("Speed up your workflow with keyboard shortcuts.");
auto pHelpShortcuts = new QAction(shortcutsTitle, this);
pHelpShortcuts->setStatusTip(shortcutsText);
pHelpShortcuts->setWhatsThis(buildWhatsThis(shortcutsTitle, shortcutsText));
m_visitUrlMapper.setMapping(pHelpShortcuts, MIXXX_SHORTCUTS_URL);
connect(pHelpShortcuts, SIGNAL(triggered()), &m_visitUrlMapper, SLOT(map()));
connect(pHelpShortcuts, &QAction::triggered,
this, [this] { slotVisitUrl(MIXXX_SHORTCUTS_URL); });
pHelpMenu->addAction(pHelpShortcuts);

QString feedbackTitle = tr("Send Us &Feedback") + externalLinkSuffix;
QString feedbackText = tr("Send feedback to the Mixxx team.");
auto pHelpFeedback = new QAction(feedbackTitle, this);
pHelpFeedback->setStatusTip(feedbackText);
pHelpFeedback->setWhatsThis(buildWhatsThis(feedbackTitle, feedbackText));
m_visitUrlMapper.setMapping(pHelpFeedback, MIXXX_FEEDBACK_URL);
connect(pHelpFeedback, SIGNAL(triggered()), &m_visitUrlMapper, SLOT(map()));
connect(pHelpFeedback, &QAction::triggered,
this, [this] { slotVisitUrl(MIXXX_FEEDBACK_URL); });
pHelpMenu->addAction(pHelpFeedback);

QString translateTitle = tr("&Translate This Application") + externalLinkSuffix;
QString translateText = tr("Help translate this application into your language.");
auto pHelpTranslation = new QAction(translateTitle, this);
pHelpTranslation->setStatusTip(translateText);
pHelpTranslation->setWhatsThis(buildWhatsThis(translateTitle, translateText));
m_visitUrlMapper.setMapping(pHelpTranslation, MIXXX_TRANSLATION_URL);
connect(pHelpTranslation, SIGNAL(triggered()), &m_visitUrlMapper, SLOT(map()));
connect(pHelpTranslation, &QAction::triggered,
this, [this] { slotVisitUrl(MIXXX_TRANSLATION_URL); });
pHelpMenu->addAction(pHelpTranslation);

pHelpMenu->addSeparator();
Expand Down
4 changes: 0 additions & 4 deletions src/widget/wmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <QMenuBar>
#include <QObject>
#include <QScopedPointer>
#include <QSignalMapper>

#include "control/controlproxy.h"
#include "preferences/configobject.h"
Expand Down Expand Up @@ -86,10 +85,7 @@ class WMainMenuBar : public QMenuBar {

UserSettingsPointer m_pConfig;
ConfigObject<ConfigValueKbd>* m_pKbdConfig;
QSignalMapper m_loadToDeckMapper;
QSignalMapper m_visitUrlMapper;
QList<QAction*> m_loadToDeckActions;
QSignalMapper m_vinylControlEnabledMapper;
QList<QAction*> m_vinylControlEnabledActions;
};

Expand Down
Loading

0 comments on commit da3c3af

Please sign in to comment.