2828#include < QtVersionChecks>
2929
3030#include " global/log.h"
31- #include " global/types/val.h"
3231
3332#include " uicomponents/view/modelutils.h"
3433
@@ -69,22 +68,24 @@ SortFilterProxyModel::SortFilterProxyModel(QObject* parent)
6968 });
7069
7170 auto onSortersChanged = [this ] {
72- SorterValue * sorter = currentSorterValue ();
71+ Sorter * sorter = currentSorter ();
7372 invalidate ();
7473
7574 if (!sorter) {
75+ sort (-1 , Qt::AscendingOrder);
7676 return ;
7777 }
7878
79- if (sourceModel ()) {
80- sort (0 , sorter->sortOrder ());
81- }
79+ sort (0 , sorter->sortOrder ());
8280 };
8381
8482 connect (m_sorters.notifier (), &QmlListPropertyNotifier::appended, this , [this , onSortersChanged](int index) {
85- onSortersChanged ();
83+ Sorter* sorter = m_sorters.at (index);
84+ if (sorter->enabled ()) {
85+ onSortersChanged ();
86+ }
8687
87- connect (m_sorters. at (index) , &SorterValue ::dataChanged, this , onSortersChanged);
88+ connect (sorter , &Sorter ::dataChanged, this , onSortersChanged);
8889 });
8990
9091 connect (this , &SortFilterProxyModel::sourceModelRoleNamesChanged, this , [this ]() {
@@ -97,7 +98,7 @@ QQmlListProperty<Filter> SortFilterProxyModel::filters()
9798 return m_filters.property ();
9899}
99100
100- QQmlListProperty<SorterValue > SortFilterProxyModel::sorters ()
101+ QQmlListProperty<Sorter > SortFilterProxyModel::sorters ()
101102{
102103 return m_sorters.property ();
103104}
@@ -194,23 +195,18 @@ bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& so
194195
195196bool SortFilterProxyModel::lessThan (const QModelIndex& left, const QModelIndex& right) const
196197{
197- SorterValue * sorter = currentSorterValue ();
198+ Sorter * sorter = currentSorter ();
198199 if (!sorter) {
199- return false ;
200+ return left < right ;
200201 }
201202
202- int sorterRoleKey = roleIdFromName (sorter->roleName ());
203-
204- Val leftData = Val::fromQVariant (sourceModel ()->data (left, sorterRoleKey));
205- Val rightData = Val::fromQVariant (sourceModel ()->data (right, sorterRoleKey));
206-
207- return leftData < rightData;
203+ return sorter->lessThan (left, right, *this );
208204}
209205
210- SorterValue * SortFilterProxyModel::currentSorterValue () const
206+ Sorter * SortFilterProxyModel::currentSorter () const
211207{
212- QList<SorterValue *> sorterList = m_sorters.list ();
213- for (SorterValue * sorter : std::as_const ( sorterList) ) {
208+ const QList<Sorter *> sorterList = m_sorters.list ();
209+ for (Sorter * sorter : sorterList) {
214210 if (sorter->enabled ()) {
215211 return sorter;
216212 }
0 commit comments