Qt: Optionally restore our selected packet when thawing.
authorGerald Combs <gerald@wireshark.org>
Mon, 12 Dec 2016 19:34:03 +0000 (11:34 -0800)
committerGerald Combs <gerald@wireshark.org>
Tue, 13 Dec 2016 22:01:59 +0000 (22:01 +0000)
Stash the current row when we freeze the packet list. Make it possible
to restore it when thawing. Do so when the layout changes and when we
move a column.

Change-Id: I44cfb8bafcd4d49a46e1c89bf47aecf5ac139773
Reviewed-on: https://code.wireshark.org/review/19222
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
ui/qt/main_window_slots.cpp
ui/qt/packet_list.cpp
ui/qt/packet_list.h

index dfdc8ac433f456589f34c3bb112fba16c1bbacfd..79e8a254338e8ed0f8f57b69dc357f7917a6a4a3 100644 (file)
@@ -320,7 +320,6 @@ void MainWindow::layoutPanes()
     if (cur_layout_ == new_layout) return;
 
     QSplitter *parents[3];
-    int current_row = capture_file_.currentRow();
 
     // Reparent all widgets and add them back in the proper order below.
     // This hides each widget as well.
@@ -397,8 +396,7 @@ void MainWindow::layoutPanes()
     proto_tree_->setVisible(ms_children.contains(proto_tree_) && recent.tree_view_show);
     byte_view_tab_->setVisible(ms_children.contains(byte_view_tab_) && recent.byte_view_show);
 
-    packet_list_->thaw();
-    cf_select_packet(capture_file_.capFile(), current_row);  // XXX Doesn't work for row 0?
+    packet_list_->thaw(true);
     cur_layout_ = new_layout;
 }
 
index b5f5493a772b1a91431f914e9116fdbebd22c600..74049d084f9bb18860b4fe4e2a022ad91970c86a 100644 (file)
@@ -246,7 +246,8 @@ PacketList::PacketList(QWidget *parent) :
     tail_timer_id_(0),
     rows_inserted_(false),
     columns_changed_(false),
-    set_column_visibility_(false)
+    set_column_visibility_(false),
+    frozen_row_(-1)
 {
     QMenu *main_menu_item, *submenu;
     QAction *action;
@@ -882,6 +883,11 @@ void PacketList::freeze()
 {
     setUpdatesEnabled(false);
     column_state_ = header()->saveState();
+    if (currentIndex().isValid()) {
+        frozen_row_ = currentIndex().row();
+    } else {
+        frozen_row_ = -1;
+    }
     selectionModel()->clear();
     setModel(NULL);
     // It looks like GTK+ sends a cursor-changed signal at this point but Qt doesn't
@@ -891,7 +897,7 @@ void PacketList::freeze()
     byte_view_tab_->clear();
 }
 
-void PacketList::thaw()
+void PacketList::thaw(bool restore_selection)
 {
     setUpdatesEnabled(true);
     setModel(packet_list_model_);
@@ -900,6 +906,13 @@ void PacketList::thaw()
     // We don't reapply the recent settings because the user could have
     // resized the columns manually since they were initially loaded.
     header()->restoreState(column_state_);
+
+    if (restore_selection && frozen_row_ > -1) {
+        // This updates our selection, which redissects the current packet,
+        // which is needed when we're called from MainWindow::layoutPanes.
+        setCurrentIndex(packet_list_model_->index(frozen_row_, 0));
+    }
+    frozen_row_ = -1;
 }
 
 void PacketList::clear() {
@@ -1388,7 +1401,7 @@ void PacketList::sectionMoved(int, int, int)
     g_list_free(prefs.col_list);
     prefs.col_list = new_col_list;
 
-    thaw();
+    thaw(true);
 
     for (int i = 0; i < saved_sizes.length(); i++) {
         if (saved_sizes[i] < 1) continue;
index 446d13a6b5f329675ceab521e5dc3f459442d959..4f3d072831e339f5142ff61a55512df4c759c78a 100644 (file)
@@ -61,8 +61,20 @@ public:
     QMenu *colorizeMenu() { return &colorize_menu_; }
     void setProtoTree(ProtoTree *proto_tree);
     void setByteViewTab(ByteViewTab *byteViewTab);
+    /** Disable and clear the packet list.
+     *
+     * Disable packet list widget updates, clear the detail and byte views,
+     * and disconnect the model.
+     */
     void freeze();
-    void thaw();
+    /** Enable and restore the packet list.
+     *
+     * Enable packet list widget updates and reconnect the model.
+     *
+     * @param restore_selection If true, redissect the previously selected
+     * packet. This includes filling in the detail and byte views.
+     */
+    void thaw(bool restore_selection = false);
     void clear();
     void writeRecent(FILE *rf);
     bool contextMenuActive();
@@ -120,6 +132,7 @@ private:
     bool rows_inserted_;
     bool columns_changed_;
     bool set_column_visibility_;
+    int frozen_row_;
 
     void setFrameReftime(gboolean set, frame_data *fdata);
     void setColumnVisibility();