CollectionFilter: Optimize use of QRegularExpression

Possible fix for #1482
This commit is contained in:
Jonas Kvinge 2024-07-09 22:06:42 +02:00
parent 6417f89596
commit 8327751b91
1 changed files with 8 additions and 10 deletions

View File

@ -64,19 +64,17 @@ bool CollectionFilter::filterAcceptsRow(const int source_row, const QModelIndex
if (filter_text.isEmpty()) return true; if (filter_text.isEmpty()) return true;
filter_text = filter_text.replace(QRegularExpression(QStringLiteral("\\s*:\\s*")), QStringLiteral(":")) for (const QString &foperator : Operators) {
.replace(QRegularExpression(QStringLiteral("\\s*=\\s*")), QStringLiteral("=")) if (filter_text.contains(foperator)) {
.replace(QRegularExpression(QStringLiteral("\\s*==\\s*")), QStringLiteral("==")) QRegularExpression regex(QStringLiteral("\\s*") + foperator + QStringLiteral("\\s*"));
.replace(QRegularExpression(QStringLiteral("\\s*<>\\s*")), QStringLiteral("<>")) filter_text = filter_text.replace(regex, foperator);
.replace(QRegularExpression(QStringLiteral("\\s*<\\s*")), QStringLiteral("<")) }
.replace(QRegularExpression(QStringLiteral("\\s*>\\s*")), QStringLiteral(">")) }
.replace(QRegularExpression(QStringLiteral("\\s*<=\\s*")), QStringLiteral("<="))
.replace(QRegularExpression(QStringLiteral("\\s*>=\\s*")), QStringLiteral(">="));
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
const QStringList tokens = filter_text.split(QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts); const QStringList tokens = filter_text.split(QLatin1Char(' '), Qt::SkipEmptyParts);
#else #else
const QStringList tokens = filter_text.split(QRegularExpression(QStringLiteral("\\s+")), QString::SkipEmptyParts); const QStringList tokens = filter_text.split(QLatin1Char(' '), QString::SkipEmptyParts);
#endif #endif
filter_text.clear(); filter_text.clear();