From 2156413bf9cb093b7f5998399bb6ceb7b4c232ce Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 13 May 2015 15:46:51 -0700 Subject: [PATCH] Qt: Column preference fixes. Don't call redrawVisiblePackets in PacketList::sectionResized. Otherwise we trigger the crash in bug 11179. Call recent_set_column_width instead. Clean up the slots called when column preferences change and when recent column widths change. Update our column visibility in redrawVisiblePackets. Use recent_get_column_width when writing the recent file. columnWidth doesn't return a valid value when we're not visible. Bug: 11179. Change-Id: I34ab93d944b341e42129a1c8ff94ba8f7ad4f5fc Reviewed-on: https://code.wireshark.org/review/8457 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Michal Labedzki Reviewed-by: Gerald Combs --- ui/qt/main_window.cpp | 4 +++- ui/qt/main_window_slots.cpp | 1 + ui/qt/packet_list.cpp | 27 ++++++++++++--------------- ui/qt/packet_list.h | 3 ++- ui/qt/wireshark_application.cpp | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 8c1dc798fd..9f32f410bb 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -326,8 +326,10 @@ MainWindow::MainWindow(QWidget *parent) : connect(&capture_file_, SIGNAL(captureFileReadFinished()), wsApp, SLOT(updateTaps())); - connect(wsApp, SIGNAL(columnsChanged()), + connect(wsApp, SIGNAL(recentFilesRead()), packet_list_, SLOT(applyRecentColumnWidths())); + connect(wsApp, SIGNAL(columnsChanged()), + packet_list_, SLOT(redrawVisiblePackets())); connect(wsApp, SIGNAL(recentFilesRead()), this, SLOT(applyRecentPaneGeometry())); connect(wsApp, SIGNAL(packetDissectionChanged()), diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 4e1b3d59c7..41b8371d1d 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -2111,6 +2111,7 @@ void MainWindow::on_actionViewResizeColumns_triggered() { for (int col = 0; col < packet_list_->packetListModel()->columnCount(); col++) { packet_list_->resizeColumnToContents(col); + recent_set_column_width(col, packet_list_->columnWidth(col)); } } diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 997b66e9bd..360cbc7ef2 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -417,8 +417,9 @@ PacketList::PacketList(QWidget *parent) : header()->setContextMenuPolicy(Qt::CustomContextMenu); connect(header(), SIGNAL(customContextMenuRequested(QPoint)), - SLOT(showHeaderMenu(QPoint))); - connect(header(), SIGNAL(sectionResized(int,int,int)), this, SLOT(sectionResized(int,int,int))); + this, SLOT(showHeaderMenu(QPoint))); + connect(header(), SIGNAL(sectionResized(int,int,int)), + this, SLOT(sectionResized(int,int,int))); connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(vScrollBarActionTriggered(int))); } @@ -645,7 +646,8 @@ void PacketList::initHeaderContextMenu() } } -// Redraw the packet list and detail +// Redraw the packet list and detail. Called from many places, including +// columnsChanged. void PacketList::redrawVisiblePackets() { if (!cap_file_) return; @@ -658,6 +660,7 @@ void PacketList::redrawVisiblePackets() { prefs.num_cols = g_list_length(prefs.col_list); col_cleanup(&cap_file_->cinfo); build_column_format_array(&cap_file_->cinfo, prefs.num_cols, FALSE); + setColumnVisibility(); packet_list_model_->resetColumns(); if (row >= 0) { @@ -674,6 +677,7 @@ void PacketList::redrawVisiblePackets() { // - Persist across file closing and opening. // - Save to recent when we save our profile (including shutting down). +// Called via recentFilesRead. void PacketList::applyRecentColumnWidths() { // Either we've just started up or a profile has changed. Read @@ -701,7 +705,6 @@ void PacketList::applyRecentColumnWidths() setColumnWidth(i, col_width) ; } column_state_ = header()->saveState(); - redrawVisiblePackets(); } void PacketList::recolorPackets() @@ -777,12 +780,8 @@ void PacketList::writeRecent(FILE *rf) { } else { fprintf (rf, " %s,", col_format_to_string(col_fmt)); } - width = columnWidth(col); + width = recent_get_column_width (col); xalign = recent_get_column_xalign (col); - if (width == 0) { - /* We have not initialized the packet list yet, use old values */ - width = recent_get_column_width (col); - } fprintf (rf, " %d", width); if (xalign != COLUMN_XALIGN_DEFAULT) { fprintf (rf, ":%c", xalign); @@ -1194,14 +1193,12 @@ void PacketList::columnVisibilityTriggered() setColumnVisibility(); } -void PacketList::sectionResized(int, int, int) +void PacketList::sectionResized(int col, int, int new_width) { - // For some reason the width of column 1 gets set to 32 when we open a file after - // closing a previous one. I (Gerald) am not sure if this is a bug in Qt or if it's - // our doing. Either way this catches that and fixes it. if (isVisible()) { - column_state_ = header()->saveState(); - redrawVisiblePackets(); + // Column 1 gets an invalid value (32 on OS X) when we're not yet + // visible. + recent_set_column_width(col, new_width); } } diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h index 0c29db71d8..4bdf59cb09 100644 --- a/ui/qt/packet_list.h +++ b/ui/qt/packet_list.h @@ -106,6 +106,7 @@ private: void setColumnVisibility(); int sizeHintForColumn(int column) const; void initHeaderContextMenu(); + signals: void packetDissectionChanged(); void packetSelectionChanged(); @@ -135,7 +136,7 @@ private slots: void showHeaderMenu(QPoint pos); void headerMenuTriggered(); void columnVisibilityTriggered(); - void sectionResized(int, int, int); + void sectionResized(int col, int, int new_width); void vScrollBarActionTriggered(int); }; diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 44bafd0401..7615297a8e 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -359,8 +359,8 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) prefs_apply_all(); emit preferencesChanged(); - emit recentFilesRead(); emit columnsChanged(); + emit recentFilesRead(); emit filterExpressionsChanged(); // macros_post_update();