QRegularExpression wildcard matching.

This commit is contained in:
Roman Telezhynskyi 2023-02-09 16:35:30 +02:00
parent e280c309cb
commit 0335bcf571

View File

@ -32,12 +32,15 @@
#include <QLineEdit>
#include <QList>
#include <QMimeData>
#include <QRegExp>
#include <QSizePolicy>
#include <QToolButton>
#include <QUrl>
#include <Qt>
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
#include <QRegExp>
#endif
VPE::VFileEditWidget::VFileEditWidget(QWidget *parent, bool is_directory)
: QWidget(parent), CurrentFilePath(), ToolButton(nullptr), FileLineEdit(nullptr), FileDialogFilter(), FilterList(),
Directory(is_directory)
@ -251,14 +254,16 @@ bool VPE::VFileEditWidget::checkFileFilter(const QString& file) const
return false;
}
for (auto &tmpFilter : FilterList)
return std::any_of(FilterList.begin(), FilterList.end(), [file](const QString &tmpFilter)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const QString wildcardFilter = QRegularExpression::wildcardToRegularExpression(tmpFilter);
QRegularExpression tmpRegExpFilter(QRegularExpression::anchoredPattern(wildcardFilter),
QRegularExpression::CaseInsensitiveOption);
return tmpRegExpFilter.match(file).hasMatch();
#else
QRegExp tmpRegExpFilter(tmpFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
if (tmpRegExpFilter.exactMatch(file))
{
return true;
}
}
return false;
return tmpRegExpFilter.exactMatch(file);
#endif
});
}