Re: Columns vs fields in GtkTreeView
- From: Murray Cumming <murrayc murrayc com>
- To: Dave Malcolm <david davemalcolm demon co uk>
- Cc: gtk-devel-list <gtk-devel-list gnome org>
- Subject: Re: Columns vs fields in GtkTreeView
- Date: Sat, 14 Feb 2004 17:14:30 +0100
On Wed, 2004-02-11 at 02:30, Dave Malcolm wrote:
> I couldn't see this in the archives, so here goes:
>
> I believe that the current tree/list API is unnecessarily hard to
> understand because of the potential for confusion between columns in the
> view and columns in the model.
This is a bit easier in gtkmm, because we have Gtk::TreeModel::Column
objects that store the type and index.
I also try to always write "model column" and "view column" in the docs,
and never just "column" to avoid confusion.
> So I propose that the "columns" in the model (and the various store
> classes) get renamed to "field".
I think that would just make things more difficult, personally.
> That way "columns" only refers to
> columns in the view. I've been using this in my own code, and it
> clarifies things when you have more than one column in the model per
> column in the view, and when you have "hidden columns" - it's suddenly a
> lot clearer that these two concepts called "column" aren't the same
> thing.
>
> Obviously this would be a pain of an API change (maybe for GTK 3?). So,
> as a simpler change, we could merely update the docs and sample code to
> use this terminology.
>
> Here's the sample code from the docs adapted to use the proposed new
> terminology:
>
> enum
> {
> TITLE_FIELD,
> AUTHOR_FIELD,
> CHECKED_FIELD,
> N_FIELDS
> };
>
> void
> populate_tree_model (GtkTreeStore *store)
> {
> GtkTreeIter iter1; /* Parent iter */
> GtkTreeIter iter2; /* Child iter */
>
> gtk_tree_store_append (store, &iter1, NULL); /* Acquire a top-level iterator */
> gtk_tree_store_set (store, &iter1,
> TITLE_FIELD, "The Art of Computer Programming",
> AUTHOR_FIELD, "Donald E. Knuth",
> CHECKED_FIELD, FALSE,
> -1);
>
> gtk_tree_store_append (store, &iter2, &iter1); /* Acquire a child iterator */
> gtk_tree_store_set (store, &iter2,
> TITLE_FIELD, "Volume 1: Fundamental Algorithms",
> -1);
>
> gtk_tree_store_append (store, &iter2, &iter1);
> gtk_tree_store_set (store, &iter2,
> TITLE_FIELD, "Volume 2: Seminumerical Algorithms",
> -1);
>
> gtk_tree_store_append (store, &iter2, &iter1);
> gtk_tree_store_set (store, &iter2,
> TITLE_FIELD, "Volume 3: Sorting and Searching",
> -1);
> }
>
> void
> setup_tree (void)
> {
> GtkTreeStore *store;
> GtkWidget *tree;
> GtkTreeViewColumn *column;
> GtkCellRenderer *renderer;
>
> /* Create a model. We are using the store model for now, though we
> * could use any other GtkTreeModel */
> store = gtk_tree_store_new (N_FIELDS,
> G_TYPE_STRING,
> G_TYPE_STRING,
> G_TYPE_BOOLEAN);
>
> /* custom function to fill the model with data */
> populate_tree_model (store);
>
> /* Create a view */
> tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
>
> /* The view now holds a reference. We can get rid of our own
> * reference */
> g_object_unref (G_OBJECT (store));
>
> /* Create a cell render and arbitrarily make it red for demonstration
> * purposes */
> renderer = gtk_cell_renderer_text_new ();
> g_object_set (G_OBJECT (renderer),
> "foreground", "red",
> NULL);
>
> /* Create a column, associating the "text" attribute of the
> * cell_renderer to the first field of the model */
> column = gtk_tree_view_column_new_with_attributes ("Author", renderer,
> "text", AUTHOR_FIELD,
> NULL);
>
> /* Add the column to the view. */
> gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
>
> /* Second column.. title of the book. */
> renderer = gtk_cell_renderer_text_new ();
> column = gtk_tree_view_column_new_with_attributes ("Title",
> renderer,
> "text", TITLE_FIELD,
> NULL);
> gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
>
> /* Last column.. whether a book is checked out. */
> renderer = gtk_cell_renderer_toggle_new ();
> column = gtk_tree_view_column_new_with_attributes ("Checked out",
> renderer,
> "active", CHECKED_FIELD,
> NULL);
> gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
>
> /* Now we can manipulate the view just like any other GTK widget */
> ...
> }
>
> Thoughts? Do other people think this is better? Should I make a patch for the docs and samples?
>
>
>
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
--
Murray Cumming
www.murrayc.com
murrayc murrayc com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]