Skip to content

Commit 92ec99f

Browse files
committed
Add a function 'reSort()' to 'Collection',
which can be called from QML, as well. The function 'reSort()' triggers sorting the collection again. Calling it is *not* required if data within the model itself has changed (re-sorting will be conducted automatically in that case). You want to call this function if external data has been updated, e.g. you sort a model by distance and the current position of the user has changed.
1 parent 645e579 commit 92ec99f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ function should return true for items that should be included; otherwise false.
164164
Return the jsobject at the index specified by the number. If Collection is sorted or filtered, then
165165
the index here refers to the index in the Collection *not* the JsonListModel.
166166

167+
### reSort() : function
168+
169+
Trigger sorting the collection again.
170+
171+
**NOTE** Calling this function is *not* required if data within the model itself has changed
172+
(re-sorting will be conducted automatically in that case). You want to call this function if
173+
external data has been updated, e.g. you sort a model by distance and the current position
174+
of the user has changed.
175+
167176
### descendingSort : property bool: false
168177

169178
Indicates if the role based sorting is sorted in ascending or descending order.

collection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,8 @@ QJSValue Collection::at(int row) const
115115
return jsonModel->at(source.row());
116116
}
117117

118+
void Collection::reSort()
119+
{
120+
sort(0);
121+
}
122+

collection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Collection : public QSortFilterProxyModel
2626

2727
Q_INVOKABLE QJSValue at(int) const;
2828

29+
Q_INVOKABLE void reSort();
30+
2931
inline bool caseSensitiveSort() const
3032
{
3133
return sortCaseSensitivity() == Qt::CaseSensitive;

0 commit comments

Comments
 (0)