summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebenginepage.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-03-08 13:17:40 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-03-30 21:01:17 +0000
commit80ec51d5273e060551a9aa2d4878fee7c0cc1de2 (patch)
tree6ace5a42a4ff4aada5fbae0fd44511d9af5fd9cc /src/webenginewidgets/api/qwebenginepage.cpp
parent6454b6b2d0f2fbb8d140fa2555af7867964748ce (diff)
Make ReplaceMisspelledWord web-actions more generic
Instead of using four numbered web-actions, use a generic method that can be called using the context data. Change-Id: If31c6f572c54d7ecfc7962edea2e27c555e6d79f Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index cb0359195..184b17095 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -1068,18 +1068,28 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
case ToggleSpellcheck:
d->adapter->toogleSpellCheckEnabled();
break;
- case ReplaceMisspelledWord_1:
- case ReplaceMisspelledWord_2:
- case ReplaceMisspelledWord_3:
- case ReplaceMisspelledWord_4:
- d->adapter->replaceMisspelling(d->actions[action]->text());
- break;
#endif
default:
Q_UNREACHABLE();
}
}
+/*!
+ * \since 5.7
+ * Replace the current misspelled word with \a replacement.
+ *
+ * The current misspelled word can be found in QWebEngineContextMenuData::misspelledWord(),
+ * and suggested replacements in QWebEngineContextMenuData::spellCheckerSuggestions().
+ *
+ * \sa contextMenuData(),
+ */
+
+void QWebEnginePage::replaceMisspelledWord(const QString &replacement)
+{
+ Q_D(QWebEnginePage);
+ d->adapter->replaceMisspelling(replacement);
+}
+
void QWebEnginePage::findText(const QString &subString, FindFlags options, const QWebEngineCallback<bool> &resultCallback)
{
Q_D(QWebEnginePage);
@@ -1263,10 +1273,12 @@ QMenu *QWebEnginePage::createStandardContextMenu()
#if !defined(QT_NO_SPELLCHECK)
if (contextMenuData.isEditable && !contextMenuData.spellCheckerSuggestions.isEmpty()) {
+ QPointer<QWebEnginePage> thisRef(this);
for (int i=0; i < contextMenuData.spellCheckerSuggestions.count() && i < 4; i++) {
- int index = ReplaceMisspelledWord_1 + i;
- QAction *action(QWebEnginePage::action(static_cast<QWebEnginePage::WebAction>(index)));
- action->setText(contextMenuData.spellCheckerSuggestions.at(i));
+ QAction *action = new QAction(menu);
+ QString replacement = contextMenuData.spellCheckerSuggestions.at(i);
+ QObject::connect(action, &QAction::triggered, [thisRef, replacement] { if (thisRef) thisRef->replaceMisspelledWord(replacement); });
+ action->setText(replacement);
menu->addAction(action);
}
menu->addSeparator();