Qt: Fix a crash when changing the layout.
Freeze and thaw the packet list when changing the layout. This has the side effect of clearing the proto tree and byte view, which avoids reading a bad tvb pointer. Note that we might want to add a cleanup callback to free_data_sources. Save and restore the current row. Add CaptureFile::currentRow. Fix a couple of comparisons in PacketList. Change-Id: I26f9b97ae5a7cdb4fb6e5e6e675570884900e995 Reviewed-on: https://code.wireshark.org/review/7337 Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
a6f4bdb874
commit
770ac9123b
|
@ -24,6 +24,10 @@
|
|||
#include <QTabBar>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
// To do:
|
||||
// - We might want to add a callback to free_data_sources in so that we
|
||||
// don't have to blindly call clear().
|
||||
|
||||
ByteViewTab::ByteViewTab(QWidget *parent) :
|
||||
QTabWidget(parent)
|
||||
{
|
||||
|
|
|
@ -68,6 +68,13 @@ bool CaptureFile::isValid() const
|
|||
return false;
|
||||
}
|
||||
|
||||
int CaptureFile::currentRow()
|
||||
{
|
||||
if (isValid())
|
||||
return cap_file_->current_row;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CaptureFile::retapPackets()
|
||||
{
|
||||
if (cap_file_) {
|
||||
|
|
|
@ -47,6 +47,13 @@ public:
|
|||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/** Get the current selected row
|
||||
*
|
||||
* @return the current selected index of the packet list if the capture
|
||||
* file is open and a packet is selected, otherwise -1.
|
||||
*/
|
||||
int currentRow();
|
||||
|
||||
/** Return a filename suitable for use in a window title.
|
||||
*
|
||||
* @return One of: the basename of the capture file without an extension,
|
||||
|
|
|
@ -255,9 +255,11 @@ 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.
|
||||
packet_list_->freeze(); // Clears tree and byte view tab.
|
||||
packet_list_->setParent(main_ui_->mainStack);
|
||||
proto_tree_->setParent(main_ui_->mainStack);
|
||||
byte_view_tab_->setParent(main_ui_->mainStack);
|
||||
|
@ -341,9 +343,8 @@ void MainWindow::layoutPanes()
|
|||
}
|
||||
widget->setVisible(show);
|
||||
}
|
||||
if (capture_file_.isValid() && capture_file_.capFile()->current_row >= 0) {
|
||||
cf_select_packet(capture_file_.capFile(), capture_file_.capFile()->current_row);
|
||||
}
|
||||
packet_list_->thaw();
|
||||
cf_select_packet(capture_file_.capFile(), current_row); // XXX Doesn't work for row 0?
|
||||
cur_layout_ = new_layout;
|
||||
}
|
||||
|
||||
|
|
|
@ -639,7 +639,7 @@ void PacketList::redrawVisiblePackets() {
|
|||
build_column_format_array(&cap_file_->cinfo, prefs.num_cols, FALSE);
|
||||
|
||||
packet_list_model_->resetColumns();
|
||||
if (row > 0) {
|
||||
if (row >= 0) {
|
||||
setCurrentIndex(packet_list_model_->index(row, 0));
|
||||
}
|
||||
|
||||
|
@ -880,7 +880,7 @@ void PacketList::goLastPacket(void) {
|
|||
// XXX We can jump to the wrong packet if a display filter is applied
|
||||
void PacketList::goToPacket(int packet) {
|
||||
int row = packet_list_model_->packetNumberToRow(packet);
|
||||
if (row > 0) {
|
||||
if (row >= 0) {
|
||||
setCurrentIndex(packet_list_model_->index(row, 0));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue