Port QRegExp to QRegularExpression
ClosedPublic

Authored by ahmadsamir on Dec 24 2019, 6:44 PM.

Details

Summary

Port QRegExp::exactMatch() with QRegularExpression::anchoredPattern().
Port QRegExp::Wildcard with QRegularExpression::wildcardToRegularExpression().
Note that QRegularExpression::wildcardToRegularExpression() returns an anchored
pattern.

Test Plan

Using the filter bar in dolphin works as before.

All unit tests pass, except:

  • kfileitemmodeltest (which is unrelated AFAICS); it fails on master too
  • placesitemmodeltest, which fails on master too

Diff Detail

Repository
R318 Dolphin
Branch
l-qregularexpression (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 22207
Build 22225: arc lint + arc unit
ahmadsamir created this revision.Dec 24 2019, 6:44 PM
Restricted Application added a project: Dolphin. · View Herald TranscriptDec 24 2019, 6:44 PM
ahmadsamir requested review of this revision.Dec 24 2019, 6:44 PM
ahmadsamir planned changes to this revision.Jan 16 2020, 3:10 PM
ahmadsamir updated this revision to Diff 75215.Feb 8 2020, 8:52 AM
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)

Update diff

meven added inline comments.Apr 20 2020, 7:25 AM
src/views/dolphinview.h
191

s/QRegulrExpresssion/QRegularExpresssion

meven added inline comments.Apr 20 2020, 7:26 AM
src/dolphinpart.cpp
510

const

src/views/dolphinview.cpp
375–376

const

ahmadsamir updated this revision to Diff 80623.Apr 20 2020, 8:37 AM

Address comments

I couldn't test the "selection dialog" part as I don't see an Edit -> "Select itmes matching" menu entry in Dolphin.

KFileItemModelFilter still uses QRegExp as there's no equivalent in QRegularExpression
to QRegExp::WildcardUnix.

Is there any plan to fix this upstream in Qt?

src/dolphinpart.cpp
510–511

Please use a single line.

ahmadsamir updated this revision to Diff 80733.Apr 21 2020, 9:14 AM
ahmadsamir marked 3 inline comments as done.

Address comments

KFileItemModelFilter still uses QRegExp as there's no equivalent in QRegularExpression
to QRegExp::WildcardUnix.

Is there any plan to fix this upstream in Qt?

I have no idea. According to QRegExp docs:

In the mode Wildcard, the wildcard characters cannot be escaped. In the mode WildcardUnix, the character '\' escapes the wildcard.

(I am all for using a full regex, it's more predictable).

KFileItemModelFilter still uses QRegExp as there's no equivalent in QRegularExpression
to QRegExp::WildcardUnix.

Is there any plan to fix this upstream in Qt?

I have no idea. According to QRegExp docs:

In the mode Wildcard, the wildcard characters cannot be escaped. In the mode WildcardUnix, the character '\' escapes the wildcard.

(I am all for using a full regex, it's more predictable).

What about QRegularExpression::wildcardToRegularExpression() ? Could we use that? Note that the filter string comes from user input (i.e. from the filter bar).

What about QRegularExpression::wildcardToRegularExpression() ? Could we use that? Note that the filter string comes from user input (i.e. from the filter bar).

I've just tested; it can be used, with the same caveat as the QRegExp docs have about WildcardUnix, a wildcard can't be escaped with a \:
*.txt would show all files with a .txt extension

  • would show all files

\* _won't_ show files with a literal "*" in their names

Looks good enough to me, if you agree I'll update the diff.

What about QRegularExpression::wildcardToRegularExpression() ? Could we use that? Note that the filter string comes from user input (i.e. from the filter bar).

I've just tested; it can be used, with the same caveat as the QRegExp docs have about WildcardUnix, a wildcard can't be escaped with a \:
*.txt would show all files with a .txt extension

  • would show all files \* _won't_ show files with a literal "*" in their names

    Looks good enough to me, if you agree I'll update the diff.

\* doesn't seem to work even now, so go for it.

ahmadsamir updated this revision to Diff 81977.May 5 2020, 8:02 AM
  • Rebase
  • Port the remaining QRegExp to QRegularExpression as dicussed in the review
ahmadsamir updated this revision to Diff 81978.May 5 2020, 8:02 AM
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)

Verbatim

elvisangelaccio accepted this revision.May 5 2020, 10:22 PM

Actually *\* currently works and with this patch won't work anymore, but IMHO this should be fixed in Qt.
QRegExp is deprecated anyway and will probably be removed in Qt 6. Let's get rid of it.

This revision is now accepted and ready to land.May 5 2020, 10:22 PM
This revision was automatically updated to reflect the committed changes.