Use QRegularExpression instead of deprecated QRegExp

Now it follows closely the definition of wildcard for glob patterns.
The backslash (\) character is not an escape char in this context.
In order to match one of the special characters, place it in square
brackets (for example, [?]).
This commit is contained in:
Vladimir Golovnev (Glassez)
2021-03-14 18:11:23 +03:00
parent ea1c4a8fc8
commit 61d2ff359b
11 changed files with 53 additions and 32 deletions

View File

@@ -825,7 +825,8 @@ void PropertiesWidget::filteredFilesChanged()
void PropertiesWidget::filterText(const QString &filter)
{
m_propListModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
const QString pattern = Utils::String::wildcardToRegexPattern(filter);
m_propListModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
if (filter.isEmpty())
{
m_ui->filesList->collapseAll();

View File

@@ -719,10 +719,14 @@ void AutomatedRssDownloader::updateMustLineValidity()
{
QStringList tokens;
if (isRegex)
{
tokens << text;
}
else
{
for (const QString &token : asConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
tokens << Utils::String::wildcardToRegexPattern(token);
}
for (const QString &token : asConst(tokens))
{
@@ -762,10 +766,14 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
{
QStringList tokens;
if (isRegex)
{
tokens << text;
}
else
{
for (const QString &token : asConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
tokens << Utils::String::wildcardToRegexPattern(token);
}
for (const QString &token : asConst(tokens))
{

View File

@@ -365,9 +365,9 @@ void SearchJobWidget::fillFilterComboBoxes()
void SearchJobWidget::filterSearchResults(const QString &name)
{
const QRegExp::PatternSyntax patternSyntax = Preferences::instance()->getRegexAsFilteringPatternForSearchJob()
? QRegExp::RegExp : QRegExp::WildcardUnix;
m_proxyModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive, patternSyntax));
const QString pattern = (Preferences::instance()->getRegexAsFilteringPatternForSearchJob()
? name : Utils::String::wildcardToRegexPattern(name));
m_proxyModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
updateResultsCount();
}

View File

@@ -129,7 +129,7 @@ bool TorrentContentFilterModel::hasFiltered(const QModelIndex &folder) const
// this should be called only with folders
// check if the folder name itself matches the filter string
QString name = folder.data().toString();
if (name.contains(filterRegExp()))
if (name.contains(filterRegularExpression()))
return true;
for (int child = 0; child < m_model->rowCount(folder); ++child)
{
@@ -141,7 +141,7 @@ bool TorrentContentFilterModel::hasFiltered(const QModelIndex &folder) const
continue;
}
name = childIndex.data().toString();
if (name.contains(filterRegExp()))
if (name.contains(filterRegularExpression()))
return true;
}

View File

@@ -36,7 +36,6 @@
#include <QHeaderView>
#include <QMenu>
#include <QMessageBox>
#include <QRegExp>
#include <QRegularExpression>
#include <QSet>
#include <QShortcut>
@@ -1131,9 +1130,9 @@ void TransferListWidget::applyTrackerFilter(const QSet<BitTorrent::TorrentID> &t
void TransferListWidget::applyNameFilter(const QString &name)
{
const QRegExp::PatternSyntax patternSyntax = Preferences::instance()->getRegexAsFilteringPatternForTransferList()
? QRegExp::RegExp : QRegExp::WildcardUnix;
m_sortFilterModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive, patternSyntax));
const QString pattern = (Preferences::instance()->getRegexAsFilteringPatternForTransferList()
? name : Utils::String::wildcardToRegexPattern(name));
m_sortFilterModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
}
void TransferListWidget::applyStatusFilter(int f)