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>
This commit is contained in:
Stig Bjørlykke 2015-11-24 20:42:50 +01:00
parent ff5719c6e8
commit 4980d505f2
2 changed files with 21 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -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();