diff --git a/addons/close-except-like/close_except_plugin.h b/addons/close-except-like/close_except_plugin.h --- a/addons/close-except-like/close_except_plugin.h +++ b/addons/close-except-like/close_except_plugin.h @@ -37,7 +37,6 @@ # include # include # include -# include # include # include # include @@ -79,31 +78,31 @@ void displayMessage(const QString&, const QString&, KTextEditor::Message::MessageType); void connectToDocument(KTextEditor::Document*); void updateMenu(); - QPointer updateMenu( + using CloseFunction = void (CloseExceptPluginView::*)(const QString &); + void updateMenu( const std::set& , const std::set& , actions_map_type& , KActionMenu* + , CloseFunction ); void appendActionsFrom( const std::set& , actions_map_type& , KActionMenu* - , QSignalMapper* + , CloseFunction ); void appendActionsFrom( const std::set& masks , actions_map_type& actions , KActionMenu* menu - , QSignalMapper* mapper + , CloseFunction ); CloseExceptPlugin* m_plugin; QPointer m_show_confirmation_action; QPointer m_except_menu; QPointer m_like_menu; - QPointer m_except_mapper; - QPointer m_like_mapper; actions_map_type m_except_actions; actions_map_type m_like_actions; KTextEditor::MainWindow *m_mainWindow; diff --git a/addons/close-except-like/close_except_plugin.cpp b/addons/close-except-like/close_except_plugin.cpp --- a/addons/close-except-like/close_except_plugin.cpp +++ b/addons/close-except-like/close_except_plugin.cpp @@ -161,44 +161,42 @@ const std::set& paths , actions_map_type& actions , KActionMenu* menu - , QSignalMapper* mapper + , CloseFunction closeFunction ) { Q_FOREACH(const QUrl& path, paths) { QString action = path.path() + QLatin1Char('*'); actions[action] = QPointer(new QAction(action, menu)); menu->addAction(actions[action]); - //connect(actions[action], &QAction::triggered, mapper, &QSignalMapper::map); connect(actions[action].data(), &QAction::triggered, - mapper, static_cast(&QSignalMapper::map)); - mapper->setMapping(actions[action], action); + this, [this, closeFunction, action]() { (this->*closeFunction)(action); }); } } void CloseExceptPluginView::appendActionsFrom( const std::set& masks , actions_map_type& actions , KActionMenu* menu - , QSignalMapper* mapper + , CloseFunction closeFunction ) { Q_FOREACH(const QString& mask, masks) { QString action = mask.startsWith(QLatin1Char('*')) ? mask : mask + QLatin1Char('*'); actions[action] = QPointer(new QAction(action, menu)); menu->addAction(actions[action]); connect(actions[action].data(), &QAction::triggered, - mapper, static_cast(&QSignalMapper::map)); - mapper->setMapping(actions[action], action); + this, [this, closeFunction, action]() { (this->*closeFunction)(action); }); } } -QPointer CloseExceptPluginView::updateMenu( +void CloseExceptPluginView::updateMenu( const std::set& paths , const std::set& masks , actions_map_type& actions , KActionMenu* menu + , CloseFunction closeFunction ) { // turn menu ON or OFF depending on collected results @@ -211,18 +209,16 @@ actions.erase(it++); } // Form a new one - QPointer mapper = QPointer(new QSignalMapper(this)); - appendActionsFrom(paths, actions, menu, mapper); + appendActionsFrom(paths, actions, menu, closeFunction); if (!masks.empty()) { if (!paths.empty()) menu->addSeparator(); // Add separator between paths and file's ext filters - appendActionsFrom(masks, actions, menu, mapper); + appendActionsFrom(masks, actions, menu, closeFunction); } // Append 'Show Confirmation' toggle menu item menu->addSeparator(); // Add separator between paths and show confirmation menu->addAction(m_show_confirmation_action); - return mapper; } void CloseExceptPluginView::updateMenu() @@ -275,12 +271,8 @@ } qDebug() << "stage #2: Collected" << paths.size() << "paths and" << masks.size() << "masks"; // - m_except_mapper = updateMenu(paths, masks, m_except_actions, m_except_menu); - m_like_mapper = updateMenu(paths, masks, m_like_actions, m_like_menu); - connect(m_except_mapper.data(), static_cast(&QSignalMapper::mapped), - this, &CloseExceptPluginView::closeExcept); - connect(m_like_mapper.data(), static_cast(&QSignalMapper::mapped), - this, &CloseExceptPluginView::closeLike); + updateMenu(paths, masks, m_except_actions, m_except_menu, &CloseExceptPluginView::closeExcept); + updateMenu(paths, masks, m_like_actions, m_like_menu, &CloseExceptPluginView::closeLike); } }