Changeset View
Changeset View
Standalone View
Standalone View
src/browsers/CollectionSortFilterProxyModel.cpp
Show All 18 Lines | |||||
19 | #include "CollectionSortFilterProxyModel.h" | 19 | #include "CollectionSortFilterProxyModel.h" | ||
20 | 20 | | |||
21 | #include "amarokconfig.h" | 21 | #include "amarokconfig.h" | ||
22 | #include "browsers/CollectionTreeItem.h" | 22 | #include "browsers/CollectionTreeItem.h" | ||
23 | #include "core/meta/Meta.h" | 23 | #include "core/meta/Meta.h" | ||
24 | #include "core/support/Debug.h" | 24 | #include "core/support/Debug.h" | ||
25 | #include "widgets/PrettyTreeRoles.h" | 25 | #include "widgets/PrettyTreeRoles.h" | ||
26 | 26 | | |||
27 | #include <kstringhandler_deprecated.h> //TODO KF5: Take care of this when moving to QCollator from KStringHandler::naturalCompare() | 27 | #include <QCollator> | ||
28 | | ||||
29 | #include <QVariant> | 28 | #include <QVariant> | ||
30 | #include <QString> | 29 | #include <QString> | ||
31 | 30 | | |||
32 | CollectionSortFilterProxyModel::CollectionSortFilterProxyModel( QObject * parent ) | 31 | CollectionSortFilterProxyModel::CollectionSortFilterProxyModel( QObject * parent ) | ||
33 | : QSortFilterProxyModel( parent ) | 32 | : QSortFilterProxyModel( parent ) | ||
33 | , m_col( new QCollator ) | ||||
34 | { | 34 | { | ||
35 | setSortLocaleAware( true ); | 35 | setSortLocaleAware( true ); | ||
36 | 36 | | |||
37 | setSortRole( PrettyTreeRoles::SortRole ); | 37 | setSortRole( PrettyTreeRoles::SortRole ); | ||
38 | setFilterRole( PrettyTreeRoles::FilterRole ); | 38 | setFilterRole( PrettyTreeRoles::FilterRole ); | ||
39 | setSortCaseSensitivity( Qt::CaseInsensitive ); | 39 | setSortCaseSensitivity( Qt::CaseInsensitive ); | ||
40 | setFilterCaseSensitivity( Qt::CaseInsensitive ); | 40 | setFilterCaseSensitivity( Qt::CaseInsensitive ); | ||
41 | 41 | | |||
42 | setDynamicSortFilter( true ); | 42 | setDynamicSortFilter( true ); | ||
43 | | ||||
44 | m_col->setCaseSensitivity( Qt::CaseInsensitive ); | ||||
43 | } | 45 | } | ||
44 | 46 | | |||
45 | 47 | | |||
46 | CollectionSortFilterProxyModel::~CollectionSortFilterProxyModel() | 48 | CollectionSortFilterProxyModel::~CollectionSortFilterProxyModel() | ||
47 | { | 49 | { | ||
50 | delete m_col; | ||||
48 | } | 51 | } | ||
49 | 52 | | |||
50 | bool | 53 | bool | ||
51 | CollectionSortFilterProxyModel::hasChildren(const QModelIndex & parent) const | 54 | CollectionSortFilterProxyModel::hasChildren(const QModelIndex & parent) const | ||
52 | { | 55 | { | ||
53 | QModelIndex sourceParent = mapToSource(parent); | 56 | QModelIndex sourceParent = mapToSource(parent); | ||
54 | return sourceModel()->hasChildren(sourceParent); | 57 | return sourceModel()->hasChildren(sourceParent); | ||
55 | } | 58 | } | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 98 | { | |||
103 | if( leftTrack->trackNumber() < rightTrack->trackNumber() ) | 106 | if( leftTrack->trackNumber() < rightTrack->trackNumber() ) | ||
104 | return true; | 107 | return true; | ||
105 | if( leftTrack->trackNumber() > rightTrack->trackNumber() ) | 108 | if( leftTrack->trackNumber() > rightTrack->trackNumber() ) | ||
106 | return false; | 109 | return false; | ||
107 | } | 110 | } | ||
108 | 111 | | |||
109 | // compare by name | 112 | // compare by name | ||
110 | { | 113 | { | ||
111 | int comp = KStringHandler::naturalCompare( leftTrack->sortableName(), rightTrack->sortableName(), Qt::CaseInsensitive ); | 114 | int comp = m_col->compare( leftTrack->sortableName(), rightTrack->sortableName() ); | ||
112 | if( comp < 0 ) | 115 | if( comp < 0 ) | ||
113 | return true; | 116 | return true; | ||
114 | if( comp > 0 ) | 117 | if( comp > 0 ) | ||
115 | return false; | 118 | return false; | ||
116 | } | 119 | } | ||
117 | 120 | | |||
118 | return leftTrack.data() < rightTrack.data(); // prevent expanded tracks from switching places (if that ever happens) | 121 | return leftTrack.data() < rightTrack.data(); // prevent expanded tracks from switching places (if that ever happens) | ||
119 | } | 122 | } | ||
Show All 21 Lines | 140 | { | |||
141 | if( leftYear < rightYear ) | 144 | if( leftYear < rightYear ) | ||
142 | return false; // left album is newer | 145 | return false; // left album is newer | ||
143 | if( leftYear > rightYear ) | 146 | if( leftYear > rightYear ) | ||
144 | return true; | 147 | return true; | ||
145 | } | 148 | } | ||
146 | 149 | | |||
147 | // compare by name | 150 | // compare by name | ||
148 | { | 151 | { | ||
149 | int comp = KStringHandler::naturalCompare( leftAlbum->sortableName(), rightAlbum->sortableName(), Qt::CaseInsensitive ); | 152 | int comp = m_col->compare( leftAlbum->sortableName(), rightAlbum->sortableName() ); | ||
150 | if( comp < 0 ) | 153 | if( comp < 0 ) | ||
151 | return true; | 154 | return true; | ||
152 | if( comp > 0 ) | 155 | if( comp > 0 ) | ||
153 | return false; | 156 | return false; | ||
154 | } | 157 | } | ||
155 | 158 | | |||
156 | return leftAlbum.data() < rightAlbum.data(); // prevent expanded albums from switching places | 159 | return leftAlbum.data() < rightAlbum.data(); // prevent expanded albums from switching places | ||
157 | } | 160 | } | ||
Show All 9 Lines | 169 | { | |||
167 | DEBUG_BLOCK | 170 | DEBUG_BLOCK | ||
168 | error() << "Should never have compared these two indexes" | 171 | error() << "Should never have compared these two indexes" | ||
169 | << left.data(Qt::DisplayRole) << "and" << right.data(Qt::DisplayRole); | 172 | << left.data(Qt::DisplayRole) << "and" << right.data(Qt::DisplayRole); | ||
170 | return QSortFilterProxyModel::lessThan( left, right ); | 173 | return QSortFilterProxyModel::lessThan( left, right ); | ||
171 | } | 174 | } | ||
172 | 175 | | |||
173 | // compare by name | 176 | // compare by name | ||
174 | { | 177 | { | ||
175 | int comp = KStringHandler::naturalCompare( leftData->sortableName(), rightData->sortableName(), Qt::CaseInsensitive ); | 178 | int comp = m_col->compare( leftData->sortableName(), rightData->sortableName() ); | ||
176 | if( comp < 0 ) | 179 | if( comp < 0 ) | ||
177 | return true; | 180 | return true; | ||
178 | if( comp > 0 ) | 181 | if( comp > 0 ) | ||
179 | return false; | 182 | return false; | ||
180 | } | 183 | } | ||
181 | 184 | | |||
182 | return leftData.data() < rightData.data(); // prevent expanded data from switching places | 185 | return leftData.data() < rightData.data(); // prevent expanded data from switching places | ||
183 | } | 186 | } | ||
Show All 23 Lines |