diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-24 20:42:50 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-26 17:17:05 +0000 |
commit | 41bf1dda4f59adbffd3a6abfb7189adc93b06e39 (patch) | |
tree | d2e7f00cdba7869f05901b013a2f0241f8add3a9 | |
parent | b6a0392d9593b9ea52280f4b8b29d5091e3de6c7 (diff) | |
download | wireshark-41bf1dda4f59adbffd3a6abfb7189adc93b06e39.tar.gz |
Qt: Use correct column width when switching profile
QTreeView::setColumnHidden() saves column width on hide and restores
column width on show. When switching from a profile with hidden
columns to a profile where this columns are shown we get a
sectionResized() signal with the saved width from the old profile,
initiated from columnsChanged() -> setColumnVisibility().
We must avoid setting this as a new column width because this is
recent values from a old column layout.
In other cases we use setColumnVisibility() we don’t need to set
a new column width either, because we store the column width ourself.
Don't store column width when hiding column (new_width == 0).
Restore column width when showing column because profiles may have
changed the packet_list layout.
Change-Id: I7e89c3477402ec6d621cd2015ee74b086f60d6cb
Reviewed-on: https://code.wireshark.org/review/12111
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
(cherry picked from commit 4980d505f268b2b1d2ebabf815f3d0ce34e8cd71)
Reviewed-on: https://code.wireshark.org/review/12192
-rw-r--r-- | ui/qt/packet_list.cpp | 24 | ||||
-rw-r--r-- | ui/qt/packet_list.h | 1 |
2 files changed, 21 insertions, 4 deletions
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index aac241adda..89cb4b3214 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -250,7 +250,8 @@ PacketList::PacketList(QWidget *parent) : capture_in_progress_(false), tail_timer_id_(0), rows_inserted_(false), - columns_changed_(false) + columns_changed_(false), + set_column_visibility_(false) { QMenu *main_menu_item, *submenu; QAction *action; @@ -559,9 +560,11 @@ void PacketList::paintEvent(QPaintEvent *event) void PacketList::setColumnVisibility() { + set_column_visibility_ = true; for (int i = 0; i < prefs.num_cols; i++) { setColumnHidden(i, get_column_visible(i) ? false : true); } + set_column_visibility_ = false; } int PacketList::sizeHintForColumn(int column) const @@ -636,8 +639,9 @@ void PacketList::redrawVisiblePackets() { // prefs.col_list has changed. void PacketList::columnsChanged() { + columns_changed_ = true; if (!cap_file_) { - columns_changed_ = true; + // Keep columns_changed_ = true until we load a capture file. return; } @@ -984,6 +988,7 @@ void PacketList::setCaptureFile(capture_file *cf) cap_file_ = cf; if (cap_file_ && columns_changed_) { columnsChanged(); + applyRecentColumnWidths(); } packet_list_model_->setCaptureFile(cf); create_near_overlay_ = true; @@ -1223,8 +1228,12 @@ void PacketList::columnVisibilityTriggered() QAction *ha = qobject_cast<QAction*>(sender()); if (!ha) return; - set_column_visible(ha->data().toInt(), ha->isChecked()); + int col = ha->data().toInt(); + set_column_visible(col, ha->isChecked()); setColumnVisibility(); + if (ha->isChecked()) { + setColumnWidth(col, recent_get_column_width(col)); + } if (!prefs.gui_use_pref_save) { prefs_main_write(); } @@ -1232,9 +1241,16 @@ void PacketList::columnVisibilityTriggered() void PacketList::sectionResized(int col, int, int new_width) { - if (isVisible()) { + if (isVisible() && !columns_changed_ && !set_column_visibility_ && new_width > 0) { // Column 1 gets an invalid value (32 on OS X) when we're not yet // visible. + // + // Don't set column width when columns changed or setting column + // visibility because we may get a sectionReized() from QTreeView + // with values from a old columns layout. + // + // Don't set column width when hiding a column. + recent_set_column_width(col, new_width); } } diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h index eaa1a3bda9..f4e6217088 100644 --- a/ui/qt/packet_list.h +++ b/ui/qt/packet_list.h @@ -117,6 +117,7 @@ private: bool tail_at_end_; bool rows_inserted_; bool columns_changed_; + bool set_column_visibility_; void setFrameReftime(gboolean set, frame_data *fdata); void setColumnVisibility(); |