Skip to content

Commit fe50203

Browse files
committed
Port to Qt 6
The PatternSyntax enum had to be removed as QRegularExpression only supports Perl-compatible regular expressions. As QVariant's comparison operators were removed, a simplified comparison is now done as a starting point, but should probably be extended to support more types. Fixes #84 Fixes #86
1 parent 5a93088 commit fe50203

19 files changed

+131
-120
lines changed

SortFilterProxyModel.pri

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ HEADERS += $$PWD/qqmlsortfilterproxymodel.h \
2727
$$PWD/proxyroles/singlerole.h \
2828
$$PWD/proxyroles/regexprole.h \
2929
$$PWD/sorters/filtersorter.h \
30-
$$PWD/proxyroles/filterrole.h
30+
$$PWD/proxyroles/filterrole.h \
31+
$$PWD/utils/utils.h
3132

3233
SOURCES += $$PWD/qqmlsortfilterproxymodel.cpp \
3334
$$PWD/filters/filter.cpp \
@@ -57,4 +58,5 @@ SOURCES += $$PWD/qqmlsortfilterproxymodel.cpp \
5758
$$PWD/proxyroles/singlerole.cpp \
5859
$$PWD/proxyroles/regexprole.cpp \
5960
$$PWD/sorters/filtersorter.cpp \
60-
$$PWD/proxyroles/filterrole.cpp
61+
$$PWD/proxyroles/filterrole.cpp \
62+
$$PWD/utils/utils.cpp

SortFilterProxyModel.qbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Group {
5757
"sorters/sortersqmltypes.cpp",
5858
"sorters/stringsorter.cpp",
5959
"sorters/stringsorter.h",
60+
"utils/utils.cpp",
61+
"utils/utils.h",
6062
"qqmlsortfilterproxymodel.cpp",
6163
"qqmlsortfilterproxymodel.h"
6264
]

filters/filtercontainer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ void FilterContainer::append_filter(QQmlListProperty<Filter>* list, Filter* filt
5656
that->appendFilter(filter);
5757
}
5858

59-
int FilterContainer::count_filter(QQmlListProperty<Filter>* list)
59+
qsizetype FilterContainer::count_filter(QQmlListProperty<Filter>* list)
6060
{
6161
QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
6262
return filters->count();
6363
}
6464

65-
Filter* FilterContainer::at_filter(QQmlListProperty<Filter>* list, int index)
65+
Filter* FilterContainer::at_filter(QQmlListProperty<Filter>* list, qsizetype index)
6666
{
6767
QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
6868
return filters->at(index);

filters/filtercontainer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class FilterContainer {
3131
virtual void onFiltersCleared() = 0;
3232

3333
static void append_filter(QQmlListProperty<Filter>* list, Filter* filter);
34-
static int count_filter(QQmlListProperty<Filter>* list);
35-
static Filter* at_filter(QQmlListProperty<Filter>* list, int index);
34+
static qsizetype count_filter(QQmlListProperty<Filter>* list);
35+
static Filter* at_filter(QQmlListProperty<Filter>* list, qsizetype index);
3636
static void clear_filters(QQmlListProperty<Filter>* list);
3737
};
3838

filters/rangefilter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "rangefilter.h"
2+
#include "../utils/utils.h"
23

34
namespace qqsfpm {
45

@@ -128,7 +129,7 @@ void RangeFilter::setMaximumInclusive(bool maximumInclusive)
128129

129130
bool RangeFilter::filterRow(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) const
130131
{
131-
QVariant value = sourceData(sourceIndex, proxyModel);
132+
const QVariant value = sourceData(sourceIndex, proxyModel);
132133
bool lessThanMin = m_minimumValue.isValid() &&
133134
(m_minimumInclusive ? value < m_minimumValue : value <= m_minimumValue);
134135
bool moreThanMax = m_maximumValue.isValid() &&

filters/regexpfilter.cpp

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ namespace qqsfpm {
3535
3636
\sa syntax
3737
*/
38+
RegExpFilter::RegExpFilter() :
39+
m_caseSensitivity(m_regExp.patternOptions().testFlag(
40+
QRegularExpression::CaseInsensitiveOption) ? Qt::CaseInsensitive : Qt::CaseSensitive)
41+
{
42+
}
43+
3844
QString RegExpFilter::pattern() const
3945
{
4046
return m_pattern;
@@ -51,38 +57,6 @@ void RegExpFilter::setPattern(const QString& pattern)
5157
invalidate();
5258
}
5359

54-
/*!
55-
\qmlproperty enum RegExpFilter::syntax
56-
57-
The pattern used to filter the contents of the source model.
58-
59-
Only the source model's value having their \l RoleFilter::roleName data matching this \l pattern with the specified \l syntax will be kept.
60-
61-
\value RegExpFilter.RegExp A rich Perl-like pattern matching syntax. This is the default.
62-
\value RegExpFilter.Wildcard This provides a simple pattern matching syntax similar to that used by shells (command interpreters) for "file globbing".
63-
\value RegExpFilter.FixedString The pattern is a fixed string. This is equivalent to using the RegExp pattern on a string in which all metacharacters are escaped.
64-
\value RegExpFilter.RegExp2 Like RegExp, but with greedy quantifiers.
65-
\value RegExpFilter.WildcardUnix This is similar to Wildcard but with the behavior of a Unix shell. The wildcard characters can be escaped with the character "\".
66-
\value RegExpFilter.W3CXmlSchema11 The pattern is a regular expression as defined by the W3C XML Schema 1.1 specification.
67-
68-
\sa pattern
69-
*/
70-
RegExpFilter::PatternSyntax RegExpFilter::syntax() const
71-
{
72-
return m_syntax;
73-
}
74-
75-
void RegExpFilter::setSyntax(RegExpFilter::PatternSyntax syntax)
76-
{
77-
if (m_syntax == syntax)
78-
return;
79-
80-
m_syntax = syntax;
81-
m_regExp.setPatternSyntax(static_cast<QRegExp::PatternSyntax>(syntax));
82-
Q_EMIT syntaxChanged();
83-
invalidate();
84-
}
85-
8660
/*!
8761
\qmlproperty Qt::CaseSensitivity RegExpFilter::caseSensitivity
8862
@@ -99,15 +73,18 @@ void RegExpFilter::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
9973
return;
10074

10175
m_caseSensitivity = caseSensitivity;
102-
m_regExp.setCaseSensitivity(caseSensitivity);
76+
QRegularExpression::PatternOptions patternOptions = m_regExp.patternOptions();
77+
if (caseSensitivity == Qt::CaseInsensitive)
78+
patternOptions.setFlag(QRegularExpression::CaseInsensitiveOption);
79+
m_regExp.setPatternOptions(patternOptions);
10380
Q_EMIT caseSensitivityChanged();
10481
invalidate();
10582
}
10683

10784
bool RegExpFilter::filterRow(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) const
10885
{
109-
QString string = sourceData(sourceIndex, proxyModel).toString();
110-
return m_regExp.indexIn(string) != -1;
86+
const QString string = sourceData(sourceIndex, proxyModel).toString();
87+
return m_regExp.match(string).hasMatch();
11188
}
11289

11390
}

filters/regexpfilter.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,23 @@
33

44
#include "rolefilter.h"
55

6+
#include <QRegularExpression>
7+
68
namespace qqsfpm {
79

810
class RegExpFilter : public RoleFilter {
911
Q_OBJECT
1012
Q_PROPERTY(QString pattern READ pattern WRITE setPattern NOTIFY patternChanged)
11-
Q_PROPERTY(PatternSyntax syntax READ syntax WRITE setSyntax NOTIFY syntaxChanged)
1213
Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity NOTIFY caseSensitivityChanged)
1314

1415
public:
15-
enum PatternSyntax {
16-
RegExp = QRegExp::RegExp,
17-
Wildcard = QRegExp::Wildcard,
18-
FixedString = QRegExp::FixedString,
19-
RegExp2 = QRegExp::RegExp2,
20-
WildcardUnix = QRegExp::WildcardUnix,
21-
W3CXmlSchema11 = QRegExp::W3CXmlSchema11 };
22-
Q_ENUMS(PatternSyntax)
23-
2416
using RoleFilter::RoleFilter;
2517

18+
RegExpFilter();
19+
2620
QString pattern() const;
2721
void setPattern(const QString& pattern);
2822

29-
PatternSyntax syntax() const;
30-
void setSyntax(PatternSyntax syntax);
31-
3223
Qt::CaseSensitivity caseSensitivity() const;
3324
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
3425

@@ -37,13 +28,11 @@ class RegExpFilter : public RoleFilter {
3728

3829
Q_SIGNALS:
3930
void patternChanged();
40-
void syntaxChanged();
4131
void caseSensitivityChanged();
4232

4333
private:
44-
QRegExp m_regExp;
45-
Qt::CaseSensitivity m_caseSensitivity = m_regExp.caseSensitivity();
46-
PatternSyntax m_syntax = static_cast<PatternSyntax>(m_regExp.patternSyntax());
34+
QRegularExpression m_regExp;
35+
Qt::CaseSensitivity m_caseSensitivity;
4736
QString m_pattern = m_regExp.pattern();
4837
};
4938

proxyroles/proxyrolecontainer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ void ProxyRoleContainer::append_proxyRole(QQmlListProperty<ProxyRole>* list, Pro
4343
that->appendProxyRole(proxyRole);
4444
}
4545

46-
int ProxyRoleContainer::count_proxyRole(QQmlListProperty<ProxyRole>* list)
46+
qsizetype ProxyRoleContainer::count_proxyRole(QQmlListProperty<ProxyRole>* list)
4747
{
4848
QList<ProxyRole*>* ProxyRoles = static_cast<QList<ProxyRole*>*>(list->data);
4949
return ProxyRoles->count();
5050
}
5151

52-
ProxyRole* ProxyRoleContainer::at_proxyRole(QQmlListProperty<ProxyRole>* list, int index)
52+
ProxyRole* ProxyRoleContainer::at_proxyRole(QQmlListProperty<ProxyRole>* list, qsizetype index)
5353
{
5454
QList<ProxyRole*>* ProxyRoles = static_cast<QList<ProxyRole*>*>(list->data);
5555
return ProxyRoles->at(index);

proxyroles/proxyrolecontainer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class ProxyRoleContainer {
2929
virtual void onProxyRolesCleared() = 0;
3030

3131
static void append_proxyRole(QQmlListProperty<ProxyRole>* list, ProxyRole* proxyRole);
32-
static int count_proxyRole(QQmlListProperty<ProxyRole>* list);
33-
static ProxyRole* at_proxyRole(QQmlListProperty<ProxyRole>* list, int index);
32+
static qsizetype count_proxyRole(QQmlListProperty<ProxyRole>* list);
33+
static ProxyRole* at_proxyRole(QQmlListProperty<ProxyRole>* list, qsizetype index);
3434
static void clear_proxyRoles(QQmlListProperty<ProxyRole>* list);
3535
};
3636

qqmlsortfilterproxymodel.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,37 +92,20 @@ void QQmlSortFilterProxyModel::setFilterRoleName(const QString& filterRoleName)
9292

9393
QString QQmlSortFilterProxyModel::filterPattern() const
9494
{
95-
return filterRegExp().pattern();
95+
return filterRegularExpression().pattern();
9696
}
9797

9898
void QQmlSortFilterProxyModel::setFilterPattern(const QString& filterPattern)
9999
{
100-
QRegExp regExp = filterRegExp();
100+
QRegularExpression regExp = filterRegularExpression();
101101
if (regExp.pattern() == filterPattern)
102102
return;
103103

104104
regExp.setPattern(filterPattern);
105-
QSortFilterProxyModel::setFilterRegExp(regExp);
105+
QSortFilterProxyModel::setFilterRegularExpression(regExp);
106106
Q_EMIT filterPatternChanged();
107107
}
108108

109-
QQmlSortFilterProxyModel::PatternSyntax QQmlSortFilterProxyModel::filterPatternSyntax() const
110-
{
111-
return static_cast<PatternSyntax>(filterRegExp().patternSyntax());
112-
}
113-
114-
void QQmlSortFilterProxyModel::setFilterPatternSyntax(QQmlSortFilterProxyModel::PatternSyntax patternSyntax)
115-
{
116-
QRegExp regExp = filterRegExp();
117-
QRegExp::PatternSyntax patternSyntaxTmp = static_cast<QRegExp::PatternSyntax>(patternSyntax);
118-
if (regExp.patternSyntax() == patternSyntaxTmp)
119-
return;
120-
121-
regExp.setPatternSyntax(patternSyntaxTmp);
122-
QSortFilterProxyModel::setFilterRegExp(regExp);
123-
Q_EMIT filterPatternSyntaxChanged();
124-
}
125-
126109
const QVariant& QQmlSortFilterProxyModel::filterValue() const
127110
{
128111
return m_filterValue;

0 commit comments

Comments
 (0)