Qt: Optionally restore our selected packet when thawing.

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>
This commit is contained in:
Gerald Combs 2016-12-12 11:34:03 -08:00
parent 6f3fed904d
commit e150235ef1
3 changed files with 31 additions and 7 deletions

View 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;
}

View 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;

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