From ecaf35b4c5997fb2584203edc1af8e7e47df0075 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 23 Feb 2024 20:20:36 +0100 Subject: [PATCH] Text widgets: document find() behavior with QRegularExpression The various find() overloads that take a QRE *ignore* the case sensitivity option set on the QRE object itself. They instead apply the case sensitivity passed in the flags (see QTextDocument::find). I think it was an historic mishap, but it's too late to change now. Amend the documentation. Change-Id: I526650d89a98777c7bb839b27d2f2e536a43ca4f Pick-to: 6.6 6.5 6.2 5.15 Fixes: QTBUG-88721 Reviewed-by: Samuel Gaist (cherry picked from commit 3ec9331c341767b1430eb2b14df02383226e25e8) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qtextdocument.cpp | 4 ++++ src/widgets/widgets/qplaintextedit.cpp | 7 +++++-- src/widgets/widgets/qtextedit.cpp | 7 +++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index ea0cc27f590..4d5a563e580 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1500,6 +1500,10 @@ static bool findInBlock(const QTextBlock &block, const QRegularExpression &expr, If the \a from position is 0 (the default) the search begins from the beginning of the document; otherwise it begins at the specified position. + + \warning For historical reasons, the case sensitivity option set on + \a expr is ignored. Instead, the \a options are used to determine + if the search is case sensitive or not. */ QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFlags options) const { diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 087b7e4d210..dcba223cb03 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2894,11 +2894,14 @@ bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options) \overload Finds the next occurrence, matching the regular expression, \a exp, using the given - \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload, - use QRegularExpression::CaseInsensitiveOption instead. + \a options. Returns \c true if a match was found and changes the cursor to select the match; otherwise returns \c false. + + \warning For historical reasons, the case sensitivity option set on + \a exp is ignored. Instead, the \a options are used to determine + if the search is case sensitive or not. */ #if QT_CONFIG(regularexpression) bool QPlainTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options) diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 2bc7d06f11a..1a3d0f9e983 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -2593,11 +2593,14 @@ bool QTextEdit::find(const QString &exp, QTextDocument::FindFlags options) \overload Finds the next occurrence, matching the regular expression, \a exp, using the given - \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload, - use QRegularExpression::CaseInsensitiveOption instead. + \a options. Returns \c true if a match was found and changes the cursor to select the match; otherwise returns \c false. + + \warning For historical reasons, the case sensitivity option set on + \a exp is ignored. Instead, the \a options are used to determine + if the search is case sensitive or not. */ #if QT_CONFIG(regularexpression) bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)