aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/packet_list.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2017-03-01 10:03:17 -0600
committerAnders Broman <a.broman58@gmail.com>2017-03-03 05:02:14 +0000
commit8e76cfbf54c209336d3aaf7e613e309675eebf38 (patch)
treed58d1c11d6a264b0d06cd37fbea0b092c3aaccb6 /ui/qt/packet_list.cpp
parentbc56801319ba30b6d83f336ec1d793b3a0ab016a (diff)
Qt: Add selection history navigation.
Add the ability to move back and forth in the packet selection history similar to GTK+. Update the documentation accordingly. Change-Id: If1fdc1e59b240c0588c292dc0f7f0a5f083c30e1 Reviewed-on: https://code.wireshark.org/review/20320 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/packet_list.cpp')
-rw-r--r--ui/qt/packet_list.cpp81
1 files changed, 79 insertions, 2 deletions
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp
index 74049d084f..e3095fd3f8 100644
--- a/ui/qt/packet_list.cpp
+++ b/ui/qt/packet_list.cpp
@@ -247,7 +247,9 @@ PacketList::PacketList(QWidget *parent) :
rows_inserted_(false),
columns_changed_(false),
set_column_visibility_(false),
- frozen_row_(-1)
+ frozen_row_(-1),
+ cur_history_(-1),
+ in_history_(false)
{
QMenu *main_menu_item, *submenu;
QAction *action;
@@ -494,6 +496,13 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS
cf_select_packet(cap_file_, row);
}
+ if (!in_history_ && cap_file_->current_frame) {
+ cur_history_++;
+ selection_history_.resize(cur_history_);
+ selection_history_.append(cap_file_->current_frame->num);
+ }
+ in_history_ = false;
+
related_packet_delegate_.clear();
if (proto_tree_) proto_tree_->clear();
if (byte_view_tab_) byte_view_tab_->clear();
@@ -755,6 +764,42 @@ void PacketList::resetColumns()
packet_list_model_->resetColumns();
}
+// Return true if we have a visible packet further along in the history.
+bool PacketList::haveNextHistory(bool update_cur)
+{
+ if (selection_history_.size() < 1 || cur_history_ >= selection_history_.size() - 1) {
+ return false;
+ }
+
+ for (int i = cur_history_ + 1; i < selection_history_.size(); i++) {
+ if (packet_list_model_->packetNumberToRow(selection_history_.at(i)) >= 0) {
+ if (update_cur) {
+ cur_history_ = i;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+// Return true if we have a visible packet back in the history.
+bool PacketList::havePreviousHistory(bool update_cur)
+{
+ if (selection_history_.size() < 1 || cur_history_ < 1) {
+ return false;
+ }
+
+ for (int i = cur_history_ - 1; i >= 0; i--) {
+ if (packet_list_model_->packetNumberToRow(selection_history_.at(i)) >= 0) {
+ if (update_cur) {
+ cur_history_ = i;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
// prefs.col_list has changed.
void PacketList::columnsChanged()
{
@@ -916,12 +961,14 @@ void PacketList::thaw(bool restore_selection)
}
void PacketList::clear() {
- // packet_history_clear();
related_packet_delegate_.clear();
selectionModel()->clear();
packet_list_model_->clear();
proto_tree_->clear();
byte_view_tab_->clear();
+ selection_history_.clear();
+ cur_history_ = -1;
+ in_history_ = false;
QImage overlay;
overlay_sb_->setNearOverlayImage(overlay);
@@ -1121,6 +1168,12 @@ void PacketList::setMonospaceFont(const QFont &mono_font)
}
void PacketList::goNextPacket(void) {
+ if (QApplication::keyboardModifiers() | Qt::MetaModifier) {
+ // Alt+toolbar
+ goNextHistoryPacket();
+ return;
+ }
+
if (selectionModel()->hasSelection()) {
setCurrentIndex(moveCursor(MoveDown, Qt::NoModifier));
} else {
@@ -1130,6 +1183,12 @@ void PacketList::goNextPacket(void) {
}
void PacketList::goPreviousPacket(void) {
+ if (QApplication::keyboardModifiers() | Qt::MetaModifier) {
+ // Alt+toolbar
+ goPreviousHistoryPacket();
+ return;
+ }
+
if (selectionModel()->hasSelection()) {
setCurrentIndex(moveCursor(MoveUp, Qt::NoModifier));
} else {
@@ -1170,6 +1229,24 @@ void PacketList::goToPacket(int packet, int hf_id)
proto_tree_->goToField(hf_id);
}
+void PacketList::goNextHistoryPacket()
+{
+ if (haveNextHistory(true)) {
+ in_history_ = true;
+ goToPacket(selection_history_.at(cur_history_));
+ in_history_ = false;
+ }
+}
+
+void PacketList::goPreviousHistoryPacket()
+{
+ if (havePreviousHistory(true)) {
+ in_history_ = true;
+ goToPacket(selection_history_.at(cur_history_));
+ in_history_ = false;
+ }
+}
+
void PacketList::markFrame()
{
if (!cap_file_ || !packet_list_model_) return;