From 27274b95df69ef3f24710e928f1b8873e2e7571b Mon Sep 17 00:00:00 2001 From: pmf Date: Tue, 27 Nov 2007 16:43:35 +0000 Subject: [PATCH] resourceview: collapse pixmaps when collapsing branches in the resource tree, and refine resource API git-svn-id: http://ltt.polymtl.ca/svn@2773 04897980-b3bd-0310-b5e0-8ef037075253 --- .../poly/lttv/modules/gui/resourceview/cfv.c | 5 + .../modules/gui/resourceview/processlist.c | 115 +++++++++++++++++- .../modules/gui/resourceview/processlist.h | 22 ++-- 3 files changed, 128 insertions(+), 14 deletions(-) diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/cfv.c b/ltt/branches/poly/lttv/modules/gui/resourceview/cfv.c index 5ab74bbd..183be8bb 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/cfv.c +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/cfv.c @@ -235,6 +235,11 @@ resourceview(LttvPluginTab *ptab) "resourceview_data", control_flow_data); + g_object_set_data( + G_OBJECT(control_flow_data->process_list->process_list_widget), + "resourceview_data", + control_flow_data); + g_control_flow_data_list = g_slist_append( g_control_flow_data_list, plugin_cfv); diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c index dd133914..03c83825 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.c @@ -106,6 +106,77 @@ gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) return TRUE; } +void expand_event(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *arg2, gpointer user_data) +{ + ControlFlowData *resourceview_data = + (ControlFlowData*)g_object_get_data( + G_OBJECT(treeview), + "resourceview_data"); + ProcessList *process_list = (ProcessList *) user_data; + ResourceUnique *rup; + HashedResourceData *hrd; + gboolean result; + + GtkTreeModel *model; + GtkTreeIter child; + + /* Determine which trace has been expanded */ + model = gtk_tree_view_get_model(treeview); + + /* mark each of the trace's resources invisible */ + result = gtk_tree_model_iter_children(model, &child, iter); + + /* for each child of the collapsed row */ + while(result) { + /* hide the item */ + gtk_tree_model_get(model, &child, DATA_COLUMN, &hrd, -1); + hrd->hidden=0; + + /* find next */ + result = gtk_tree_model_iter_next(model, &child); + } + + update_index_to_pixmap(process_list); + + gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); +} + +void collapse_event(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *arg2, gpointer user_data) +{ + ControlFlowData *resourceview_data = + (ControlFlowData*)g_object_get_data( + G_OBJECT(treeview), + "resourceview_data"); + ProcessList *process_list = (ProcessList *) user_data; + ResourceUnique *rup; + HashedResourceData *hrd; + gboolean result; + + GtkTreeModel *model; + GtkTreeIter child; + + /* Determine which trace has been expanded */ + model = gtk_tree_view_get_model(treeview); + + /* mark each of the trace's resources invisible */ + result = gtk_tree_model_iter_children(model, &child, iter); + + /* for each child of the collapsed row */ + while(result) { + char *name; + /* hide the item */ + gtk_tree_model_get(model, &child, NAME_COLUMN, &name, DATA_COLUMN, &hrd, -1); + hrd->hidden=1; + + /* find next */ + result = gtk_tree_model_iter_next(model, &child); + } + + update_index_to_pixmap(process_list); + + gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); +} + static gboolean update_index_to_pixmap_each (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, UpdateIndexPixmapArg *arg) { guint array_index = arg->count; @@ -116,11 +187,13 @@ static gboolean update_index_to_pixmap_each (GtkTreeModel *model, GtkTreePath *p g_assert(array_index < arg->process_list->index_to_pixmap->len); - GdkPixmap **pixmap = - (GdkPixmap**)&g_ptr_array_index(arg->process_list->index_to_pixmap, array_index); - *pixmap = hdata->pixmap; + if(hdata->hidden == 0) { + GdkPixmap **pixmap = + (GdkPixmap**)&g_ptr_array_index(arg->process_list->index_to_pixmap, array_index); + *pixmap = hdata->pixmap; - arg->count++; + arg->count++; + } return FALSE; } @@ -134,6 +207,8 @@ void update_index_to_pixmap(ProcessList *process_list) items += g_hash_table_size(process_list->restypes[i].hash_table); } + /* we don't know the exact number of items there will be, + * so set an upper bound */ g_ptr_array_set_size(process_list->index_to_pixmap, items); arg.count = 0; @@ -141,6 +216,9 @@ void update_index_to_pixmap(ProcessList *process_list) gtk_tree_model_foreach(GTK_TREE_MODEL(process_list->list_store), (GtkTreeModelForeachFunc)update_index_to_pixmap_each, &arg); + + /* now that we know the exact number of items, set it */ + g_ptr_array_set_size(process_list->index_to_pixmap, arg.count); } @@ -334,6 +412,9 @@ ProcessList *processlist_construct(void) NULL, NULL, &process_list->cell_height); + + g_signal_connect(process_list->process_list_widget, "row-expanded", G_CALLBACK(expand_event), process_list); + g_signal_connect(process_list->process_list_widget, "row-collapsed", G_CALLBACK(collapse_event), process_list); #if GTK_CHECK_VERSION(2,4,15) guint ypad; @@ -532,6 +613,7 @@ HashedResourceData *resourcelist_obtain_machine(ControlFlowData *resourceview_da data->x.under_used = FALSE; data->x.under_marked = FALSE; data->next_good_time = ltt_time_zero; + data->hidden = 0; data->height = resourceview_data->process_list->cell_height; data->pixmap = @@ -576,7 +658,16 @@ HashedResourceData *resourcelist_obtain_machine(ControlFlowData *resourceview_da gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); } - gtk_tree_view_expand_all(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget)); + /* expand the newly added machine */ + { + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget)); + GtkTreePath *path; + path = gtk_tree_model_get_path(model, &data->y_iter); + + gtk_tree_view_expand_row(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget), path, FALSE); + + gtk_tree_path_free(path); + } return data; } @@ -587,6 +678,7 @@ HashedResourceData *resourcelist_obtain_generic(ControlFlowData *resourceview_da HashedResourceData *data = g_new(HashedResourceData, 1); /* Prepare hash key */ + ru->ru.type = &(resourceview_data->process_list->restypes[res_type]); ru->trace_num = trace_num; ru->id = id; @@ -643,6 +735,19 @@ HashedResourceData *resourcelist_obtain_generic(ControlFlowData *resourceview_da NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, -1); + /* Determine if we should add it hidden or not */ + { + gboolean result; + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget)); + GtkTreeIter parent_iter; + + result = gtk_tree_model_iter_parent(model, &parent_iter, &data->y_iter); + GtkTreePath *path = gtk_tree_model_get_path(model, &parent_iter); + data->hidden = gtk_tree_view_row_expanded(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget), path)?0:1; + gtk_tree_path_free(path); + } + + update_index_to_pixmap(resourceview_data->process_list); int heightall = data->height * resourceview_data->process_list->number_of_process; diff --git a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h index 9a14171c..2070a9c6 100644 --- a/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h +++ b/ltt/branches/poly/lttv/modules/gui/resourceview/processlist.h @@ -66,7 +66,19 @@ typedef struct _ResourceInfo { } ResourceInfo; */ +struct _ResourceType { + /* a hashtable containing the data of each resource of this type */ + GHashTable *hash_table; +}; +typedef struct _ResourceType ResourceType; + +typedef struct _ResourceUnique { + ResourceType *type; + void *priv; +} ResourceUnique; + typedef struct _ResourceUniqueNumeric { + ResourceUnique ru; guint trace_num; guint id; } ResourceUniqueNumeric; @@ -93,18 +105,10 @@ typedef struct _HashedResourceData { LttTime next_good_time; /* precalculate the next time where the next pixel is.*/ + gint hidden; } HashedResourceData; -struct _ResourceType { - /* functions for the hash table below */ - guint (*hashfunc)(gconstpointer); - gboolean (*hashequalfunc)(gconstpointer,gconstpointer); - /* a hashtable containing the data of each resource of this type */ - GHashTable *hash_table; -}; -typedef struct _ResourceType ResourceType; - struct _ProcessList { GtkWidget *process_list_widget; -- 2.34.1