tree model sort: Fix set_sort_column

We were failing to change the sort order for the
default sort column in some cases. Fix that, and
add a testcase for this issue.

https://bugzilla.gnome.org/show_bug.cgi?id=792459

Add a testcase for the previous fix
This commit is contained in:
Matthias Clasen 2018-01-16 18:16:21 -05:00
parent 42369e31e2
commit e2f3b9b1cc
2 changed files with 92 additions and 11 deletions

View File

@ -1684,6 +1684,9 @@ gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable;
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
if (priv->sort_column_id == sort_column_id && priv->order == order)
return;
if (sort_column_id != GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID)
{
if (sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
@ -1699,17 +1702,6 @@ gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
}
else
g_return_if_fail (priv->default_sort_func != NULL);
if (priv->sort_column_id == sort_column_id)
{
if (sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
{
if (priv->order == order)
return;
}
else
return;
}
}
priv->sort_column_id = sort_column_id;

View File

@ -1202,6 +1202,93 @@ specific_bug_698846 (void)
g_assert_cmpuint (count, ==, 2);
}
static int
sort_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer data)
{
return 0;
}
static int column_changed;
static void
sort_column_changed (GtkTreeSortable *sortable)
{
column_changed++;
}
static void
sort_column_change (void)
{
GtkListStore *store;
GtkTreeModel *sorted;
int col;
GtkSortType order;
gboolean ret;
g_test_bug ("792459");
store = gtk_list_store_new (1, G_TYPE_STRING);
sorted = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
column_changed = 0;
g_signal_connect (sorted, "sort-column-changed", G_CALLBACK (sort_column_changed), NULL);
g_assert (!gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (sorted)));
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sorted), sort_func, NULL, NULL);
g_assert (gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (sorted)));
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sorted), 0, sort_func, NULL, NULL);
ret = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (sorted), &col, &order);
g_assert (column_changed == 0);
g_assert (ret == FALSE);
g_assert (col == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID);
g_assert (order == GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sorted),
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_DESCENDING);
ret = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (sorted), &col, &order);
g_assert (column_changed == 1);
g_assert (ret == FALSE);
g_assert (col == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID);
g_assert (order == GTK_SORT_DESCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sorted),
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_DESCENDING);
ret = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (sorted), &col, &order);
g_assert (column_changed == 1);
g_assert (ret == FALSE);
g_assert (col == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID);
g_assert (order == GTK_SORT_DESCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sorted),
0, GTK_SORT_DESCENDING);
ret = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (sorted), &col, &order);
g_assert (column_changed == 2);
g_assert (ret == TRUE);
g_assert (col == 0);
g_assert (order == GTK_SORT_DESCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sorted),
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
ret = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (sorted), &col, &order);
g_assert (column_changed == 3);
g_assert (ret == FALSE);
g_assert (col == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID);
g_assert (order == GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sorted),
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
ret = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (sorted), &col, &order);
g_assert (column_changed == 4);
g_assert (ret == FALSE);
g_assert (col == GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID);
g_assert (order == GTK_SORT_ASCENDING);
}
/* main */
void
@ -1239,5 +1326,7 @@ register_sort_model_tests (void)
specific_bug_674587);
g_test_add_func ("/TreeModelSort/specific/bug-698846",
specific_bug_698846);
g_test_add_func ("/TreeModelSort/specific/bug-792459",
sort_column_change);
}