Re: user-defined data types & GtkListStore



On Fri, 2003-04-11 at 15:07, Bryan Kubishta wrote:

> I saw the suggestion in the archives about puting everything in a single
> column, and even considered it for the sake of efficiency.  But the
> convenience of having GTK handle sorting by specific columns is so nice, so
> I dropped the idea.  The GTypes of my columns can be different every time
> the program runs, (each column maps to whatever type happens to be in the
> database table currently being viewed) so I didn't want to tackle the
> sorting using my own structure.  TreeViews and ListStores _almost_ gave a
> perfect framework for this.

Use:

gtk_tree_sortable_set_sort_func (store, column, compare_rows,
                                 GUINT_TO_POINTER (column), NULL);

for each column of your database table.

int
compare_rows (GtkTreeModel *model,
              GtkTreeIter  *a,
              GtkTreeIter  *b,
              gpointer      user_data)

 int column = GPOINTER_TO_UINT (user_data);
 MyRow *row_a, row_b;

 gtk_tree_model_get (model, DATA_COLUMN, a, &row_a, -1);
 gtk_tree_model_get (model, DATA_COLUMN, b, &row_b, -1);
 
 return compare_cells (row_a->cells[column], row_b->cells[column]);
}

You get the the idea.

Presumably you'd need a custom compare function anyways for your
custom date type; you might as well make things consistent for
all data types.

> But along the same lines of performance, I noticed that each column of data
> is stored in an individual linked list.  I've got all my data stored
> row-by-row instead of column-by-column.  Can anyone here verify that there's
> a significant speedup by storing data grouped by column instead of row?

Check again, it's one linked list per row.

> Also I noticed that the renderer gets called for all tree_view cells,
> regardless of whether they are visible to the user or outside the bounds of
> the tree_view.  Is there a simple way to eliminate this waste, or am I doing
> something wrong?

The TreeView has to go over all rows to measure their size to know
how big to make the scrollbars. Nothing is drawn for rows outside
the bounds of the treeview.

Regards,
                                         Owen






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