void StatsTreeDialog::drawTreeItems(void *st_ptr) { stats_tree *st = (stats_tree *) st_ptr; if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return; TapParameterDialog *st_dlg = st->cfg->pr->st_dlg; QTreeWidgetItemIterator iter(st_dlg->statsTreeWidget()); int node_count = 0; while (*iter) { stat_node *node = VariantPointer<stat_node>::asPtr((*iter)->data(item_col_, Qt::UserRole)); if (node) { gchar **valstrs = stats_tree_get_values_from_node(node); for (int count = 0; count<st->num_columns; count++) { (*iter)->setText(count,valstrs[count]); g_free(valstrs[count]); } (*iter)->setExpanded((node->parent==(&st->root)) && (!(node->st_flags&ST_FLG_DEF_NOEXPAND))); g_free(valstrs); } node_count++; ++iter; } st_dlg->drawTreeItems(); }
void StatsTreeDialog::drawTreeItems(void *st_ptr) { stats_tree *st = (stats_tree *) st_ptr; if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return; StatsTreeDialog *st_dlg = st->cfg->pr->st_dlg; QTreeWidgetItemIterator iter(st_dlg->ui->statsTreeWidget); int node_count = 0; while (*iter) { stat_node *node = (*iter)->data(item_col_, Qt::UserRole).value<stat_node *>(); if (node) { gchar **valstrs = stats_tree_get_values_from_node(node); for (int count = 0; count<st->num_columns; count++) { (*iter)->setText(count,valstrs[count]); g_free(valstrs[count]); } (*iter)->setExpanded( (node->parent==(&st->root)) && (!(node->st_flags&ST_FLG_DEF_NOEXPAND)) ); g_free(valstrs); } node_count++; ++iter; } if (node_count < expand_all_threshold_) { st_dlg->ui->statsTreeWidget->expandAll(); } for (int count = 0; count<st->num_columns; count++) { st_dlg->ui->statsTreeWidget->resizeColumnToContents(count); } }
static void draw_gtk_node(stat_node* node) { GtkTreeIter *parent = NULL; stat_node *child; int num_columns = node->st->num_columns+N_RESERVED_COL; gint *columns = (gint*) g_malloc(sizeof(gint)*num_columns); GValue *values = (GValue*) g_malloc0(sizeof(GValue)*num_columns); gchar **valstrs = stats_tree_get_values_from_node(node); int count; columns[0]= 0; g_value_init(values, G_TYPE_POINTER); g_value_set_pointer(values, node); for (count = N_RESERVED_COL; count<num_columns; count++) { columns[count]= count; g_value_init(values+count, G_TYPE_STRING); g_value_take_string (values+count,valstrs[count-N_RESERVED_COL]); } if (!node->pr) { node->pr = (st_node_pres *)g_malloc(sizeof(st_node_pres)); if (node->st->pr->store) { node->pr->iter = (GtkTreeIter *)g_malloc0(sizeof(GtkTreeIter)); if ( node->parent && node->parent->pr ) { parent = node->parent->pr->iter; } gtk_tree_store_append (node->st->pr->store, node->pr->iter, parent); gtk_tree_store_set_valuesv(node->st->pr->store, node->pr->iter, columns, values, num_columns); } } if (node->st->pr->store && node->pr->iter) { /* skip reserved columns and first entry in the stats_tree values */ /* list (the node name). These should already be set and static. */ gtk_tree_store_set_valuesv(node->st->pr->store, node->pr->iter, columns+N_RESERVED_COL+1, values+N_RESERVED_COL+1, num_columns-N_RESERVED_COL-1); } for (count = 0; count<num_columns; count++) { g_value_unset(values+count); } g_free(columns); g_free(values); g_free(valstrs); if (node->children) { for (child = node->children; child; child = child->next ) draw_gtk_node(child); } }
/** helper funcation to add note to formatted stats_tree */ WS_DLL_PUBLIC void stats_tree_format_node_as_str(const stat_node *node, GString *s, st_format_type format_type, guint indent, const gchar *path, gint maxnamelen, gint sort_column, gboolean sort_descending) { int count; int num_columns= node->st->num_columns; gchar **values= stats_tree_get_values_from_node(node); stat_node *child; sortinfo si; gchar *full_path; char fmt[16]; switch(format_type) { case ST_FORMAT_YAML: if (indent) { g_sprintf(fmt, "%%%ds%%s%%s", indent*4-2); } else { strcpy(fmt, "%s%s%s"); } g_string_append_printf(s, fmt, "", indent?"- ":"", "Description"); g_string_append_printf(s, ": \"%s\"\n", values[0]); for (count = 1; count<num_columns; count++) { if (*values[count]) { g_string_append_printf(s, fmt, "", indent?" ":"", stats_tree_get_column_name(count)); g_string_append_printf(s, ": %s\n", values[count]); } } if (node->children) { g_string_append_printf(s, fmt, "", indent?" ":"", "Items:\n"); } break; case ST_FORMAT_XML: { char *itemname = xml_escape(values[0]); g_string_append_printf(s,"<stat-node name=\"%s\"%s>\n",itemname, node->rng?" isrange=\"true\"":""); g_free(itemname); for (count = 1; count<num_columns; count++) { gchar *colname= g_strdup(stats_tree_get_column_name(count)); g_string_append_printf(s,"<%s>",clean_for_xml_tag(colname)); g_string_append_printf(s,"%s</%s>\n",values[count],colname); g_free(colname); } } break; case ST_FORMAT_CSV: g_string_append_printf(s,"%d,\"%s\",\"%s\"",indent,path,values[0]); for (count = 1; count<num_columns; count++) { g_string_append_printf(s,",%s",values[count]); } g_string_append (s,"\n"); break; case ST_FORMAT_PLAIN: g_sprintf (fmt,"%%%ds%%-%us",indent,maxnamelen-indent); g_string_append_printf(s,fmt,"",values[0]); for (count = 1; count<num_columns; count++) { g_sprintf (fmt," %%-%us",stats_tree_get_column_size(count)+1); g_string_append_printf(s,fmt,values[count]); } g_string_append (s,"\n"); break; } indent++; indent = indent > INDENT_MAX ? INDENT_MAX : indent; full_path= g_strdup_printf ("%s/%s",path,values[0]); for (count = 0; count<num_columns; count++) { g_free(values[count]); } g_free(values); if (node->children) { GArray *Children= g_array_new(FALSE,FALSE,sizeof(child)); for (child = node->children; child; child = child->next ) { g_array_append_val(Children,child); } si.sort_column = sort_column; si.sort_descending = sort_descending; g_array_sort_with_data(Children,stat_node_array_sortcmp,&si); for (count = 0; count<((int)Children->len); count++) { stats_tree_format_node_as_str(g_array_index(Children,stat_node*,count), s, format_type, indent, full_path, maxnamelen, sort_column, sort_descending); } g_array_free(Children,FALSE); } g_free(full_path); if (format_type==ST_FORMAT_XML) { g_string_append(s,"</stat-node>\n"); } }