Data definition:GtkListStore
- From: "William Walter" <wwalterw gmail com>
- To: gtk-list gnome org
- Subject: Data definition:GtkListStore
- Date: Sat, 31 Mar 2007 16:57:45 -0400
May be i'm overlooking the obvious explanation for this but I can't find the answer.
Gtk+ source code folder(../gtk+-2.8.10/demos/gtk-demo) has a demo program
editable_cells.c. It displays total number of products, product name and taste level
(yummy) in a treeview widget. So the program uses GtkCellRendererCombo for the
first column, GtkCellRendererText for second and GtkCellRendererCombo for the
third . It declares the list store(model) for the treeview widget and add the data
to the model like this:
.............
enum
{
COLUMN_ITEM_NUMBER,
COLUMN_ITEM_PRODUCT,
COLUMN_ITEM_YUMMY,
NUM_ITEM_COLUMNS
};
static GArray *articles = NULL;
static void
add_items (void)
{
Item foo;
g_return_if_fail (articles != NULL);
foo.number = 3;
foo.product = g_strdup ("bottles of coke");
foo.yummy = 20;
g_array_append_vals (articles, &foo, 1);
foo.number = 5;
foo.product = g_strdup ("packages of noodles");
foo.yummy = 50;
g_array_append_vals (articles, &foo, 1);
foo.number = 2;
foo.product = g_strdup ("packages of chocolate chip cookies");
foo.yummy = 90;
g_array_append_vals (articles, &foo, 1);
foo.number = 1;
foo.product = g_strdup ("can vanilla ice cream");
foo.yummy = 60;
g_array_append_vals (articles, &foo, 1);
foo.number = 6;
foo.product = g_strdup ("eggs");
foo.yummy = 10;
g_array_append_vals (articles, &foo, 1);
}
static GtkTreeModel *
create_items_model (void)
{
gint i = 0;
GtkListStore *model;
GtkTreeIter iter;
/* create array */
articles = g_array_sized_new (FALSE, FALSE, sizeof (Item), 1);
add_items ();
/* create list store */
model = gtk_list_store_new (NUM_ITEM_COLUMNS, G_TYPE_INT, G_TYPE_STRING,
G_TYPE_INT, G_TYPE_BOOLEAN); //<--why G_TYPE_BOOLEAN is used here?
/* add items */
for (i = 0; i < articles->len; i++)
{
gtk_list_store_append (model, &iter);
gtk_list_store_set (model, &iter,
COLUMN_ITEM_NUMBER,
g_array_index (articles, Item, i).number,
COLUMN_ITEM_PRODUCT,
g_array_index (articles, Item, i).product,
COLUMN_ITEM_YUMMY,
g_array_index (articles, Item, i).yummy,
-1);
}
return GTK_TREE_MODEL (model);
}
.....
what's the use of fourth column(G_TYPE_BOOLEAN) used during the definition of
treeview model? You can see that no data is associated with this column. so why
use it?
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]