From 54d2ff1c3e74e57a59a57b9b3fdeb50e64cceb0f Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Mon, 31 Aug 2015 16:06:33 -0700 Subject: Convert the WSP stats to generic stat API. Add support for multiple tables to SimpleStatisticsDialog. Change-Id: I843d901db092d2f2856d3d1a16f29f85fb41374b Reviewed-on: https://code.wireshark.org/review/10339 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs --- ui/qt/simple_statistics_dialog.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'ui/qt/simple_statistics_dialog.cpp') diff --git a/ui/qt/simple_statistics_dialog.cpp b/ui/qt/simple_statistics_dialog.cpp index 9ed61324aa..d9d235456e 100644 --- a/ui/qt/simple_statistics_dialog.cpp +++ b/ui/qt/simple_statistics_dialog.cpp @@ -68,7 +68,7 @@ enum { class SimpleStatisticsTreeWidgetItem : public QTreeWidgetItem { public: - SimpleStatisticsTreeWidgetItem(QTreeWidget *parent, int num_fields, const stat_tap_table_item_type *fields) : + SimpleStatisticsTreeWidgetItem(QTreeWidgetItem *parent, int num_fields, const stat_tap_table_item_type *fields) : QTreeWidgetItem (parent, simple_row_type_), num_fields_(num_fields), fields_(fields) @@ -196,15 +196,26 @@ void SimpleStatisticsDialog::addMissingRows(struct _new_stat_data_t *stat_data) // For multiple table support we might want to add them as subtrees, with // the top-level tree item text set to the column labels for that table. - // Add any missing rows. - guint table_index = 0; - new_stat_tap_table* st_table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, table_index); - for (guint element = statsTreeWidget()->topLevelItemCount(); element < st_table->num_elements; element++) { - stat_tap_table_item_type* fields = new_stat_tap_get_field_data(st_table, element, 0); - SimpleStatisticsTreeWidgetItem *ss_ti = new SimpleStatisticsTreeWidgetItem(statsTreeWidget(), st_table->num_fields, fields); - for (int col = 0; col < (int) stu_->nfields; col++) { - if (stu_->fields[col].align == TAP_ALIGN_RIGHT) { - ss_ti->setTextAlignment(col, Qt::AlignRight); + // Add any missing tables and rows. + for (guint table_idx = 0; table_idx < stat_data->new_stat_tap_data->tables->len; table_idx++) { + new_stat_tap_table* st_table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, table_idx); + QTreeWidgetItem *ti = NULL; + + if ((int) table_idx >= statsTreeWidget()->topLevelItemCount()) { + ti = new QTreeWidgetItem(statsTreeWidget()); + ti->setText(0, st_table->title); + ti->setFirstColumnSpanned(true); + ti->setExpanded(true); + } else { + ti = statsTreeWidget()->topLevelItem(table_idx); + } + for (guint element = ti->childCount(); element < st_table->num_elements; element++) { + stat_tap_table_item_type* fields = new_stat_tap_get_field_data(st_table, element, 0); + SimpleStatisticsTreeWidgetItem *ss_ti = new SimpleStatisticsTreeWidgetItem(ti, st_table->num_fields, fields); + for (int col = 0; col < (int) stu_->nfields; col++) { + if (stu_->fields[col].align == TAP_ALIGN_RIGHT) { + ss_ti->setTextAlignment(col, Qt::AlignRight); + } } } } @@ -265,6 +276,11 @@ void SimpleStatisticsDialog::fillTree() cap_file_.retapPackets(); + // We only have one table. Move its tree items up one level. + if (statsTreeWidget()->invisibleRootItem()->childCount() == 1) { + statsTreeWidget()->setRootIndex(statsTreeWidget()->model()->index(0, 0)); + } + tapDraw(&stat_data); removeTapListeners(); -- cgit v1.2.1