diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-26 19:15:44 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-11-27 05:29:08 +0000 |
commit | f5b816d4c92e633453fe65dfa56d80ad32bab477 (patch) | |
tree | d3299453b4edae79a21eb122b5b11ed3da201f06 /ui/qt/packet_list.cpp | |
parent | c51f207308d04bda005f84828b59cec4104e4b8f (diff) | |
download | wireshark-f5b816d4c92e633453fe65dfa56d80ad32bab477.tar.gz |
Qt: Check zero recent column width
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 <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/packet_list.cpp')
-rw-r--r-- | ui/qt/packet_list.cpp | 49 |
1 files changed, 27 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(); |