Qt: Set tooltip for packet list header

Added get_column_tooltip() to use common code in GTK and Qt.

Change-Id: I2f6ce95e2e129752bbb958a28aec6f42aa81be3d
Reviewed-on: https://code.wireshark.org/review/12047
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Stig Bjørlykke 2015-11-22 21:25:15 +01:00 committed by Anders Broman
parent fad15654b1
commit c5fb402222
6 changed files with 56 additions and 26 deletions

View File

@ -671,6 +671,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
get_column_format_matches@Base 1.9.1
get_column_resolved@Base 1.9.1
get_column_title@Base 1.9.1
get_column_tooltip@Base 2.0.1
get_column_visible@Base 1.9.1
get_column_width_string@Base 1.9.1
get_conversation_address@Base 1.99.0

View File

@ -784,6 +784,42 @@ set_column_custom_occurrence(const gint col, const gint custom_occurrence)
cfmt->custom_occurrence = custom_occurrence;
}
gchar *
get_column_tooltip(const gint col)
{
GList *clp = g_list_nth(prefs.col_list, col);
fmt_data *cfmt;
gchar *tooltip_text;
if (!clp) /* Invalid column requested */
return NULL;
cfmt = (fmt_data *) clp->data;
if (cfmt->fmt == COL_CUSTOM) {
header_field_info *hfi = proto_registrar_get_byname(cfmt->custom_field);
/* Check if this is a valid custom_field */
if (hfi != NULL) {
if (hfi->parent != -1) {
/* Prefix with protocol name */
if (cfmt->custom_occurrence != 0) {
tooltip_text = g_strdup_printf("%s\n%s (%s#%d)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev, cfmt->custom_occurrence);
} else {
tooltip_text = g_strdup_printf("%s\n%s (%s)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev);
}
} else {
tooltip_text = g_strdup_printf("%s (%s)", hfi->name, hfi->abbrev);
}
} else {
tooltip_text = g_strdup_printf("Unknown Field: %s", get_column_custom_field(col));
}
} else {
tooltip_text = g_strdup(col_format_desc(cfmt->fmt));
}
return tooltip_text;
}
void
build_column_format_array(column_info *cinfo, const gint num_cols, const gboolean reset_fences)
{

View File

@ -75,6 +75,8 @@ WS_DLL_PUBLIC
const gchar *get_column_width_string(const gint, const gint);
WS_DLL_PUBLIC
gint get_column_char_width(const gint format);
WS_DLL_PUBLIC
gchar *get_column_tooltip(const gint col);
WS_DLL_PUBLIC
void

View File

@ -656,7 +656,6 @@ create_view_and_model(void)
gint i, col_width;
gdouble value;
gchar *tooltip_text;
header_field_info *hfi;
gint col_min_width;
gchar *escaped_title;
col_item_t* col_item;
@ -705,26 +704,7 @@ create_view_and_model(void)
show_cell_data_func,
GINT_TO_POINTER(i),
NULL);
if (col_item->col_fmt == COL_CUSTOM) {
hfi = proto_registrar_get_byname(col_item->col_custom_field);
/* Check if this is a valid custom_field */
if (hfi != NULL) {
if (hfi->parent != -1) {
/* Prefix with protocol name */
if (col_item->col_custom_occurrence != 0) {
tooltip_text = g_strdup_printf("%s\n%s (%s#%d)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev, col_item->col_custom_occurrence);
} else {
tooltip_text = g_strdup_printf("%s\n%s (%s)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev);
}
} else {
tooltip_text = g_strdup_printf("%s (%s)", hfi->name, hfi->abbrev);
}
} else {
tooltip_text = g_strdup_printf("Unknown Field: %s", get_column_custom_field(i));
}
} else {
tooltip_text = g_strdup(col_format_desc(col_item->col_fmt));
}
escaped_title = ws_strdup_escape_char(col_item->col_title, '_');
gtk_tree_view_column_set_title(col, escaped_title);
g_free (escaped_title);
@ -769,6 +749,7 @@ create_view_and_model(void)
gtk_tree_view_append_column(GTK_TREE_VIEW(packetlist->view), col);
tooltip_text = get_column_tooltip(i);
gtk_widget_set_tooltip_text(gtk_tree_view_column_get_button(col), tooltip_text);
g_free(tooltip_text);
g_signal_connect(gtk_tree_view_column_get_button(col), "button_press_event",

View File

@ -528,20 +528,30 @@ QVariant PacketListModel::data(const QModelIndex &d_index, int role) const
}
QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
int role) const
int role) const
{
if (!cap_file_) return QVariant();
QVariant data;
if (!cap_file_) return data;
if (orientation == Qt::Horizontal && section < prefs.num_cols) {
switch (role) {
case Qt::DisplayRole:
return get_column_title(section);
data = get_column_title(section);
break;
case Qt::ToolTipRole:
{
gchar *tooltip = get_column_tooltip(section);
data = tooltip;
g_free (tooltip);
break;
}
default:
break;
}
}
return QVariant();
return data;
}
void PacketListModel::flushVisibleRows()

View File

@ -58,7 +58,7 @@ public:
int columnCount(const QModelIndex & = QModelIndex()) const;
QVariant data(const QModelIndex &d_index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
int role = Qt::DisplayRole | Qt::ToolTipRole) const;
gint appendPacket(frame_data *fdata);
frame_data *getRowFdata(int row);