problems with GtkTreeModelSort



Hy,

I am trying to implement improved sorting in gtodo using the GtkTreeModelSort
but I have some problems with it.
(It goes wrong on gtk+-2.2.4 and Gtk+-2.3)

I do the following:
(mw.list is a GtkListStore)

mw.sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(mw. list)); mw.treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(mw. sortmodel));


I add columns to the tree view then I set a default sort function:

gtk_tree_sortable_set_default_sort_func((GtkTreeSortable *)mw. sortmodel,
(GtkTreeIterCompareFunc)sort_function_test, NULL, NULL);

where sort_function_test is the following function
(function is/looks a bit crappy because I changed it alot)

gint sort_function_test(GtkTreeModel *model,GtkTreeIter *a,GtkTreeIter *b,
gpointer user_data)
  {
        gint prioritya=0, priorityb=0;
        gint donea=0, doneb=0;
        guint32 datea=0, dateb=0;
        gchar *sum1, *sum2;
        if(a == NULL || b == NULL) return 0;
        
        gtk_tree_model_get(model,a, DONE, &donea, PRIORITY, &prioritya,
END_DATE, &datea, -1);
        gtk_tree_model_get(model,b, DONE, &doneb, PRIORITY, &priorityb,
END_DATE, &dateb, -1);      

        if(donea == 1 && doneb == 0) return -1;
        if(donea == 0 && doneb == 1) return 1;
        if(datea < dateb) return -1;
        if(datea > dateb) return 1;
        if(prioritya < priorityb) return -1;
        if(prioritya > priorityb) return 1;  
        return 0;
        }
        
        return 0;
        }

But the "sorted" results doesnt make any sence.
I fill the list by calling gtk_list_store_append and after that multiple times
gtk_list_store_set.
it calls the sort function (atleast it looks that way) sometimes after a gtk_list_store_set. Is there a way to stop this? I think most of my problems
are caused by this.
(it tries to sort with data not yet entered in the list store.)

it crashes from time to time (mostly on gtk+-2.3) if I use gdb I get the
following:



Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 15902)]
0x4006a148 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
(gdb) up
#1  0x4019e61d in gtk_tree_model_sort_level_find_insert (
tree_model_sort=0x808ade8, level=0x8150338, iter=0xbffff07c, skip_index=2)
  at gtktreemodelsort.c:1732
        in gtktreemodelsort.c
(gdb) up
#2 0x4019e720 in gtk_tree_model_sort_insert_value (tree_model_sort=0x808ade8,
  level=0x8150338, s_path=0x80789d0, s_iter=0xbffff07c)
  at gtktreemodelsort.c:1780
1780    in gtktreemodelsort.c
(gdb)
#3  0x4019c860 in gtk_tree_model_sort_row_inserted (s_model=0x80cf460,
  s_path=0x81519f8, s_iter=0x81519f8, data=0x808ade8)
  at gtktreemodelsort.c:692
692     in gtktreemodelsort.c
(gdb)
#4  0x4010962f in _gtk_marshal_VOID__BOXED_BOXED (closure=0x80d0960,
  return_value=0x0, n_param_values=3, param_values=0xbffff270,
invocation_hint=0xbffff188, marshal_data=0x0) at gtkmarshalers. c:1028
        in gtkmarshalers.c
(gdb)
#5 0x404ac94e in g_closure_invoke (closure=0x80d0960, return_value=0x0, n_param_values=3, param_values=0xbffff270, invocation_hint=0xbffff188)
  at gclosure.c:437
        in gclosure.c
(gdb)
#6  0x404bbf7c in signal_emit_unlocked_R (node=0x80c9da0, detail=0,
instance=0x80cf460, emission_return=0x0, instance_and_params=0xbffff270)
  at gsignal.c:2436
        in gsignal.c
(gdb)
#7 0x404bb58d in g_signal_emit_valist (instance=0x80cf460, signal_id=0,
  detail=0,
var_args=0xbffff3f4 "¬©&@ø\002\025\b`ô\f\b,ôÿ¿B4\020 `ô\f\bø\002\025 \bdôÿ¿ø
\002\025\b\002") at gsignal.c:2195
2195    in gsignal.c
(gdb)
#8 0x404bb7aa in g_signal_emit (instance=0x80cf460, signal_id=112, detail=0)
  at gsignal.c:2239
2239    in gsignal.c
(gdb)
#9  0x40197611 in gtk_tree_model_row_inserted (tree_model=0x80cf460,
  path=0x81502f8, iter=0xbffff464) at gtktreemodel.c:1347
        in gtktreemodel.c
(gdb)
#10 0x40103442 in gtk_list_store_append (list_store=0x80cf460,
iter=0xbffff464)
  at gtkliststore.c:1346
        in gtkliststore.c

This is making me believe that the problem is it tries to sort before all the
information is entered. is there a way for me to block this?
or a better way todo sorting?

Thanks alot,

Qball



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]