Skip to content

Commit 07e45b0

Browse files
authored
Merge pull request #7 from micuintus/master
Add a `reSort()` function to the Collection.
2 parents 645e579 + 0da374b commit 07e45b0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Return the jsobject that has the id specified by 'id'.
119119

120120
## Collection
121121

122-
An item for sorting an filtering a JsonListModel. The Collection itself does not
122+
An item for sorting and filtering a JsonListModel. The Collection itself does not
123123
store any data, but rather proxies the data stored inside the source model.
124124

125125
### model : JsonListModel
@@ -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)