From 036c404e6d82762c4c6d26159d34dde8bf6fa349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Thu, 26 Nov 2015 19:15:44 +0100 Subject: Qt: Check zero recent column width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hidden columns may have been stored with zero width, so ensure we always check for this when fetching. Change-Id: I625c05adccaf2d81198fdeeccf7feeb9a9eb82c2 Reviewed-on: https://code.wireshark.org/review/12196 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman (cherry picked from commit f5b816d4c92e633453fe65dfa56d80ad32bab477) Reviewed-on: https://code.wireshark.org/review/12217 --- ui/qt/packet_list.cpp | 49 +++++++++++++++++++++++++++---------------------- ui/qt/packet_list.h | 1 + 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 89cb4b3214..4c0ec0bdda 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -582,6 +582,30 @@ int PacketList::sizeHintForColumn(int column) const return size_hint; } +void PacketList::setRecentColumnWidth(int col) +{ + int col_width = recent_get_column_width(col); + + if (col_width < 1) { + int fmt = get_column_format(col); + const char *long_str = get_column_width_string(fmt, col); + + QFontMetrics fm = QFontMetrics(wsApp->monospaceFont()); + if (long_str) { + col_width = fm.width(long_str); + } else { + col_width = fm.width(MIN_COL_WIDTH_STR); + } + + // Custom delegate padding + if (itemDelegateForColumn(col)) { + col_width += itemDelegateForColumn(col)->sizeHint(viewOptions(), QModelIndex()).width(); + } + } + + setColumnWidth(col, col_width); +} + void PacketList::initHeaderContextMenu() { header_ctx_menu_.clear(); @@ -674,27 +698,8 @@ void PacketList::applyRecentColumnWidths() { // Either we've just started up or a profile has changed. Read // the recent settings, apply them, and save the header state. - QFontMetrics fm = QFontMetrics(wsApp->monospaceFont()); - for (int i = 0; i < prefs.num_cols; i++) { - int col_width = recent_get_column_width(i); - - if (col_width < 1) { - int fmt; - const char *long_str; - - fmt = get_column_format(i); - long_str = get_column_width_string(fmt, i); - if (long_str) { - col_width = fm.width(long_str); - } else { - col_width = fm.width(MIN_COL_WIDTH_STR); - } - // Custom delegate padding - if (itemDelegateForColumn(i)) { - col_width += itemDelegateForColumn(i)->sizeHint(viewOptions(), QModelIndex()).width(); - } - } - setColumnWidth(i, col_width) ; + for (int col = 0; col < prefs.num_cols; col++) { + setRecentColumnWidth(col); } column_state_ = header()->saveState(); } @@ -1232,7 +1237,7 @@ void PacketList::columnVisibilityTriggered() set_column_visible(col, ha->isChecked()); setColumnVisibility(); if (ha->isChecked()) { - setColumnWidth(col, recent_get_column_width(col)); + setRecentColumnWidth(col); } if (!prefs.gui_use_pref_save) { prefs_main_write(); diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h index f4e6217088..f0786a5ecc 100644 --- a/ui/qt/packet_list.h +++ b/ui/qt/packet_list.h @@ -122,6 +122,7 @@ private: void setFrameReftime(gboolean set, frame_data *fdata); void setColumnVisibility(); int sizeHintForColumn(int column) const; + void setRecentColumnWidth(int column); void initHeaderContextMenu(); void drawCurrentPacket(); -- cgit v1.2.1