diff --git a/libs/widgets/KoDialog.cpp b/libs/widgets/KoDialog.cpp --- a/libs/widgets/KoDialog.cpp +++ b/libs/widgets/KoDialog.cpp @@ -157,10 +157,8 @@ mButtonBox->addButton(button, role); mButtonList.insert(key, button); - mButtonSignalMapper.setMapping(button, key); - QObject::connect(button, SIGNAL(clicked()), - &mButtonSignalMapper, SLOT(map())); + QObject::connect(button, &QPushButton::clicked, [this, key] { q_ptr->slotButtonClicked(key); }); if (key == mDefaultButton) { // Now that it exists, set it as default @@ -177,8 +175,6 @@ q->setButtons(KoDialog::Ok | KoDialog::Cancel); q->setDefaultButton(KoDialog::Ok); - q->connect(&mButtonSignalMapper, SIGNAL(mapped(int)), q, SLOT(slotButtonClicked(int))); - q->setPlainCaption(qApp->applicationDisplayName()); // set appropriate initial window title for case it gets not set later } diff --git a/libs/widgets/KoDialog_p.h b/libs/widgets/KoDialog_p.h --- a/libs/widgets/KoDialog_p.h +++ b/libs/widgets/KoDialog_p.h @@ -22,7 +22,6 @@ #include "KoDialog.h" #include -#include #include #include @@ -76,7 +75,6 @@ QDialogButtonBox *mButtonBox; QHash mButtonList; - QSignalMapper mButtonSignalMapper; protected Q_SLOTS: void queuedLayoutUpdate(); diff --git a/plugins/formulashape/KoFormulaTool.h b/plugins/formulashape/KoFormulaTool.h --- a/plugins/formulashape/KoFormulaTool.h +++ b/plugins/formulashape/KoFormulaTool.h @@ -26,7 +26,11 @@ class KoFormulaShape; class FormulaEditor; class FormulaCommand; -class QSignalMapper; + +struct TemplateAction { + QAction *action; + QString data; +}; /** * @short The flake tool for a formula @@ -122,7 +126,7 @@ QList m_cursorList; - QSignalMapper* m_signalMapper; + std::vector m_templateActions; }; #endif diff --git a/plugins/formulashape/KoFormulaTool.cpp b/plugins/formulashape/KoFormulaTool.cpp --- a/plugins/formulashape/KoFormulaTool.cpp +++ b/plugins/formulashape/KoFormulaTool.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -60,7 +59,6 @@ m_formulaShape( 0 ), m_formulaEditor( 0 ) { - m_signalMapper = new QSignalMapper(this); setupActions(); setTextMode(true); } @@ -114,23 +112,25 @@ m_formulaEditor = new FormulaEditor( m_formulaShape->formulaData()); } connect(m_formulaShape->formulaData(), SIGNAL(dataChanged(FormulaCommand*,bool)), this, SLOT(updateCursor(FormulaCommand*,bool))); - connect(m_signalMapper, SIGNAL(mapped(QString)), this, SLOT(insert(QString))); + for (const TemplateAction &templateAction : qAsConst(m_templateActions)) { + connect(templateAction.action, &QAction::triggered, this, [this, templateAction] { insert(templateAction.data); }); + } //Only for debugging: connect(action("write_elementTree"),SIGNAL(triggered(bool)), m_formulaShape->formulaData(), SLOT(writeElementTree())); } void KoFormulaTool::deactivate() { + for (const TemplateAction &templateAction : qAsConst(m_templateActions)) { + disconnect(templateAction.action, &QAction::triggered, this, nullptr); + } disconnect(m_formulaShape->formulaData(),0,this,0); - disconnect(m_signalMapper,0,this,0); if (canvas()) { m_cursorList.append(m_formulaEditor); debugFormula << "Appending cursor"; } if (m_cursorList.count() > 20) { // don't let it grow indefinitely - //TODO: is this save? - delete m_cursorList[0]; - m_cursorList.removeAt(0); + delete m_cursorList.takeAt(0); } m_formulaShape = 0; } @@ -481,12 +481,11 @@ void KoFormulaTool::addTemplateAction(const QString &caption, const QString &name, const QString &data, const char *iconName) { - QAction * action; - action = new QAction( caption, this ); - m_signalMapper->setMapping(action, data); - addAction( name , action ); + QAction *action = new QAction( caption, this ); + addAction(name , action); action->setIcon(QIcon::fromTheme(QLatin1String(iconName))); - connect( action, SIGNAL(triggered()), m_signalMapper, SLOT(map())); + m_templateActions.push_back(TemplateAction { action, data }); + // the connection takes place when this KoToolBase is activated } diff --git a/plugins/textediting/spellcheck/SpellCheckMenu.h b/plugins/textediting/spellcheck/SpellCheckMenu.h --- a/plugins/textediting/spellcheck/SpellCheckMenu.h +++ b/plugins/textediting/spellcheck/SpellCheckMenu.h @@ -30,7 +30,6 @@ class QAction; class QAction; class QMenu; -class QSignalMapper; class SpellCheck; class SpellCheckMenu : public QObject @@ -63,7 +62,6 @@ QAction *m_addToDictionaryAction; QMenu *m_suggestionsMenu; int m_lengthMisspelled; - QSignalMapper *m_suggestionsSignalMapper; int m_currentMisspelledPosition; QString m_currentMisspelled; QStringList m_suggestions; diff --git a/plugins/textediting/spellcheck/SpellCheckMenu.cpp b/plugins/textediting/spellcheck/SpellCheckMenu.cpp --- a/plugins/textediting/spellcheck/SpellCheckMenu.cpp +++ b/plugins/textediting/spellcheck/SpellCheckMenu.cpp @@ -27,7 +27,6 @@ #include #include -#include SpellCheckMenu::SpellCheckMenu(const Sonnet::Speller &speller, SpellCheck *spellCheck) : QObject(spellCheck), @@ -37,7 +36,6 @@ m_ignoreWordAction(0), m_addToDictionaryAction(0), m_suggestionsMenu(0), - m_suggestionsSignalMapper(new QSignalMapper(this)), m_currentMisspelledPosition(-1) { m_suggestionsMenuAction = new KActionMenu(i18n("Spelling"), this); @@ -55,9 +53,6 @@ // m_ignoreWordAction = new QAction(i18n("Ignore Word"), this); // connect(m_ignoreWordAction, SIGNAL(triggered()), this, SLOT(ignoreWord())); - connect(m_suggestionsSignalMapper, SIGNAL(mapped(QString)), - this, SLOT(replaceWord(QString))); - setEnabled(false); setVisible(false); } @@ -85,8 +80,7 @@ for (int i = 0; i < m_suggestions.count(); ++i) { const QString &suggestion = m_suggestions.at(i); QAction *action = new QAction(suggestion, m_suggestionsMenu); - connect(action, SIGNAL(triggered()), m_suggestionsSignalMapper, SLOT(map())); - m_suggestionsSignalMapper->setMapping(action, suggestion); + connect(action, &QAction::triggered, [this, suggestion] { replaceWord(suggestion); }); m_suggestionsMenu->addAction(action); } } diff --git a/plugins/textshape/TextTool.cpp b/plugins/textshape/TextTool.cpp --- a/plugins/textshape/TextTool.cpp +++ b/plugins/textshape/TextTool.cpp @@ -91,7 +91,6 @@ #include #include #include -#include #include #include #include @@ -184,16 +183,13 @@ } // setup the context list. - QSignalMapper *signalMapper = new QSignalMapper(this); - connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(startTextEditingPlugin(QString))); QList list; list.append(this->action("format_font")); foreach (const QString &key, KoTextEditingRegistry::instance()->keys()) { KoTextEditingFactory *factory = KoTextEditingRegistry::instance()->value(key); if (factory && factory->showInMenu()) { QAction *a = new QAction(factory->title(), this); - connect(a, SIGNAL(triggered()), signalMapper, SLOT(map())); - signalMapper->setMapping(a, factory->id()); + connect(a, &QAction::triggered, [this, factory] { startTextEditingPlugin(factory->id()); }); list.append(a); addAction(QString("apply_%1").arg(factory->id()), a); } diff --git a/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.cpp b/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.cpp --- a/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.cpp +++ b/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.cpp @@ -28,13 +28,11 @@ #include #include -#include SimpleCitationBibliographyWidget::SimpleCitationBibliographyWidget(ReferencesTool *tool, QWidget *parent) : QWidget(parent), m_blockSignals(false), - m_referenceTool(tool), - m_signalMapper(0) + m_referenceTool(tool) { widget.setupUi(this); Q_ASSERT(tool); @@ -66,29 +64,20 @@ void SimpleCitationBibliographyWidget::prepareTemplateMenu() { m_previewGenerator.clear(); - if (m_signalMapper) { - delete m_signalMapper; - m_signalMapper = 0; - } qDeleteAll(m_templateList.begin(), m_templateList.end()); m_templateList.clear(); - m_signalMapper = new QSignalMapper(); - m_templateList = m_templateGenerator->templates(); - connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(pixmapReady(int))); - m_chooser = widget.addBibliography->addItemChooser(1); int index = 0; foreach (KoBibliographyInfo *info, m_templateList) { BibliographyPreview *preview = new BibliographyPreview(); preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); preview->setPreviewSize(QSize(200,120)); preview->updatePreview(info); - connect(preview, SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); - m_signalMapper->setMapping(preview, index); + connect(preview, &BibliographyPreview::pixmapGenerated, [this, index] { pixmapReady(index); }); m_previewGenerator.append(preview); ++index; @@ -118,7 +107,7 @@ { // +1 to the templateId is because formattingButton does not allow id = 0 widget.addBibliography->addItem(m_chooser, m_previewGenerator.at(templateId)->previewPixmap(), templateId + 1); - disconnect(m_previewGenerator.at(templateId), SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); + disconnect(m_previewGenerator.at(templateId), &BibliographyPreview::pixmapGenerated, this, nullptr); m_previewGenerator.at(templateId)->deleteLater(); } diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp --- a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp +++ b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp @@ -62,7 +62,6 @@ #include #include #include -#include #include diff --git a/plugins/textshape/dialogs/SimpleTableOfContentsWidget.h b/plugins/textshape/dialogs/SimpleTableOfContentsWidget.h --- a/plugins/textshape/dialogs/SimpleTableOfContentsWidget.h +++ b/plugins/textshape/dialogs/SimpleTableOfContentsWidget.h @@ -30,7 +30,6 @@ class KoStyleManager; class KoTableOfContentsGeneratorInfo; class TableOfContentsPreview; -class QSignalMapper; class TableOfContentsTemplate; class SimpleTableOfContentsWidget : public QWidget @@ -62,7 +61,6 @@ QList m_previewGenerator; ItemChooserAction *m_chooser; ReferencesTool *m_referenceTool; - QSignalMapper *m_signalMapper; TableOfContentsTemplate *m_templateGenerator; }; diff --git a/plugins/textshape/dialogs/SimpleTableOfContentsWidget.cpp b/plugins/textshape/dialogs/SimpleTableOfContentsWidget.cpp --- a/plugins/textshape/dialogs/SimpleTableOfContentsWidget.cpp +++ b/plugins/textshape/dialogs/SimpleTableOfContentsWidget.cpp @@ -32,13 +32,11 @@ #include #include -#include SimpleTableOfContentsWidget::SimpleTableOfContentsWidget(ReferencesTool *tool, QWidget *parent) : QWidget(parent), m_blockSignals(false), - m_referenceTool(tool), - m_signalMapper(0) + m_referenceTool(tool) { widget.setupUi(this); Q_ASSERT(tool); @@ -64,29 +62,20 @@ void SimpleTableOfContentsWidget::prepareTemplateMenu() { m_previewGenerator.clear(); - if (m_signalMapper) { - delete m_signalMapper; - m_signalMapper = 0; - } qDeleteAll(m_templateList.begin(), m_templateList.end()); m_templateList.clear(); - m_signalMapper = new QSignalMapper(); - m_templateList = m_templateGenerator->templates(); - connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(pixmapReady(int))); - m_chooser = widget.addToC->addItemChooser(1); int index = 0; foreach (KoTableOfContentsGeneratorInfo *info, m_templateList) { TableOfContentsPreview *preview = new TableOfContentsPreview(); preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); preview->setPreviewSize(QSize(200,120)); preview->updatePreview(info); - connect(preview, SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); - m_signalMapper->setMapping(preview, index); + connect(preview, &TableOfContentsPreview::pixmapGenerated, this, [this, index] { pixmapReady(index); }); m_previewGenerator.append(preview); ++index; @@ -109,7 +98,7 @@ { // +1 to the templateId is because formattingButton does not allow id = 0 widget.addToC->addItem(m_chooser, m_previewGenerator.at(templateId)->previewPixmap(), templateId + 1); - disconnect(m_previewGenerator.at(templateId), SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); + disconnect(m_previewGenerator.at(templateId), &TableOfContentsPreview::pixmapGenerated, this, nullptr); m_previewGenerator.at(templateId)->deleteLater(); } diff --git a/words/plugins/scripting/Tool.h b/words/plugins/scripting/Tool.h --- a/words/plugins/scripting/Tool.h +++ b/words/plugins/scripting/Tool.h @@ -22,7 +22,6 @@ #ifndef SCRIPTING_TOOL_H #define SCRIPTING_TOOL_H -#include #include #include @@ -65,13 +64,11 @@ KoCanvasBase* c = v ? v->canvasBase() : 0; m_toolproxy = c ? c->toolProxy() : 0; - m_signalMapper = new QSignalMapper(this); QHash actionhash = actions(); for (QHash::const_iterator it = actionhash.constBegin(); it != actionhash.constEnd(); ++it) { - connect(it.value(), SIGNAL(triggered()), m_signalMapper, SLOT(map())); - m_signalMapper->setMapping(it.value() , it.key()); + QString key = it.key(); + connect(it.value(), &QAction::triggered, this, [this, key] { actionTriggered(key); }); } - connect(m_signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(actionTriggered(QString))); connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)), this, SIGNAL(changedTool())); } @@ -155,7 +152,6 @@ private: Module* m_module; KoToolProxy* m_toolproxy; - QSignalMapper* m_signalMapper; }; }