Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to build with Qt6 #86

Open
maxwell130631 opened this issue Jan 15, 2021 · 4 comments · May be fixed by #96
Open

Fails to build with Qt6 #86

maxwell130631 opened this issue Jan 15, 2021 · 4 comments · May be fixed by #96

Comments

@maxwell130631
Copy link

Is there a plan to make this work on Qt6?

@mitchcurtis
Copy link
Contributor

I took a bit of a destructive approach to porting this to Qt 6 (removed some stuff I don't use because I don't think there is an equivalent in Qt 6), but haven't finished yet:

diff --git a/isle/3rdparty/SortFilterProxyModel/filter.cpp b/isle/3rdparty/SortFilterProxyModel/filter.cpp
index b57b1eb4..b620aef4 100644
--- a/isle/3rdparty/SortFilterProxyModel/filter.cpp
+++ b/isle/3rdparty/SortFilterProxyModel/filter.cpp
@@ -297,6 +297,12 @@ bool IndexFilter::filterRow(const QModelIndex& sourceIndex, const QQmlSortFilter
 
     \sa syntax
 */
+RegExpFilter::RegExpFilter()
+{
+    m_caseSensitivity = m_regExp.patternOptions().testFlag(QRegularExpression::CaseInsensitiveOption)
+        ? Qt::CaseInsensitive : Qt::CaseSensitive;
+}
+
 QString RegExpFilter::pattern() const
 {
     return m_pattern;
@@ -313,38 +319,6 @@ void RegExpFilter::setPattern(const QString& pattern)
     invalidate();
 }
 
-/*!
-    \qmlproperty enum RegExpFilter::syntax
-
-    The pattern used to filter the contents of the source model.
-
-    Only the source model's value having their \l roleName data matching this \l pattern with the specified \l syntax will be kept.
-
-    \value RegExpFilter.RegExp A rich Perl-like pattern matching syntax. This is the default.
-    \value RegExpFilter.Wildcard This provides a simple pattern matching syntax similar to that used by shells (command interpreters) for "file globbing".
-    \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.
-    \value RegExpFilter.RegExp2 Like RegExp, but with greedy quantifiers.
-    \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 "\".
-    \value RegExpFilter.W3CXmlSchema11 The pattern is a regular expression as defined by the W3C XML Schema 1.1 specification.
-
-    \sa pattern
-*/
-RegExpFilter::PatternSyntax RegExpFilter::syntax() const
-{
-    return m_syntax;
-}
-
-void RegExpFilter::setSyntax(RegExpFilter::PatternSyntax syntax)
-{
-    if (m_syntax == syntax)
-        return;
-
-    m_syntax = syntax;
-    m_regExp.setPatternSyntax(static_cast<QRegExp::PatternSyntax>(syntax));
-    Q_EMIT syntaxChanged();
-    invalidate();
-}
-
 /*!
     \qmlproperty Qt::CaseSensitivity RegExpFilter::caseSensitivity
 
@@ -361,7 +335,9 @@ void RegExpFilter::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
         return;
 
     m_caseSensitivity = caseSensitivity;
-    m_regExp.setCaseSensitivity(caseSensitivity);
+    auto patternOptions = m_regExp.patternOptions();
+    patternOptions.setFlag(QRegularExpression::CaseInsensitiveOption, caseSensitivity == Qt::CaseInsensitive);
+    m_regExp.setPatternOptions(patternOptions);
     Q_EMIT caseSensitivityChanged();
     invalidate();
 }
@@ -369,7 +345,7 @@ void RegExpFilter::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
 bool RegExpFilter::filterRow(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) const
 {
     QString string = sourceData(sourceIndex, proxyModel).toString();
-    return m_regExp.indexIn(string) != -1;
+    return m_regExp.match(string).hasMatch();
 }
 
 /*!
@@ -624,11 +600,11 @@ void ExpressionFilter::updateExpression()
 
 QQmlListProperty<Filter> FilterContainer::filters()
 {
-    return QQmlListProperty<Filter>(this, &m_filters,
-                                    &FilterContainer::append_filter,
-                                    &FilterContainer::count_filter,
-                                    &FilterContainer::at_filter,
-                                    &FilterContainer::clear_filters);
+    return { this, this, &m_filters,
+        &FilterContainer::append_filter,
+        &FilterContainer::count_filter,
+        &FilterContainer::at_filter,
+        &FilterContainer::clear_filters };
 }
 
 void FilterContainer::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
@@ -648,13 +624,13 @@ void FilterContainer::append_filter(QQmlListProperty<Filter>* list, Filter* filt
     that->invalidate();
 }
 
-int FilterContainer::count_filter(QQmlListProperty<Filter>* list)
+qsizetype FilterContainer::count_filter(QQmlListProperty<Filter>* list)
 {
     QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
     return filters->count();
 }
 
-Filter* FilterContainer::at_filter(QQmlListProperty<Filter>* list, int index)
+Filter* FilterContainer::at_filter(QQmlListProperty<Filter>* list, qsizetype index)
 {
     QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
     return filters->at(index);
diff --git a/isle/3rdparty/SortFilterProxyModel/filter.h b/isle/3rdparty/SortFilterProxyModel/filter.h
index 01a3a755..265982c8 100644
--- a/isle/3rdparty/SortFilterProxyModel/filter.h
+++ b/isle/3rdparty/SortFilterProxyModel/filter.h
@@ -111,27 +111,16 @@ private:
 class RegExpFilter : public RoleFilter {
     Q_OBJECT
     Q_PROPERTY(QString pattern READ pattern WRITE setPattern NOTIFY patternChanged)
-    Q_PROPERTY(PatternSyntax syntax READ syntax WRITE setSyntax NOTIFY syntaxChanged)
     Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity NOTIFY caseSensitivityChanged)
 
 public:
-    enum PatternSyntax {
-        RegExp = QRegExp::RegExp,
-        Wildcard = QRegExp::Wildcard,
-        FixedString = QRegExp::FixedString,
-        RegExp2 = QRegExp::RegExp2,
-        WildcardUnix = QRegExp::WildcardUnix,
-        W3CXmlSchema11 = QRegExp::W3CXmlSchema11 };
-    Q_ENUMS(PatternSyntax)
-
     using RoleFilter::RoleFilter;
 
+    RegExpFilter();
+
     QString pattern() const;
     void setPattern(const QString& pattern);
 
-    PatternSyntax syntax() const;
-    void setSyntax(PatternSyntax syntax);
-
     Qt::CaseSensitivity caseSensitivity() const;
     void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
 
@@ -144,9 +133,8 @@ Q_SIGNALS:
     void caseSensitivityChanged();
 
 private:
-    QRegExp m_regExp;
-    Qt::CaseSensitivity m_caseSensitivity = m_regExp.caseSensitivity();
-    PatternSyntax m_syntax = static_cast<PatternSyntax>(m_regExp.patternSyntax());
+    QRegularExpression m_regExp;
+    Qt::CaseSensitivity m_caseSensitivity;
     QString m_pattern = m_regExp.pattern();
 };
 
@@ -232,8 +220,8 @@ protected:
 
 private:
     static void append_filter(QQmlListProperty<Filter>* list, Filter* filter);
-    static int count_filter(QQmlListProperty<Filter>* list);
-    static Filter* at_filter(QQmlListProperty<Filter>* list, int index);
+    static qsizetype count_filter(QQmlListProperty<Filter>* list);
+    static Filter* at_filter(QQmlListProperty<Filter>* list, qsizetype index);
     static void clear_filters(QQmlListProperty<Filter>* list);
 };
 
diff --git a/isle/3rdparty/SortFilterProxyModel/proxyrole.cpp b/isle/3rdparty/SortFilterProxyModel/proxyrole.cpp
index 22e9cea2..3514632e 100644
--- a/isle/3rdparty/SortFilterProxyModel/proxyrole.cpp
+++ b/isle/3rdparty/SortFilterProxyModel/proxyrole.cpp
@@ -244,11 +244,11 @@ void SwitchRole::setDefaultValue(const QVariant& defaultValue)
 */
 QQmlListProperty<Filter> SwitchRole::filters()
 {
-    return QQmlListProperty<Filter>(this, &m_filters,
-                                    &SwitchRole::append_filter,
-                                    &SwitchRole::count_filter,
-                                    &SwitchRole::at_filter,
-                                    &SwitchRole::clear_filters);
+    return { this, &m_filters,
+        &SwitchRole::append_filter,
+        &SwitchRole::count_filter,
+        &SwitchRole::at_filter,
+        &SwitchRole::clear_filters };
 }
 
 void SwitchRole::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
@@ -299,13 +299,13 @@ void SwitchRole::append_filter(QQmlListProperty<Filter>* list, Filter* filter)
     that->invalidate();
 }
 
-int SwitchRole::count_filter(QQmlListProperty<Filter>* list)
+qsizetype SwitchRole::count_filter(QQmlListProperty<Filter>* list)
 {
     QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
     return filters->count();
 }
 
-Filter* SwitchRole::at_filter(QQmlListProperty<Filter>* list, int index)
+Filter* SwitchRole::at_filter(QQmlListProperty<Filter>* list, qsizetype index)
 {
     QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
     return filters->at(index);
diff --git a/isle/3rdparty/SortFilterProxyModel/proxyrole.h b/isle/3rdparty/SortFilterProxyModel/proxyrole.h
index 1f132ad1..ba712bf7 100644
--- a/isle/3rdparty/SortFilterProxyModel/proxyrole.h
+++ b/isle/3rdparty/SortFilterProxyModel/proxyrole.h
@@ -111,8 +111,8 @@ private:
     QVariant data(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) override;
 
     static void append_filter(QQmlListProperty<Filter>* list, Filter* filter);
-    static int count_filter(QQmlListProperty<Filter>* list);
-    static Filter* at_filter(QQmlListProperty<Filter>* list, int index);
+    static qsizetype count_filter(QQmlListProperty<Filter>* list);
+    static Filter* at_filter(QQmlListProperty<Filter>* list, qsizetype index);
     static void clear_filters(QQmlListProperty<Filter>* list);
 
     QString m_defaultRoleName;
diff --git a/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.cpp b/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.cpp
index acc7b9af..b10c2b51 100644
--- a/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.cpp
+++ b/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.cpp
@@ -86,23 +86,6 @@ void QQmlSortFilterProxyModel::setFilterPattern(const QString& filterPattern)
     Q_EMIT filterPatternChanged();
 }
 
-QQmlSortFilterProxyModel::PatternSyntax QQmlSortFilterProxyModel::filterPatternSyntax() const
-{
-    return static_cast<PatternSyntax>(filterRegExp().patternSyntax());
-}
-
-void QQmlSortFilterProxyModel::setFilterPatternSyntax(QQmlSortFilterProxyModel::PatternSyntax patternSyntax)
-{
-    QRegExp regExp = filterRegExp();
-    QRegExp::PatternSyntax patternSyntaxTmp = static_cast<QRegExp::PatternSyntax>(patternSyntax);
-    if (regExp.patternSyntax() == patternSyntaxTmp)
-        return;
-
-    regExp.setPatternSyntax(patternSyntaxTmp);
-    QSortFilterProxyModel::setFilterRegExp(regExp);
-    Q_EMIT filterPatternSyntaxChanged();
-}
-
 const QVariant& QQmlSortFilterProxyModel::filterValue() const
 {
     return m_filterValue;
@@ -165,11 +148,11 @@ void QQmlSortFilterProxyModel::setAscendingSortOrder(bool ascendingSortOrder)
 */
 QQmlListProperty<Filter> QQmlSortFilterProxyModel::filters()
 {
-    return QQmlListProperty<Filter>(this, &m_filters,
-                                    &QQmlSortFilterProxyModel::append_filter,
-                                    &QQmlSortFilterProxyModel::count_filter,
-                                    &QQmlSortFilterProxyModel::at_filter,
-                                    &QQmlSortFilterProxyModel::clear_filters);
+    return { this, this, &m_filters,
+        &QQmlSortFilterProxyModel::append_filter,
+        &QQmlSortFilterProxyModel::count_filter,
+        &QQmlSortFilterProxyModel::at_filter,
+        &QQmlSortFilterProxyModel::clear_filters };
 }
 
 /*!
@@ -181,11 +164,11 @@ QQmlListProperty<Filter> QQmlSortFilterProxyModel::filters()
 */
 QQmlListProperty<Sorter> QQmlSortFilterProxyModel::sorters()
 {
-    return QQmlListProperty<Sorter>(this, &m_sorters,
-                                    &QQmlSortFilterProxyModel::append_sorter,
-                                    &QQmlSortFilterProxyModel::count_sorter,
-                                    &QQmlSortFilterProxyModel::at_sorter,
-                                    &QQmlSortFilterProxyModel::clear_sorters);
+    return { this, &m_sorters,
+        &QQmlSortFilterProxyModel::append_sorter,
+        &QQmlSortFilterProxyModel::count_sorter,
+        &QQmlSortFilterProxyModel::at_sorter,
+        &QQmlSortFilterProxyModel::clear_sorters };
 }
 
 /*!
@@ -471,13 +454,13 @@ void QQmlSortFilterProxyModel::append_filter(QQmlListProperty<Filter>* list, Fil
     that->invalidateFilter();
 }
 
-int QQmlSortFilterProxyModel::count_filter(QQmlListProperty<Filter>* list)
+qsizetype QQmlSortFilterProxyModel::count_filter(QQmlListProperty<Filter>* list)
 {
     QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
     return filters->count();
 }
 
-Filter* QQmlSortFilterProxyModel::at_filter(QQmlListProperty<Filter>* list, int index)
+Filter* QQmlSortFilterProxyModel::at_filter(QQmlListProperty<Filter>* list, qsizetype index)
 {
     QList<Filter*>* filters = static_cast<QList<Filter*>*>(list->data);
     return filters->at(index);
@@ -501,13 +484,13 @@ void QQmlSortFilterProxyModel::append_sorter(QQmlListProperty<Sorter>* list, Sor
     that->invalidate();
 }
 
-int QQmlSortFilterProxyModel::count_sorter(QQmlListProperty<Sorter>* list)
+qsizetype QQmlSortFilterProxyModel::count_sorter(QQmlListProperty<Sorter>* list)
 {
     auto sorters = static_cast<QList<Sorter*>*>(list->data);
     return sorters->count();
 }
 
-Sorter* QQmlSortFilterProxyModel::at_sorter(QQmlListProperty<Sorter>* list, int index)
+Sorter* QQmlSortFilterProxyModel::at_sorter(QQmlListProperty<Sorter>* list, qsizetype index)
 {
     auto sorters = static_cast<QList<Sorter*>*>(list->data);
     return sorters->at(index);
@@ -534,13 +517,13 @@ void QQmlSortFilterProxyModel::append_proxyRole(QQmlListProperty<ProxyRole>* lis
     that->endResetModel();
 }
 
-int QQmlSortFilterProxyModel::count_proxyRole(QQmlListProperty<ProxyRole>* list)
+qsizetype QQmlSortFilterProxyModel::count_proxyRole(QQmlListProperty<ProxyRole>* list)
 {
     auto proxyRoles = static_cast<QList<ProxyRole*>*>(list->data);
     return proxyRoles->count();
 }
 
-ProxyRole* QQmlSortFilterProxyModel::at_proxyRole(QQmlListProperty<ProxyRole>* list, int index)
+ProxyRole* QQmlSortFilterProxyModel::at_proxyRole(QQmlListProperty<ProxyRole>* list, qsizetype index)
 {
     auto proxyRoles = static_cast<QList<ProxyRole*>*>(list->data);
     return proxyRoles->at(index);
diff --git a/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.h b/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.h
index bc22566e..8a84efbd 100644
--- a/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.h
+++ b/isle/3rdparty/SortFilterProxyModel/qqmlsortfilterproxymodel.h
@@ -2,6 +2,7 @@
 #define QQMLSORTFILTERPROXYMODEL_H
 
 #include <QSortFilterProxyModel>
+#include <QRegularExpression>
 #include <QQmlParserStatus>
 #include <QQmlListProperty>
 
@@ -20,7 +21,6 @@ class QQmlSortFilterProxyModel : public QSortFilterProxyModel, public QQmlParser
 
     Q_PROPERTY(QString filterRoleName READ filterRoleName WRITE setFilterRoleName NOTIFY filterRoleNameChanged)
     Q_PROPERTY(QString filterPattern READ filterPattern WRITE setFilterPattern NOTIFY filterPatternChanged)
-    Q_PROPERTY(PatternSyntax filterPatternSyntax READ filterPatternSyntax WRITE setFilterPatternSyntax NOTIFY filterPatternSyntaxChanged)
     Q_PROPERTY(QVariant filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged)
 
     Q_PROPERTY(QString sortRoleName READ sortRoleName WRITE setSortRoleName NOTIFY sortRoleNameChanged)
@@ -31,15 +31,6 @@ class QQmlSortFilterProxyModel : public QSortFilterProxyModel, public QQmlParser
     Q_PROPERTY(QQmlListProperty<qqsfpm::ProxyRole> proxyRoles READ proxyRoles)
 
 public:
-    enum PatternSyntax {
-        RegExp = QRegExp::RegExp,
-        Wildcard = QRegExp::Wildcard,
-        FixedString = QRegExp::FixedString,
-        RegExp2 = QRegExp::RegExp2,
-        WildcardUnix = QRegExp::WildcardUnix,
-        W3CXmlSchema11 = QRegExp::W3CXmlSchema11 };
-    Q_ENUMS(PatternSyntax)
-
     QQmlSortFilterProxyModel(QObject* parent = 0);
 
     int count() const;
@@ -50,9 +41,6 @@ public:
     QString filterPattern() const;
     void setFilterPattern(const QString& filterPattern);
 
-    PatternSyntax filterPatternSyntax() const;
-    void setFilterPatternSyntax(PatternSyntax patternSyntax);
-
     const QVariant& filterValue() const;
     void setFilterValue(const QVariant& filterValue);
 
@@ -89,7 +77,6 @@ Q_SIGNALS:
     void countChanged();
 
     void filterRoleNameChanged();
-    void filterPatternSyntaxChanged();
     void filterPatternChanged();
     void filterValueChanged();
 
@@ -101,7 +88,7 @@ protected:
     bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
 
 protected Q_SLOTS:
-    void resetInternalData();
+    void resetInternalData() override;
 
 private Q_SLOTS:
     void invalidateFilter();
@@ -117,18 +104,18 @@ private:
     QVariantMap modelDataMap(const QModelIndex& modelIndex) const;
 
     static void append_filter(QQmlListProperty<Filter>* list, Filter* filter);
-    static int count_filter(QQmlListProperty<Filter>* list);
-    static Filter* at_filter(QQmlListProperty<Filter>* list, int index);
+    static qsizetype count_filter(QQmlListProperty<Filter>* list);
+    static Filter* at_filter(QQmlListProperty<Filter>* list, qsizetype index);
     static void clear_filters(QQmlListProperty<Filter>* list);
 
     static void append_sorter(QQmlListProperty<Sorter>* list, Sorter* sorter);
-    static int count_sorter(QQmlListProperty<Sorter>* list);
-    static Sorter* at_sorter(QQmlListProperty<Sorter>* list, int index);
+    static qsizetype count_sorter(QQmlListProperty<Sorter>* list);
+    static Sorter* at_sorter(QQmlListProperty<Sorter>* list, qsizetype index);
     static void clear_sorters(QQmlListProperty<Sorter>* list);
 
     static void append_proxyRole(QQmlListProperty<ProxyRole>* list, ProxyRole* proxyRole);
-    static int count_proxyRole(QQmlListProperty<ProxyRole>* list);
-    static ProxyRole* at_proxyRole(QQmlListProperty<ProxyRole>* list, int index);
+    static qsizetype count_proxyRole(QQmlListProperty<ProxyRole>* list);
+    static ProxyRole* at_proxyRole(QQmlListProperty<ProxyRole>* list, qsizetype index);
     static void clear_proxyRoles(QQmlListProperty<ProxyRole>* list);
 
     QString m_filterRoleName;

I'm getting this error:

[...]/isle/3rdparty/SortFilterProxyModel/sorter.cpp:167:19: error: invalid operands to binary expression ('QVariant' and 'QVariant')
    if (leftValue < rightValue)
        ~~~~~~~~~ ^ ~~~~~~~~~~

@mitchcurtis
Copy link
Contributor

https://doc.qt.io/qt-5/qvariant-obsolete.html#operator-lt says:

Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().

@Fianax
Copy link

Fianax commented May 26, 2021

thanks for your work I hope you get it because I love this module and I hope to use it in qt6

@mitchcurtis
Copy link
Contributor

I'm guessing the solution to the QVariant comparison issue is just to check for the most common types like int, QString, etc. So basically similar to the operator< that was removed. We could warn and fail for all other types. I don't know how it would be possible to support custom user types now that QMetaType::registerComparators() function was removed.

For reference, they were deprecated here and removed here.

mitchcurtis added a commit to mitchcurtis/SortFilterProxyModel that referenced this issue May 14, 2022
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 oKcerG#84
Fixes oKcerG#86
@mitchcurtis mitchcurtis linked a pull request May 14, 2022 that will close this issue
mitchcurtis added a commit to mitchcurtis/SortFilterProxyModel that referenced this issue May 14, 2022
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 oKcerG#84
Fixes oKcerG#86
arunpkio pushed a commit to arunpkio/SortFilterProxyModel that referenced this issue Nov 10, 2023
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 oKcerG#84
Fixes oKcerG#86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants