forked from osmocom/wireshark
Qt: Fix saving+restoring frozen packet list rows.
Use the packet list selection model to save and restore selected rows
when freezing and thawing. Fixes #16770.
(cherry picked from commit 1c2fd68e26
)
This commit is contained in:
parent
a4213f2c4f
commit
f49d6000a7
|
@ -229,7 +229,7 @@ PacketList::PacketList(QWidget *parent) :
|
||||||
rows_inserted_(false),
|
rows_inserted_(false),
|
||||||
columns_changed_(false),
|
columns_changed_(false),
|
||||||
set_column_visibility_(false),
|
set_column_visibility_(false),
|
||||||
frozen_row_(-1),
|
frozen_rows_(QModelIndexList()),
|
||||||
cur_history_(-1),
|
cur_history_(-1),
|
||||||
in_history_(false)
|
in_history_(false)
|
||||||
{
|
{
|
||||||
|
@ -1180,11 +1180,7 @@ void PacketList::freeze()
|
||||||
{
|
{
|
||||||
column_state_ = header()->saveState();
|
column_state_ = header()->saveState();
|
||||||
setHeaderHidden(true);
|
setHeaderHidden(true);
|
||||||
if (currentIndex().isValid()) {
|
frozen_rows_ = selectedIndexes();
|
||||||
frozen_row_ = currentIndex().row();
|
|
||||||
} else {
|
|
||||||
frozen_row_ = -1;
|
|
||||||
}
|
|
||||||
selectionModel()->clear();
|
selectionModel()->clear();
|
||||||
setModel(Q_NULLPTR);
|
setModel(Q_NULLPTR);
|
||||||
// It looks like GTK+ sends a cursor-changed signal at this point but Qt doesn't
|
// It looks like GTK+ sends a cursor-changed signal at this point but Qt doesn't
|
||||||
|
@ -1205,14 +1201,16 @@ void PacketList::thaw(bool restore_selection)
|
||||||
// resized the columns manually since they were initially loaded.
|
// resized the columns manually since they were initially loaded.
|
||||||
header()->restoreState(column_state_);
|
header()->restoreState(column_state_);
|
||||||
|
|
||||||
if (restore_selection && frozen_row_ > -1 && selectionModel()) {
|
if (restore_selection && frozen_rows_.length() > 0 && selectionModel()) {
|
||||||
/* This updates our selection, which redissects the current packet,
|
/* This updates our selection, which redissects the current packet,
|
||||||
* which is needed when we're called from MainWindow::layoutPanes.
|
* which is needed when we're called from MainWindow::layoutPanes.
|
||||||
* Also, this resets all ProtoTree and ByteView data */
|
* Also, this resets all ProtoTree and ByteView data */
|
||||||
QModelIndex restored = packet_list_model_->index(frozen_row_, 0);
|
clearSelection();
|
||||||
selectionModel()->select(restored, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
foreach (QModelIndex idx, frozen_rows_) {
|
||||||
|
selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
frozen_row_ = -1;
|
frozen_rows_ = QModelIndexList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::clear() {
|
void PacketList::clear() {
|
||||||
|
|
|
@ -134,7 +134,7 @@ private:
|
||||||
bool rows_inserted_;
|
bool rows_inserted_;
|
||||||
bool columns_changed_;
|
bool columns_changed_;
|
||||||
bool set_column_visibility_;
|
bool set_column_visibility_;
|
||||||
int frozen_row_;
|
QModelIndexList frozen_rows_;
|
||||||
QVector<int> selection_history_;
|
QVector<int> selection_history_;
|
||||||
int cur_history_;
|
int cur_history_;
|
||||||
bool in_history_;
|
bool in_history_;
|
||||||
|
|
Loading…
Reference in New Issue