After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 792459 - gtk_tree_model_sort_set_sort_column_id() ignores change to sort order
gtk_tree_model_sort_set_sort_column_id() ignores change to sort order
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.22.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2018-01-12 11:29 UTC by Karas
Modified: 2018-01-17 09:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Suggested fix (354 bytes, patch)
2018-01-12 11:29 UTC, Karas
none Details | Review

Description Karas 2018-01-12 11:29:28 UTC
Created attachment 366722 [details] [review]
Suggested fix

The following code snippet fails to change the sort order from the default GTK_SORT_ASCENDING to GTK_SORT_DESCENDING.

=== Begin ===
GtkTreeModel *sorted = gtk_tree_model_sort_new_with_model(my_model);

gtk_tree_sortable_set_default_sort_func(
    GTK_TREE_SORTABLE(GTK_TREE_MODEL_SORT(sorted)),
    my_sort_func, NULL, NULL);

gtk_tree_sortable_set_sort_column_id(
    GTK_TREE_SORTABLE(GTK_TREE_MODEL_SORT(sorted)),
    GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
    GTK_SORT_DESCENDING);
=== End ===

This is due to a bug in gtk_tree_model_sort_set_sort_column_id(). The function returns without updating sort order when:
1) there is no change to column ID, and
2) column ID is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID.

A work-around is to call gtk_tree_sortable_set_sort_column_id() twice. First time to set sort order by using a dummy column ID (e.g. the value zero), and then a second time with the values you want applied.

Patch with suggested fix is attached.

Reviewing the master branch showed the bug is present there too.
Comment 1 Karas 2018-01-12 11:36:31 UTC
Well, it turns out the work-around only works so far as to get the sort order set. However, the GtkTreeModelSort object does not use the sort order, when there is a user supplied sort function as in the example in previous comment.

So maybe it is per design? If so, it is different behavior than how GtkListStore behaves. The GtkListStore does not suffer from either issue.
Comment 2 Matthias Clasen 2018-01-16 23:22:57 UTC
Pushed a slightly different fix and a testcase. Thanks