@@ -274,6 +274,12 @@ class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate
274
274
Q_DECLARE_PUBLIC (QSortFilterProxyModel)
275
275
276
276
public:
277
+ enum class Direction {
278
+ Rows = 1 ,
279
+ Columns = 2 ,
280
+ All = Rows | Columns
281
+ };
282
+
277
283
struct Mapping {
278
284
QVector<int > source_rows;
279
285
QVector<int > source_columns;
@@ -413,7 +419,7 @@ class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate
413
419
void update_persistent_indexes (const QModelIndexPairList &source_indexes);
414
420
415
421
void filter_about_to_be_changed (const QModelIndex &source_parent = QModelIndex());
416
- void filter_changed (const QModelIndex &source_parent = QModelIndex());
422
+ void filter_changed (Direction dir, const QModelIndex &source_parent = QModelIndex());
417
423
QSet<int > handle_filter_changed (
418
424
QVector<int > &source_to_proxy, QVector<int > &proxy_to_source,
419
425
const QModelIndex &source_parent, Qt::Orientation orient);
@@ -431,6 +437,11 @@ class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate
431
437
432
438
typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;
433
439
440
+ static bool operator &(QSortFilterProxyModelPrivate::Direction a, QSortFilterProxyModelPrivate::Direction b)
441
+ {
442
+ return int (a) & int (b);
443
+ }
444
+
434
445
void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed ()
435
446
{
436
447
QAbstractProxyModelPrivate::_q_sourceModelDestroyed ();
@@ -1269,14 +1280,14 @@ void QSortFilterProxyModelPrivate::filter_about_to_be_changed(const QModelIndex
1269
1280
Updates the proxy model (adds/removes rows) based on the
1270
1281
new filter.
1271
1282
*/
1272
- void QSortFilterProxyModelPrivate::filter_changed (const QModelIndex &source_parent)
1283
+ void QSortFilterProxyModelPrivate::filter_changed (Direction dir, const QModelIndex &source_parent)
1273
1284
{
1274
1285
IndexMap::const_iterator it = source_index_mapping.constFind (source_parent);
1275
1286
if (it == source_index_mapping.constEnd ())
1276
1287
return ;
1277
1288
Mapping *m = it.value ();
1278
- QSet<int > rows_removed = handle_filter_changed (m->proxy_rows , m->source_rows , source_parent, Qt::Vertical);
1279
- QSet<int > columns_removed = handle_filter_changed (m->proxy_columns , m->source_columns , source_parent, Qt::Horizontal);
1289
+ const QSet<int > rows_removed = (dir & Direction::Rows) ? handle_filter_changed (m->proxy_rows , m->source_rows , source_parent, Qt::Vertical) : QSet< int >( );
1290
+ const QSet<int > columns_removed = (dir & Direction::Columns) ? handle_filter_changed (m->proxy_columns , m->source_columns , source_parent, Qt::Horizontal) : QSet< int >( );
1280
1291
1281
1292
// We need to iterate over a copy of m->mapped_children because otherwise it may be changed by other code, invalidating
1282
1293
// the iterator it2.
@@ -1290,7 +1301,7 @@ void QSortFilterProxyModelPrivate::filter_changed(const QModelIndex &source_pare
1290
1301
indexesToRemove.push_back (i);
1291
1302
remove_from_mapping (source_child_index);
1292
1303
} else {
1293
- filter_changed (source_child_index);
1304
+ filter_changed (dir, source_child_index);
1294
1305
}
1295
1306
}
1296
1307
QVector<int >::const_iterator removeIt = indexesToRemove.constEnd ();
@@ -2605,7 +2616,7 @@ void QSortFilterProxyModel::setFilterRegExp(const QRegExp ®Exp)
2605
2616
Q_D (QSortFilterProxyModel);
2606
2617
d->filter_about_to_be_changed ();
2607
2618
d->filter_data .setRegExp (regExp);
2608
- d->filter_changed ();
2619
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2609
2620
}
2610
2621
2611
2622
#if QT_CONFIG(regularexpression)
@@ -2634,7 +2645,7 @@ void QSortFilterProxyModel::setFilterRegularExpression(const QRegularExpression
2634
2645
Q_D (QSortFilterProxyModel);
2635
2646
d->filter_about_to_be_changed ();
2636
2647
d->filter_data .setRegularExpression (regularExpression);
2637
- d->filter_changed ();
2648
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2638
2649
}
2639
2650
#endif
2640
2651
@@ -2657,7 +2668,7 @@ void QSortFilterProxyModel::setFilterKeyColumn(int column)
2657
2668
Q_D (QSortFilterProxyModel);
2658
2669
d->filter_about_to_be_changed ();
2659
2670
d->filter_column = column;
2660
- d->filter_changed ();
2671
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2661
2672
}
2662
2673
2663
2674
/* !
@@ -2683,7 +2694,7 @@ void QSortFilterProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs)
2683
2694
return ;
2684
2695
d->filter_about_to_be_changed ();
2685
2696
d->filter_data .setCaseSensitivity (cs);
2686
- d->filter_changed ();
2697
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2687
2698
emit filterCaseSensitivityChanged (cs);
2688
2699
}
2689
2700
@@ -2754,7 +2765,7 @@ void QSortFilterProxyModel::setFilterRegExp(const QString &pattern)
2754
2765
QRegExp rx (pattern);
2755
2766
rx.setCaseSensitivity (d->filter_data .caseSensitivity ());
2756
2767
d->filter_data .setRegExp (rx);
2757
- d->filter_changed ();
2768
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2758
2769
}
2759
2770
2760
2771
#if QT_CONFIG(regularexpression)
@@ -2775,7 +2786,7 @@ void QSortFilterProxyModel::setFilterRegularExpression(const QString &pattern)
2775
2786
d->filter_about_to_be_changed ();
2776
2787
QRegularExpression rx (pattern);
2777
2788
d->filter_data .setRegularExpression (rx);
2778
- d->filter_changed ();
2789
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2779
2790
}
2780
2791
#endif
2781
2792
@@ -2791,7 +2802,7 @@ void QSortFilterProxyModel::setFilterWildcard(const QString &pattern)
2791
2802
d->filter_about_to_be_changed ();
2792
2803
QRegExp rx (pattern, d->filter_data .caseSensitivity (), QRegExp::Wildcard);
2793
2804
d->filter_data .setRegExp (rx);
2794
- d->filter_changed ();
2805
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2795
2806
}
2796
2807
2797
2808
/* !
@@ -2806,7 +2817,7 @@ void QSortFilterProxyModel::setFilterFixedString(const QString &pattern)
2806
2817
d->filter_about_to_be_changed ();
2807
2818
QRegExp rx (pattern, d->filter_data .caseSensitivity (), QRegExp::FixedString);
2808
2819
d->filter_data .setRegExp (rx);
2809
- d->filter_changed ();
2820
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2810
2821
}
2811
2822
2812
2823
/* !
@@ -2886,7 +2897,7 @@ void QSortFilterProxyModel::setFilterRole(int role)
2886
2897
return ;
2887
2898
d->filter_about_to_be_changed ();
2888
2899
d->filter_role = role;
2889
- d->filter_changed ();
2900
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2890
2901
emit filterRoleChanged (role);
2891
2902
}
2892
2903
@@ -2913,7 +2924,7 @@ void QSortFilterProxyModel::setRecursiveFilteringEnabled(bool recursive)
2913
2924
return ;
2914
2925
d->filter_about_to_be_changed ();
2915
2926
d->filter_recursive = recursive;
2916
- d->filter_changed ();
2927
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows );
2917
2928
emit recursiveFilteringEnabledChanged (recursive);
2918
2929
}
2919
2930
@@ -2964,11 +2975,57 @@ void QSortFilterProxyModel::filterChanged()
2964
2975
(e.g. filterAcceptsRow()), and your filter parameters have changed.
2965
2976
2966
2977
\sa invalidate()
2978
+ \sa invalidateColumnsFilter()
2979
+ \sa invalidateRowsFilter()
2967
2980
*/
2968
2981
void QSortFilterProxyModel::invalidateFilter ()
2969
2982
{
2970
2983
Q_D (QSortFilterProxyModel);
2971
- d->filter_changed ();
2984
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::All);
2985
+ }
2986
+
2987
+ /* !
2988
+ \since 6.0
2989
+
2990
+ Invalidates the current filtering for the columns.
2991
+
2992
+ This function should be called if you are implementing custom filtering
2993
+ (by filterAcceptsColumn()), and your filter parameters have changed.
2994
+ This differs from invalidateFilter() in that it will not invoke
2995
+ filterAcceptsRow(), but only filterAcceptsColumn(). You can use this
2996
+ instead of invalidateFilter() if you want to hide or show a column where
2997
+ the rows don't change.
2998
+
2999
+ \sa invalidate()
3000
+ \sa invalidateFilter()
3001
+ \sa invalidateRowsFilter()
3002
+ */
3003
+ void QSortFilterProxyModel::invalidateColumnsFilter ()
3004
+ {
3005
+ Q_D (QSortFilterProxyModel);
3006
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Columns);
3007
+ }
3008
+
3009
+ /* !
3010
+ \since 6.0
3011
+
3012
+ Invalidates the current filtering for the rows.
3013
+
3014
+ This function should be called if you are implementing custom filtering
3015
+ (by filterAcceptsRow()), and your filter parameters have changed.
3016
+ This differs from invalidateFilter() in that it will not invoke
3017
+ filterAcceptsColumn(), but only filterAcceptsRow(). You can use this
3018
+ instead of invalidateFilter() if you want to hide or show a row where
3019
+ the columns don't change.
3020
+
3021
+ \sa invalidate()
3022
+ \sa invalidateFilter()
3023
+ \sa invalidateColumnsFilter()
3024
+ */
3025
+ void QSortFilterProxyModel::invalidateRowsFilter ()
3026
+ {
3027
+ Q_D (QSortFilterProxyModel);
3028
+ d->filter_changed (QSortFilterProxyModelPrivate::Direction::Rows);
2972
3029
}
2973
3030
2974
3031
/* !
0 commit comments