[KTextWidgets] Port from QRegExp to QRegularExpression
ClosedPublic

Authored by ahmadsamir on Feb 2 2020, 9:38 AM.

Details

Summary

Deprecate the KFind::find() and KReplace::replace() methods that take a
QRegExp; Regular Expression matches will be handled internally if the
KFind::RegularExpression flag is set.

Port QRegExp::setMinimal() by making the regex pattern non-greedy, where
possible.

Test Plan
  • make && ctest
  • a quick test of searching and replacing in ktexteditest still works

Diff Detail

Repository
R310 KTextWidgets
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahmadsamir created this revision.Feb 2 2020, 9:38 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptFeb 2 2020, 9:38 AM
ahmadsamir requested review of this revision.Feb 2 2020, 9:38 AM

A couple of notes:

  • "Incremental" search isn't used by anything in KDE, AFAICS from lxr.kde.org, remove it (in a separate diff)?
  • Nothing in KDE uses the static KFind::find(... QRegExp..) directly; should we make the new one that takes a QRegularExpression private? the same question applies to KReplace::replce(... QRegExp).
ahmadsamir updated this revision to Diff 74871.Feb 2 2020, 7:08 PM
ahmadsamir edited the test plan for this revision. (Show Details)

Add test plan section

dfaure requested changes to this revision.Feb 22 2020, 9:11 AM

OK for deprecating Incremental. A full revert (at KF6 time) of commit 9ac82e27ad0322e444c16 looks tricky though :-)
I searched the git history, and I can't see where we ever used FindIncremental... [I searched kdelibs, since I'm pretty sure this was added for KHTML]

You say that nothing calls find(QRegExp), that's because the find dialog just sets the option RegularExpression, right?
This makes sense actually. I don't see why we have this API. The user uses the dialog and checks a box...
It sounds like we should just deprecate find(QRegExp) and point to the RegularExpression option.
(and make it private, as you said, i.e. move to private class)

src/findreplace/kfind.cpp
759–762

typo: additional 'e' in regeExp

src/findreplace/kfinddialog.cpp
567

I doubt end users want to open Qt API documentation...

This revision now requires changes to proceed.Feb 22 2020, 9:11 AM
ahmadsamir marked an inline comment as done.Feb 25 2020, 3:13 PM

OK for deprecating Incremental. A full revert (at KF6 time) of commit 9ac82e27ad0322e444c16 looks tricky though :-)
I searched the git history, and I can't see where we ever used FindIncremental... [I searched kdelibs, since I'm pretty sure this was added for KHTML]

It's got to be removed at KF6; since it's not actually used, it'll make the code simpler, I think (partial/incremental matching is usually a complex pain).

You say that nothing calls find(QRegExp), that's because the find dialog just sets the option RegularExpression, right?
This makes sense actually. I don't see why we have this API. The user uses the dialog and checks a box...

Yeah, I meant explicitly call Kfind::find() that takes a QRegExp.

It sounds like we should just deprecate find(QRegExp) and point to the RegularExpression option.
(and make it private, as you said, i.e. move to private class)

OK, will do.

src/findreplace/kfinddialog.cpp
567

One alternative is https://perldoc.perl.org/perlre.html :)

I could opt for:
"Invalid PCRE (Perl-compatible regular expressions) pattern syntax" OR
"Invalid PCRE pattern syntax"

then one online search later, the user finds what PCRE is.

Looking at the incremental stuff some more, there are no public methods that mention incremental; the only way is to set the KFind::FindIncremental flag; the only method I could find is in the private API (find_p.h) startNewIncrementalSearch(). So technically it's all hidden behind the d-pointer, there's nothing to deprecate about incremental search, except remove the flag/enum FindIncremental... (does that mean we can remove the incremental code now, or wait till the KF6 branching?).

FWIW, I checked lxr again and KFind::FindIncremental exists only in kmplayer and khtml, and in both cases it's in commented out code.

Deprecate the attribute, keep the code. There is more KF5-based code out there than the one visible by lxr.kde.org. Some of it not even public. We make the same promise as Qt, preserving SC and BC in major versions.

OK for "Invalid PCRE pattern syntax"

ahmadsamir updated this revision to Diff 79373.Apr 5 2020, 4:35 AM
ahmadsamir retitled this revision from Port from QRegExp to QRegularExpression to [KTextWidgets] Port from QRegExp to QRegularExpression.
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)

Update

dfaure accepted this revision.Apr 5 2020, 4:45 PM

Thanks!

This revision is now accepted and ready to land.Apr 5 2020, 4:45 PM

I think I should wait until 5.69 is released before landing, right?

dfaure added a comment.Apr 5 2020, 4:58 PM

It's tagged, you can go ahead.

This revision was automatically updated to reflect the committed changes.

CI doesn't like this commit.

https://build.kde.org/job/Frameworks/job/ktextwidgets/job/kf5-qt5%20SUSEQt5.14/4/testReport/junit/projectroot/autotests/ktextwidgets_kfindtest/

FAIL!  : TestKFind::testStaticFindRegexp(whole words ok) Compared values are not the same
  Actual   (result2)       : 1
  Expected (expectedResult): 9
  Loc: [/home/jenkins/workspace/Frameworks/ktextwidgets/kf5-qt5 SUSEQt5.14/autotests/kfindtest.cpp(242)]

Please check.

I'll look into it.