diff --git a/libs/text/styles/KoParagraphStyle.h b/libs/text/styles/KoParagraphStyle.h --- a/libs/text/styles/KoParagraphStyle.h +++ b/libs/text/styles/KoParagraphStyle.h @@ -721,7 +721,6 @@ Q_SIGNALS: - void nameChanged(const QString &newName); void styleApplied(const KoParagraphStyle*) const; private: 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 @@ -54,13 +53,16 @@ #include "FormulaRenderer.h" #include +// this adds const to non-const objects (like std::as_const) +template Q_DECL_CONSTEXPR typename std::add_const::type &koAsConst(T &t) noexcept { return t; } +// prevent rvalue arguments: +template void koAsConst(const T &&) = delete; KoFormulaTool::KoFormulaTool( KoCanvasBase* canvas ) : KoToolBase( canvas ), m_formulaShape( 0 ), m_formulaEditor( 0 ) { - m_signalMapper = new QSignalMapper(this); setupActions(); setTextMode(true); } @@ -114,23 +116,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 : koAsConst(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 : koAsConst(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 +485,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.h b/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.h --- a/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.h +++ b/plugins/textshape/dialogs/SimpleCitationBibliographyWidget.h @@ -31,7 +31,6 @@ class KoBibliographyInfo; class BibliographyPreview; class BibliographyTemplate; -class QSignalMapper; class SimpleCitationBibliographyWidget : public QWidget { @@ -62,7 +61,6 @@ //each template in the template list will have have a previewGenerator that will be deleted after preview is generated QList m_previewGenerator; ItemChooserAction *m_chooser; - QSignalMapper *m_signalMapper; BibliographyTemplate *m_templateGenerator; }; 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.h b/plugins/textshape/dialogs/SimpleParagraphWidget.h --- a/plugins/textshape/dialogs/SimpleParagraphWidget.h +++ b/plugins/textshape/dialogs/SimpleParagraphWidget.h @@ -39,7 +39,6 @@ class DockerStylesComboModel; class StylesDelegate; -class QSignalMapper; namespace Lists {class ListStyleItem;}; class SimpleParagraphWidget : public QWidget 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/plugins/textshape/dialogs/StylesModel.h b/plugins/textshape/dialogs/StylesModel.h --- a/plugins/textshape/dialogs/StylesModel.h +++ b/plugins/textshape/dialogs/StylesModel.h @@ -34,7 +34,6 @@ class KoCharacterStyle; class QImage; -class QSignalMapper; /** This class is used to provide widgets (like the @class StylesCombo) the styles available to the document being worked on. The @class StylesModel can be of two types: character styles or paragraph styles type. This allows the widget to ignore the type of style it is handling. * Character styles in ODF can be specified in two ways. First, a named character style, specifying character formatting properties. It is meant to be used on a couple of individual characters. Secondly, a paragraph style also specifies character formatting properties, which are to be considered the default for that particular paragraph. @@ -165,8 +164,6 @@ KoParagraphStyle *m_currentParagraphStyle; KoCharacterStyle *m_defaultCharacterStyle; - QSignalMapper *m_styleMapper; - bool m_provideStyleNone; }; diff --git a/plugins/textshape/dialogs/StylesModel.cpp b/plugins/textshape/dialogs/StylesModel.cpp --- a/plugins/textshape/dialogs/StylesModel.cpp +++ b/plugins/textshape/dialogs/StylesModel.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -41,7 +40,6 @@ m_styleManager(0), m_currentParagraphStyle(0), m_defaultCharacterStyle(0), - m_styleMapper(new QSignalMapper(this)), m_provideStyleNone(false) { m_modelType = modelType; @@ -55,8 +53,6 @@ m_provideStyleNone = true; } - - connect(m_styleMapper, SIGNAL(mapped(int)), this, SLOT(updateName(int))); } StylesModel::~StylesModel() @@ -321,9 +317,9 @@ ++index; } beginInsertRows(QModelIndex(), index, index); - m_styleList.insert(begin, style->styleId()); - m_styleMapper->setMapping(style, style->styleId()); - connect(style, SIGNAL(nameChanged(QString)), m_styleMapper, SLOT(map())); + int styleId = style->styleId(); + m_styleList.insert(begin, styleId); + connect(style, &KoParagraphStyle::nameChanged, this, [this, styleId] { updateName(styleId); }); endInsertRows(); } @@ -346,9 +342,9 @@ foreach(KoParagraphStyle *style, styles) { if (style != m_styleManager->defaultParagraphStyle()) { //The default character style is not user selectable. It only provides individual property defaults and is not a style per say. - m_styleList.append(style->styleId()); - m_styleMapper->setMapping(style, style->styleId()); - connect(style, SIGNAL(nameChanged(QString)), m_styleMapper, SLOT(map())); + int styleId = style->styleId(); + m_styleList.append(styleId); + connect(style, &KoParagraphStyle::nameChanged, this, [this, styleId] { updateName(styleId); }); } } @@ -382,8 +378,8 @@ beginInsertRows(QModelIndex(), index, index); m_styleList.insert(index, style->styleId()); endInsertRows(); - m_styleMapper->setMapping(style, style->styleId()); - connect(style, SIGNAL(nameChanged(QString)), m_styleMapper, SLOT(map())); + int styleId = style->styleId(); + connect(style, &KoParagraphStyle::nameChanged, this, [this, styleId] (const QString &) { updateName(styleId); }); } bool sortCharacterStyleByName(KoCharacterStyle *style1, KoCharacterStyle *style2) @@ -409,9 +405,9 @@ foreach(KoCharacterStyle *style, styles) { if (style != m_styleManager->defaultCharacterStyle()) { //The default character style is not user selectable. It only provides individual property defaults and is not a style per say. - m_styleList.append(style->styleId()); - m_styleMapper->setMapping(style, style->styleId()); - connect(style, SIGNAL(nameChanged(QString)), m_styleMapper, SLOT(map())); + int styleId = style->styleId(); + m_styleList.append(styleId); + connect(style, &KoParagraphStyle::nameChanged, this, [this, styleId] { updateName(styleId); }); } } @@ -423,8 +419,7 @@ { int row = m_styleList.indexOf(style->styleId()); beginRemoveRows(QModelIndex(), row, row); - m_styleMapper->removeMappings(style); - disconnect(style, SIGNAL(nameChanged(QString)), m_styleMapper, SLOT(map())); + disconnect(style, &KoParagraphStyle::nameChanged, this, nullptr); m_styleList.removeAt(row); endRemoveRows(); } @@ -434,8 +429,7 @@ { int row = m_styleList.indexOf(style->styleId()); beginRemoveRows(QModelIndex(), row, row); - m_styleMapper->removeMappings(style); - disconnect(style, SIGNAL(nameChanged(QString)), m_styleMapper, SLOT(map())); + disconnect(style, &KoParagraphStyle::nameChanged, this, nullptr); m_styleList.removeAt(row); endRemoveRows(); } 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; }; }