diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-21 01:00:56 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-21 01:00:56 +0200 |
commit | daa8040b5045dd282945bccef3a3f06c85595389 (patch) | |
tree | 410a6707534b4328ea01279c6b3e23dcb09883cf /src/corelib/itemmodels | |
parent | 5e9b2ade678f37e43bfc2e3484f54cbbb5844d2e (diff) | |
parent | 84db112fe2c175a6e0351b5672b87f1425f30c3e (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I642be6de9ef32491b09db97185146c671266240e
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 675bf4b8c3..978102035e 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -377,6 +377,7 @@ public: void sort(); bool update_source_sort_column(); + int find_source_sort_column() const; void sort_source_rows(QVector<int> &source_rows, const QModelIndex &source_parent) const; QVector<QPair<int, QVector<int > > > proxy_intervals_for_source_items_to_add( @@ -479,11 +480,8 @@ void QSortFilterProxyModelPrivate::_q_clearMapping() qDeleteAll(source_index_mapping); source_index_mapping.clear(); - if (dynamic_sortfilter && update_source_sort_column()) { - //update_source_sort_column might have created wrong mapping so we have to clear it again - qDeleteAll(source_index_mapping); - source_index_mapping.clear(); - } + if (dynamic_sortfilter) + source_sort_column = find_source_sort_column(); // update the persistent indexes update_persistent_indexes(source_indexes); @@ -640,6 +638,31 @@ bool QSortFilterProxyModelPrivate::update_source_sort_column() return old_source_sort_column != source_sort_column; } +/*! + \internal + + Find the source_sort_column without creating a full mapping and + without updating anything. +*/ +int QSortFilterProxyModelPrivate::find_source_sort_column() const +{ + if (proxy_sort_column == -1) + return -1; + + const QModelIndex rootIndex; + const int source_cols = model->columnCount(); + int accepted_columns = -1; + + Q_Q(const QSortFilterProxyModel); + for (int i = 0; i < source_cols; ++i) { + if (q->filterAcceptsColumn(i, rootIndex)) { + if (++accepted_columns == proxy_sort_column) + return i; + } + } + + return -1; +} /*! \internal @@ -1591,11 +1614,8 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersisten update_persistent_indexes(saved_persistent_indexes); saved_persistent_indexes.clear(); - if (dynamic_sortfilter && update_source_sort_column()) { - //update_source_sort_column might have created wrong mapping so we have to clear it again - qDeleteAll(source_index_mapping); - source_index_mapping.clear(); - } + if (dynamic_sortfilter) + source_sort_column = find_source_sort_column(); emit q->layoutChanged(saved_layoutChange_parents); saved_layoutChange_parents.clear(); |