Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions Libs/DICOM/Widgets/ctkDICOMObjectListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QClipboard>
#include <QDesktopServices>
#include <QImage>
#include <QRegularExpression>
#include <QSortFilterProxyModel>
#include <QString>
#include <QStringList>
Expand All @@ -48,17 +49,10 @@ class qRecursiveTreeProxyFilter : public QSortFilterProxyModel {

bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (filterRegExp().isEmpty() && filterRegularExpression().pattern().isEmpty())
{
return true;
}
#else
if (filterRegularExpression().pattern().isEmpty())
{
return true;
}
#endif
if (filterRegularExpression().pattern().isEmpty())
{
return true;
}
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return filterAcceptsIndex(index);
}
Expand Down Expand Up @@ -141,13 +135,22 @@ void ctkDICOMObjectListWidgetPrivate::setFilterExpressionInModel(qRecursiveTreeP
const QString regexpPrefix("regexp:");
if (expr.startsWith(regexpPrefix))
{
filterModel->setFilterCaseSensitivity(Qt::CaseSensitive);
filterModel->setFilterRegularExpression(expr.right(expr.length() - regexpPrefix.length()));
// User-supplied regex: case-sensitive by default (user can add (?i) if needed)
filterModel->setFilterRegularExpression(
QRegularExpression(expr.right(expr.length() - regexpPrefix.length())));
}
else
{
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
filterModel->setFilterWildcard(expr);
// Convert wildcard pattern to QRegularExpression so that filterRegularExpression()
// (used by filterAcceptsIndex) works correctly in both Qt5 and Qt6.
// setFilterWildcard() in Qt5 stores a QRegExp internally; Qt5's conversion of that
// QRegExp to QRegularExpression copies the wildcard pattern as-is, making '*' an
// invalid leading quantifier that never matches anything.
QString regexPattern = QRegularExpression::escape(expr);
regexPattern.replace("\\*", ".*");
regexPattern.replace("\\?", ".");
Comment thread
Punzo marked this conversation as resolved.
filterModel->setFilterRegularExpression(
QRegularExpression(regexPattern, QRegularExpression::CaseInsensitiveOption));
Comment thread
Punzo marked this conversation as resolved.
}
}

Expand Down
Loading