situation
- bt-edit uses gtk_list_store_new in 8 files 18 times together
- for the list-store we need to duplicate data
- we also need to connect to many notify::handlers to keep things in-sync
- often we actually have a GList pointing to GObjects and we want to map the list columns to properties
- sometimes we have a mapping (e.g. type->icon)
- other usecases are a list of structs where the columns map to struct members
- some might need a custom model
list/array of structs
// crash-recover-dialog.c:
// list: name, file_name, timestamp
store=gtk_list_store_new(3,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
// machine-preferences-dialog.c:
// enum: enum value, enum nick
store=gtk_list_store_new(2,G_TYPE_ULONG,G_TYPE_STRING);
// machine-properties-dialog.c:
// preset array: name, comment
store=gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_STRING);
// enum: enum value, enum nick
store=gtk_list_store_new(2,G_TYPE_ULONG,G_TYPE_STRING);
list of objects
// main-page-patterns.c:
// list machine::(name, machine, -> pixbuf)
store=gtk_list_store_new(3,GDK_TYPE_PIXBUF,G_TYPE_STRING,BT_TYPE_MACHINE);
// list pattern::(name, pattern, -> is_used) + filter to hide internal patterns
store=gtk_list_store_new(3,G_TYPE_STRING,BT_TYPE_PATTERN,G_TYPE_BOOLEAN);
// waves wavetable::(name, -> index_as_hex_str)
store=gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_STRING);
// main-page-sequence.c:
// list pattern::(name, pattern, -> is_used) + filter to hide internal patterns
store=gtk_list_store_new(3,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_BOOLEAN);
// main-page-waves.c:
// waves (name, index, index_as_hex)
store=gtk_list_store_new(WAVE_TABLE_CT,G_TYPE_ULONG,G_TYPE_STRING,G_TYPE_STRING);
// list (wavelevels properties)
store=gtk_list_store_new(WAVELEVEL_TABLE_CT,G_TYPE_ULONG,G_TYPE_STRING,G_TYPE_ULONG,G_TYPE_ULONG,G_TYPE_UINT,G_TYPE_LONG,G_TYPE_LONG);
// settings-page-interaction-controller.c:
// list (name, control)
store=gtk_list_store_new(2,G_TYPE_STRING,BTIC_TYPE_CONTROL);
// list (name, device)
store=gtk_list_store_new(2,G_TYPE_STRING,BTIC_TYPE_DEVICE);
complex
// main-page-sequence.c:
// sequence::(index, -> index_str, -> label)
label_menu_store=gtk_list_store_new(3,G_TYPE_ULONG,G_TYPE_STRING,G_TYPE_STRING);
// sequence::( 2D array (sequence-data) of patterns + 1 label column)
store=gtk_list_store_newv(col_ct,store_types);
proper use
// main-page-sequence.c:
// bars-combo
store=gtk_list_store_new(1,G_TYPE_STRING);
// settings-dialog.c:
// settings selection
store=gtk_list_store_new(4,G_TYPE_STRING,G_TYPE_LONG,GDK_TYPE_PIXBUF,G_TYPE_STRING);
idea
objects
store=bt_gobject_list_store_new(1, BT_TYPE_MACHINE, "name");
for (node=list; node; node=g_list_next(node) {
object = (GObject *)(node->data);
bt_object_list_model_append(store, object);
}
- it assumes that each of the list/array item has a gobject of the same type
- it pairs the model columns with object-properties
- the object is always added (and can be queried back later)
- the app has to take care of add/remove activity on the collection (list,array).
current implementation
structs
store=bt_struct_list_store_new(2, G_TYPE_STRING, G_TYPE_ULONG);
for (node=list; node; node=g_list_next(node) {
item = (BtStructItem *)(node->data);
bt_struct_list_model_append(store, iter);
bt_struct_list_model_set(sotore, iter,
COLUMN_NAME, &item->name,
COLUMN_NUMBER, &item->number,
-1);
}
- it assumes that each of the list/array item has a struct of the same type
- it pairs the model columns with struct members
- the whole struct is not referenced
- the app has to take care of add/remove activity on the collection (list,array)
store=bt_struct_list_store_new(2, G_TYPE_STRING, G_STRUCT_OFFSET(BtStructItem,name),G_TYPE_ULONG, G_STRUCT_OFFSET(BtStructItem,number));
for (node=list; node; node=g_list_next(node) {
item = (BtStructItem *)(node->data);
bt_struct_list_model_append(store, item);
}
- here we setup the offsets initialy
- this makes appending easier and allows us also to store the struct for later retrieval
- assumes that the structs are keept