summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2019-10-01 08:17:50 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2019-10-19 18:00:33 +0000
commit43f26916a5716ddcd2270c513f15a62b183929bb (patch)
tree1c2566d93e39f9e61dafbc8ca7771c501416cf6f
parent0ce522cb43813a2a557c4197e0bc672596080a10 (diff)
Improve QWebEngineFindTextResult APIv5.14.0-beta2
Implements suggestions from 5.14 API review: - Rename activeMatchOrdinal to activeMatch - Extend documentation - Change QML import version number to 1.10 Task-number: QTBUG-77839 Change-Id: I5eae659cfb5355af8d0c878d3b5f00654c9d6d13 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--examples/webengine/quicknanobrowser/BrowserWindow.qml4
-rw-r--r--examples/webengine/quicknanobrowser/FindBar.qml6
-rw-r--r--examples/webenginewidgets/simplebrowser/browserwindow.cpp2
-rw-r--r--src/core/api/qwebenginefindtextresult.cpp24
-rw-r--r--src/core/api/qwebenginefindtextresult.h6
-rw-r--r--src/core/find_text_helper.cpp4
-rw-r--r--src/core/find_text_helper.h2
-rw-r--r--src/webengine/doc/src/webengineview_lgpl.qdoc4
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp2
-rw-r--r--tests/auto/quick/qmltests/data/tst_findText.qml32
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp16
11 files changed, 57 insertions, 45 deletions
diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml
index 39a13df5..2d316838 100644
--- a/examples/webengine/quicknanobrowser/BrowserWindow.qml
+++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml
@@ -57,7 +57,7 @@ import QtQuick.Controls.Styles 1.0
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.0
import QtQuick.Window 2.1
-import QtWebEngine 1.11
+import QtWebEngine 1.10
ApplicationWindow {
id: browserWindow
@@ -580,7 +580,7 @@ ApplicationWindow {
findBar.visible = true;
findBar.numberOfMatches = result.numberOfMatches;
- findBar.activeMatchOrdinal = result.activeMatchOrdinal;
+ findBar.activeMatch = result.activeMatch;
}
onLoadingChanged: function(loadRequest) {
diff --git a/examples/webengine/quicknanobrowser/FindBar.qml b/examples/webengine/quicknanobrowser/FindBar.qml
index 2d673592..de407ac3 100644
--- a/examples/webengine/quicknanobrowser/FindBar.qml
+++ b/examples/webengine/quicknanobrowser/FindBar.qml
@@ -57,12 +57,12 @@ Rectangle {
id: root
property int numberOfMatches: 0
- property int activeMatchOrdinal: 0
+ property int activeMatch: 0
property alias text: findTextField.text
function reset() {
numberOfMatches = 0;
- activeMatchOrdinal = 0;
+ activeMatch = 0;
visible = false;
}
@@ -113,7 +113,7 @@ Rectangle {
}
Label {
- text: activeMatchOrdinal + "/" + numberOfMatches
+ text: activeMatch + "/" + numberOfMatches
visible: findTextField.text != ""
}
diff --git a/examples/webenginewidgets/simplebrowser/browserwindow.cpp b/examples/webenginewidgets/simplebrowser/browserwindow.cpp
index 7b167ded..c1d0ea35 100644
--- a/examples/webenginewidgets/simplebrowser/browserwindow.cpp
+++ b/examples/webenginewidgets/simplebrowser/browserwindow.cpp
@@ -532,7 +532,7 @@ void BrowserWindow::handleFindTextFinished(const QWebEngineFindTextResult &resul
statusBar()->showMessage(tr("\"%1\" not found.").arg(m_lastSearch));
} else {
statusBar()->showMessage(tr("\"%1\" found: %2/%3").arg(m_lastSearch,
- QString::number(result.activeMatchOrdinal()),
+ QString::number(result.activeMatch()),
QString::number(result.numberOfMatches())));
}
}
diff --git a/src/core/api/qwebenginefindtextresult.cpp b/src/core/api/qwebenginefindtextresult.cpp
index ce1be359..c0adc617 100644
--- a/src/core/api/qwebenginefindtextresult.cpp
+++ b/src/core/api/qwebenginefindtextresult.cpp
@@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE
class QWebEngineFindTextResultPrivate : public QSharedData {
public:
int numberOfMatches = 0;
- int activeMatchOrdinal = 0;
+ int activeMatch = 0;
};
/*!
@@ -54,6 +54,18 @@ public:
\inmodule QtWebEngineCore
+ The string search can be initiated by the \l QWebEnginePage::findText() or
+ \l{WebEngineView::findText()}{WebEngineView.findText()} method. The results of the search
+ are highlighted in the view. The details of this result are passed as a
+ QWebEngineFindTextResult object that can be used to show a status message,
+ such as "2 of 2 matches". For example:
+
+ \code
+ QObject::connect(view.page(), &QWebEnginePage::findTextFinished, [](const QWebEngineFindTextResult &result) {
+ qInfo() << result.activeMatch() << "of" << result.numberOfMatches() << "matches";
+ });
+ \endcode
+
Results are passed to the user in the
\l QWebEnginePage::findTextFinished() and
\l{WebEngineView::findTextFinished()}{WebEngineView.findTextFinished()} signals.
@@ -67,11 +79,11 @@ QWebEngineFindTextResult::QWebEngineFindTextResult()
/*! \internal
*/
-QWebEngineFindTextResult::QWebEngineFindTextResult(int numberOfMatches, int activeMatchOrdinal)
+QWebEngineFindTextResult::QWebEngineFindTextResult(int numberOfMatches, int activeMatch)
: d(new QWebEngineFindTextResultPrivate)
{
d->numberOfMatches = numberOfMatches;
- d->activeMatchOrdinal = activeMatchOrdinal;
+ d->activeMatch = activeMatch;
}
/*! \internal
@@ -103,12 +115,12 @@ int QWebEngineFindTextResult::numberOfMatches() const
}
/*!
- \property QWebEngineFindTextResult::activeMatchOrdinal
+ \property QWebEngineFindTextResult::activeMatch
\brief The index of the currently highlighted match.
*/
-int QWebEngineFindTextResult::activeMatchOrdinal() const
+int QWebEngineFindTextResult::activeMatch() const
{
- return d->activeMatchOrdinal;
+ return d->activeMatch;
}
QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginefindtextresult.h b/src/core/api/qwebenginefindtextresult.h
index 073a8135..246e689c 100644
--- a/src/core/api/qwebenginefindtextresult.h
+++ b/src/core/api/qwebenginefindtextresult.h
@@ -55,11 +55,11 @@ class QWebEngineFindTextResultPrivate;
class Q_WEBENGINECORE_EXPORT QWebEngineFindTextResult {
Q_GADGET
Q_PROPERTY(int numberOfMatches READ numberOfMatches CONSTANT FINAL)
- Q_PROPERTY(int activeMatchOrdinal READ activeMatchOrdinal CONSTANT FINAL)
+ Q_PROPERTY(int activeMatch READ activeMatch CONSTANT FINAL)
public:
int numberOfMatches() const;
- int activeMatchOrdinal() const;
+ int activeMatch() const;
QWebEngineFindTextResult();
QWebEngineFindTextResult(const QWebEngineFindTextResult &other);
@@ -67,7 +67,7 @@ public:
~QWebEngineFindTextResult();
private:
- QWebEngineFindTextResult(int numberOfMatches, int activeMatchOrdinal);
+ QWebEngineFindTextResult(int numberOfMatches, int activeMatch);
QSharedDataPointer<QWebEngineFindTextResultPrivate> d;
diff --git a/src/core/find_text_helper.cpp b/src/core/find_text_helper.cpp
index effda529..065fed38 100644
--- a/src/core/find_text_helper.cpp
+++ b/src/core/find_text_helper.cpp
@@ -135,7 +135,7 @@ bool FindTextHelper::isFindTextInProgress() const
}
void FindTextHelper::handleFindReply(content::WebContents *source, int requestId, int numberOfMatches,
- const gfx::Rect &selectionRect, int activeMatchOrdinal, bool finalUpdate)
+ const gfx::Rect &selectionRect, int activeMatch, bool finalUpdate)
{
Q_UNUSED(selectionRect);
@@ -146,7 +146,7 @@ void FindTextHelper::handleFindReply(content::WebContents *source, int requestId
Q_ASSERT(m_currentFindRequestId == requestId);
m_lastCompletedFindRequestId = requestId;
- m_viewClient->findTextFinished(QWebEngineFindTextResult(numberOfMatches, activeMatchOrdinal));
+ m_viewClient->findTextFinished(QWebEngineFindTextResult(numberOfMatches, activeMatch));
invokeResultCallback(requestId, numberOfMatches);
}
diff --git a/src/core/find_text_helper.h b/src/core/find_text_helper.h
index e8f18627..9843dc8b 100644
--- a/src/core/find_text_helper.h
+++ b/src/core/find_text_helper.h
@@ -78,7 +78,7 @@ public:
void startFinding(const QString &findText, bool caseSensitively, bool findBackward);
void stopFinding();
bool isFindTextInProgress() const;
- void handleFindReply(content::WebContents *source, int requestId, int numberOfMatches, const gfx::Rect &selectionRect, int activeMatchOrdinal, bool finalUpdate);
+ void handleFindReply(content::WebContents *source, int requestId, int numberOfMatches, const gfx::Rect &selectionRect, int activeMatch, bool finalUpdate);
void handleLoadCommitted();
private:
diff --git a/src/webengine/doc/src/webengineview_lgpl.qdoc b/src/webengine/doc/src/webengineview_lgpl.qdoc
index 3a7717bd..df956f03 100644
--- a/src/webengine/doc/src/webengineview_lgpl.qdoc
+++ b/src/webengine/doc/src/webengineview_lgpl.qdoc
@@ -1599,7 +1599,7 @@
*/
/*!
- \qmlproperty int FindTextResult::activeMatchOrdinal
+ \qmlproperty int FindTextResult::activeMatch
\readonly
\brief The index of the currently highlighted match.
@@ -1607,7 +1607,7 @@
/*!
\qmlsignal WebEngineView::findTextFinished(FindTextResult result)
- \since QtWebEngine 1.11
+ \since QtWebEngine 1.10
This signal is emitted when a string search on a page is completed. \a result is
the result of the string search.
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index 9f7dfa8a..32197205 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -279,7 +279,7 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineFileDialogRequest.dialogReject() --> void"
<< "QQuickWebEngineFileDialogRequest.mode --> FileMode"
<< "QWebEngineFindTextResult.numberOfMatches --> int"
- << "QWebEngineFindTextResult.activeMatchOrdinal --> int"
+ << "QWebEngineFindTextResult.activeMatch --> int"
<< "QQuickWebEngineFormValidationMessageRequest.Hide --> RequestType"
<< "QQuickWebEngineFormValidationMessageRequest.Move --> RequestType"
<< "QQuickWebEngineFormValidationMessageRequest.Show --> RequestType"
diff --git a/tests/auto/quick/qmltests/data/tst_findText.qml b/tests/auto/quick/qmltests/data/tst_findText.qml
index 040d324e..c02a1348 100644
--- a/tests/auto/quick/qmltests/data/tst_findText.qml
+++ b/tests/auto/quick/qmltests/data/tst_findText.qml
@@ -113,7 +113,7 @@ TestWebEngineView {
verify(!findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1)
}
function test_findTextCaseInsensitive() {
@@ -127,7 +127,7 @@ TestWebEngineView {
verify(!findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1)
}
function test_findTextManyMatches() {
@@ -141,7 +141,7 @@ TestWebEngineView {
verify(!findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 100)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1)
}
@@ -156,7 +156,7 @@ TestWebEngineView {
verify(findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 0)
}
function test_findTextNotFound() {
@@ -170,7 +170,7 @@ TestWebEngineView {
verify(findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 0)
}
function test_findTextAfterNotFound() {
@@ -184,7 +184,7 @@ TestWebEngineView {
verify(findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 0)
webEngineView.url = Qt.resolvedUrl("test1.html")
verify(webEngineView.waitForLoadSucceeded())
@@ -195,7 +195,7 @@ TestWebEngineView {
verify(!findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1)
}
function test_findTextInModifiedDOMAfterNotFound() {
@@ -212,7 +212,7 @@ TestWebEngineView {
verify(findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 0)
runJavaScript("document.body.innerHTML = 'blahellobla'");
tryVerify(function() { return getBodyInnerHTML() == "blahellobla"; }, 20000);
@@ -223,7 +223,7 @@ TestWebEngineView {
verify(!findFailed)
tryCompare(findTextSpy, "count", 1)
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1)
}
function test_findTextInterruptedByLoad() {
@@ -276,7 +276,7 @@ TestWebEngineView {
findTextSpy.wait();
compare(findTextSpy.count, i);
compare(findTextSpy.signalArguments[i-1][0].numberOfMatches, 3);
- compare(findTextSpy.signalArguments[i-1][0].activeMatchOrdinal, i);
+ compare(findTextSpy.signalArguments[i-1][0].activeMatch, i);
}
// The last match is followed by the fist one.
@@ -285,7 +285,7 @@ TestWebEngineView {
findTextSpy.wait();
compare(findTextSpy.count, 1);
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 3);
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1);
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1);
// The first match is preceded by the last one.
webEngineView.clear();
@@ -293,23 +293,23 @@ TestWebEngineView {
findTextSpy.wait();
compare(findTextSpy.count, 1);
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 3);
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 3);
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 3);
- // Finding another word resets the activeMatchOrdinal.
+ // Finding another word resets the activeMatch.
webEngineView.clear();
webEngineView.findText("bar");
findTextSpy.wait();
compare(findTextSpy.count, 1);
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 2);
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1);
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 1);
- // If no match activeMatchOrdinal is 0.
+ // If no match activeMatch is 0.
webEngineView.clear();
webEngineView.findText("bla");
findTextSpy.wait();
compare(findTextSpy.count, 1);
compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0);
- compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0);
+ compare(findTextSpy.signalArguments[0][0].activeMatch, 0);
}
}
}
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 124dc825..1b3295ab 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -999,7 +999,7 @@ void tst_QWebEnginePage::findTextResult()
if (findTextSpy.count() != 1)
return QVector<int>({-1, -1});
auto r = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
- return QVector<int>({ r.numberOfMatches(), r.activeMatchOrdinal() });
+ return QVector<int>({ r.numberOfMatches(), r.activeMatch() });
};
// findText will abort in blink if the view has an empty size.
@@ -1104,7 +1104,7 @@ void tst_QWebEnginePage::findTextActiveMatchOrdinal()
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 3);
- QCOMPARE(result.activeMatchOrdinal(), i);
+ QCOMPARE(result.activeMatch(), i);
}
// The last match is followed by the fist one.
@@ -1112,28 +1112,28 @@ void tst_QWebEnginePage::findTextActiveMatchOrdinal()
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 3);
- QCOMPARE(result.activeMatchOrdinal(), 1);
+ QCOMPARE(result.activeMatch(), 1);
// The first match is preceded by the last one.
m_view->page()->findText("foo", QWebEnginePage::FindBackward);
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 3);
- QCOMPARE(result.activeMatchOrdinal(), 3);
+ QCOMPARE(result.activeMatch(), 3);
- // Finding another word resets the activeMatchOrdinal.
+ // Finding another word resets the activeMatch.
m_view->page()->findText("bar", 0);
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 2);
- QCOMPARE(result.activeMatchOrdinal(), 1);
+ QCOMPARE(result.activeMatch(), 1);
- // If no match activeMatchOrdinal is 0.
+ // If no match activeMatch is 0.
m_view->page()->findText("bla", 0);
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 0);
- QCOMPARE(result.activeMatchOrdinal(), 0);
+ QCOMPARE(result.activeMatch(), 0);
}
static QWindow *findNewTopLevelWindow(const QWindowList &oldTopLevelWindows)