From c5f64863e3fd5895510a5a890a49114825293812 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Sat, 6 Jan 2001 05:31:13 +0000 Subject: Fixed sorting. needs_sorting was getting set to 0 when sorted happens, but 2001-01-06 Christopher James Lahey * e-table-sorter.c, e-table-sorter.h (ets_sort): Fixed sorting. needs_sorting was getting set to 0 when sorted happens, but needs_sorting tells you whether or not the sorter is sorted or not, not whether the sorting has happened. Documented the needs_sorting variable. svn path=/trunk/; revision=7281 --- widgets/table/e-table-sorter.c | 32 ++------------------------------ widgets/table/e-table-sorter.h | 1 + 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/widgets/table/e-table-sorter.c b/widgets/table/e-table-sorter.c index cf878c56ca..0eb52d42d1 100644 --- a/widgets/table/e-table-sorter.c +++ b/widgets/table/e-table-sorter.c @@ -243,32 +243,6 @@ struct _subinfo { GArray *rowsort; /* an array of row info's */ }; -static int -qsort_callback_complex(const void *data1, const void *data2) -{ - gint row1 = ((struct _rowinfo *)data1)->row; - gint row2 = ((struct _rowinfo *)data2)->row; - int j; - int sort_count = e_table_sort_info_sorting_get_count(ets_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - /* builds the info needed to sort everything */ static struct _subinfo * ets_sort_build_subset(ETableSorter *ets, struct _group_info *groupinfo, int start, int *end) @@ -340,7 +314,7 @@ ets_sort_subset(ETableSorter *ets, struct _subinfo *subinfo, int startoffset) d(printf("sorting subset start %d rows %d\n", startoffset, rowsort->len)); /* first, sort the actual data */ - qsort(rowsort->data, rowsort->len, sizeof(struct _rowinfo), qsort_callback_complex); + qsort(rowsort->data, rowsort->len, sizeof(struct _rowinfo), qsort_callback); /* then put it back in the map table, where appropriate */ offset = startoffset; @@ -401,7 +375,7 @@ ets_sort_by_group (ETableSorter *ets) return; /* get all the rows' sort groups */ - groups = g_malloc(sizeof(struct _group_info) * rows); + groups = g_new(struct _group_info, rows); for (i=0;isource, groups[i].row)); @@ -437,8 +411,6 @@ ets_sort(ETableSorter *ets) if (ets->sorted) return; - ets->needs_sorting = 0; - rows = e_table_model_row_count(ets->source); group_cols = e_table_sort_info_grouping_get_count(ets->sort_info); cols = e_table_sort_info_sorting_get_count(ets->sort_info) + group_cols; diff --git a/widgets/table/e-table-sorter.h b/widgets/table/e-table-sorter.h index 43959a0a93..2f4c5bdf9d 100644 --- a/widgets/table/e-table-sorter.h +++ b/widgets/table/e-table-sorter.h @@ -21,6 +21,7 @@ typedef struct { ETableHeader *full_header; ETableSortInfo *sort_info; + /* If needs_sorting is 0, then model_to_sorted and sorted_to_model are no-ops. */ int needs_sorting; int *sorted; -- cgit v1.2.3