分类: LINUX
2015-03-18 10:21:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
GtkListStore *store;
.................
//第1列
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(NULL,renderer,"text",0,NULL);
gtk_tree_view_column_set_min_width(column,130);
gtk_tree_view_column_set_resizable(column,TRUE);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),column);
//FIXME:排序设置 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store),0,obtable_tree_sort,NULL,NULL);
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),0,GTK_SORT_ASCENDING);//按值升序排列
gtk_tree_view_set_model(treeview,GTK_TREE_MODEL(store));
//FIXME:数字型字符串的大小比较,用于排序
static gint obtable_text_number_sort(const gchar *text_a,const gchar *text_b)
{
gint retval = 0;
if(text_a == NULL && text_b == NULL)
retval = 0;
else if(text_a == NULL) retval = -1;
else if(text_b == NULL) retval = 1;
else {
double a;
double b;
a = atof(text_a);
b = atof(text_b);
//retval = strcasecmp(text_a,text_b);
retval = a-b;
}
return retval;
}
//FIXME:3列数据排序的函数static
gint obtable_tree_sort(GtkTreeModel *model,GtkTreeIter *a,GtkTreeIter *b,gpointer user_data)
{
const gchar *text_a;
const gchar *text_b;
gtk_tree_model_get(model,a,0,&text_a,-1);
gtk_tree_model_get(model,b,0,&text_b,-1);
return obtable_text_number_sort(text_a,text_b);
}
|