Replace deprecated QSignalMapper class

This commit is contained in:
Chocobo1 2019-02-27 16:16:02 +08:00
parent c6ae1aa9d9
commit 3dd969df64
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
4 changed files with 2 additions and 19 deletions

View File

@ -32,7 +32,6 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QMenu> #include <QMenu>
#include <QSignalMapper>
#include <QTimer> #include <QTimer>
#include <libtorrent/session_status.hpp> #include <libtorrent/session_status.hpp>
@ -89,18 +88,13 @@ SpeedWidget::SpeedWidget(PropertiesWidget *parent)
m_graphsMenu->addAction(tr("Tracker Download")); m_graphsMenu->addAction(tr("Tracker Download"));
m_graphsMenuActions = m_graphsMenu->actions(); m_graphsMenuActions = m_graphsMenu->actions();
m_graphsSignalMapper = new QSignalMapper(this);
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) { for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
QAction *action = m_graphsMenuActions.at(id); QAction *action = m_graphsMenuActions.at(id);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(true); action->setChecked(true);
connect(action, &QAction::changed, m_graphsSignalMapper connect(action, &QAction::changed, this, [this, id]() { onGraphChange(id); });
, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
m_graphsSignalMapper->setMapping(action, id);
} }
connect(m_graphsSignalMapper, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped)
, this, &SpeedWidget::onGraphChange);
m_graphsButton = new ComboBoxMenuButton(this, m_graphsMenu); m_graphsButton = new ComboBoxMenuButton(this, m_graphsMenu);
m_graphsButton->addItem(tr("Select Graphs")); m_graphsButton->addItem(tr("Select Graphs"));

View File

@ -38,7 +38,6 @@ class QVBoxLayout;
class QHBoxLayout; class QHBoxLayout;
class QLabel; class QLabel;
class QMenu; class QMenu;
class QSignalMapper;
class PropertiesWidget; class PropertiesWidget;
class ComboBoxMenuButton : public QComboBox class ComboBoxMenuButton : public QComboBox
@ -80,7 +79,6 @@ private:
ComboBoxMenuButton *m_graphsButton; ComboBoxMenuButton *m_graphsButton;
QMenu *m_graphsMenu; QMenu *m_graphsMenu;
QList<QAction *> m_graphsMenuActions; QList<QAction *> m_graphsMenuActions;
QSignalMapper *m_graphsSignalMapper;
}; };
#endif // SPEEDWIDGET_H #endif // SPEEDWIDGET_H

View File

@ -42,7 +42,6 @@
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
#include <QShortcut> #include <QShortcut>
#include <QSignalMapper>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QTextStream> #include <QTextStream>
@ -91,7 +90,6 @@ namespace
SearchWidget::SearchWidget(MainWindow *mainWindow) SearchWidget::SearchWidget(MainWindow *mainWindow)
: QWidget(mainWindow) : QWidget(mainWindow)
, m_ui(new Ui::SearchWidget()) , m_ui(new Ui::SearchWidget())
, m_tabStatusChangedMapper(new QSignalMapper(this))
, m_mainWindow(mainWindow) , m_mainWindow(mainWindow)
, m_isNewQueryString(false) , m_isNewQueryString(false)
{ {
@ -131,9 +129,6 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &SearchWidget::closeTab); connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &SearchWidget::closeTab);
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::tabChanged); connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::tabChanged);
connect(m_tabStatusChangedMapper, static_cast<void (QSignalMapper::*)(QWidget *)>(&QSignalMapper::mapped)
, this, &SearchWidget::tabStatusChanged);
const auto *searchManager = SearchPluginManager::instance(); const auto *searchManager = SearchPluginManager::instance();
const auto onPluginChanged = [this]() const auto onPluginChanged = [this]()
{ {
@ -342,9 +337,7 @@ void SearchWidget::on_searchButton_clicked()
m_ui->tabWidget->setCurrentWidget(newTab); m_ui->tabWidget->setCurrentWidget(newTab);
connect(newTab, &SearchJobWidget::resultsCountUpdated, this, &SearchWidget::resultsCountUpdated); connect(newTab, &SearchJobWidget::resultsCountUpdated, this, &SearchWidget::resultsCountUpdated);
connect(newTab, &SearchJobWidget::statusChanged connect(newTab, &SearchJobWidget::statusChanged, this, [this, &newTab]() { tabStatusChanged(newTab); });
, m_tabStatusChangedMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
m_tabStatusChangedMapper->setMapping(newTab, newTab);
m_ui->searchButton->setText(tr("Stop")); m_ui->searchButton->setText(tr("Stop"));
m_activeSearchTab = newTab; m_activeSearchTab = newTab;

View File

@ -34,7 +34,6 @@
#include <QWidget> #include <QWidget>
class QShortcut; class QShortcut;
class QSignalMapper;
class QTabWidget; class QTabWidget;
class MainWindow; class MainWindow;
@ -81,7 +80,6 @@ private:
QString selectedPlugin() const; QString selectedPlugin() const;
Ui::SearchWidget *m_ui; Ui::SearchWidget *m_ui;
QSignalMapper *m_tabStatusChangedMapper;
QPointer<SearchJobWidget> m_currentSearchTab; // Selected tab QPointer<SearchJobWidget> m_currentSearchTab; // Selected tab
QPointer<SearchJobWidget> m_activeSearchTab; // Tab with running search QPointer<SearchJobWidget> m_activeSearchTab; // Tab with running search
QList<SearchJobWidget *> m_allTabs; // To store all tabs QList<SearchJobWidget *> m_allTabs; // To store all tabs