diff options
author | Roland Knall <rknall@gmail.com> | 2019-11-20 16:34:18 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2019-11-20 16:21:51 +0000 |
commit | 0d534873dc6d2c5d5452e465f9313b412225078b (patch) | |
tree | b754932d4fc8ae7c6007fe03dc47fc597c255d3d | |
parent | b7ce4e3f7a6a8a256da4dfdd535898f7fc41d7eb (diff) |
Qt: Speed up selection handling
Improve the speed for selection checks in PacketList and MainWindow
Change-Id: Ic3a413624463a798b5d13102965f75c7b1347b5f
Reviewed-on: https://code.wireshark.org/review/35160
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
-rw-r--r-- | ui/qt/main_window.cpp | 7 | ||||
-rw-r--r-- | ui/qt/main_window.h | 1 | ||||
-rw-r--r-- | ui/qt/models/related_packet_delegate.cpp | 2 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 41 |
4 files changed, 30 insertions, 21 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index b4ccaef11d..3dbd5a59bd 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -2889,6 +2889,13 @@ void MainWindow::setMwFileName(QString fileName) return; } +bool MainWindow::hasSelection() +{ + if (packet_list_) + return packet_list_->multiSelectActive(); + return false; +} + QList<int> MainWindow::selectedRows(bool useFrameNum) { if (packet_list_) diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index d92a001b3e..82f51ae58e 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -133,6 +133,7 @@ public: void insertColumn(QString name, QString abbrev, gint pos = -1); + bool hasSelection(); QList<int> selectedRows(bool useFrameNum = false); frame_data * frameDataForRow(int row) const; diff --git a/ui/qt/models/related_packet_delegate.cpp b/ui/qt/models/related_packet_delegate.cpp index d6d4d2c870..ac04a586d0 100644 --- a/ui/qt/models/related_packet_delegate.cpp +++ b/ui/qt/models/related_packet_delegate.cpp @@ -45,7 +45,7 @@ void RelatedPacketDelegate::paint(QPainter *painter, const QStyleOptionViewItem if (wsApp && wsApp->mainWindow()) { MainWindow * mw = qobject_cast<MainWindow *>(wsApp->mainWindow()); - if (mw && mw->selectedRows().count() > 1) + if (mw && mw->hasSelection()) { QStyledItemDelegate::paint(painter, option, index); return; diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index abfc715d62..b7a1be3bbb 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -412,30 +412,28 @@ void PacketList::setProtoTree (ProtoTree *proto_tree) { bool PacketList::multiSelectActive() { - return selectedRows().count() > 1 ? true : false; + return selectionModel()->selectedRows(0).count() > 1 ? true : false; } QList<int> PacketList::selectedRows(bool useFrameNum) { QList<int> rows; - if (selectionModel() && selectionModel()->selectedIndexes().count() > 0) + if (selectionModel() && selectionModel()->hasSelection()) { - foreach (QModelIndex idx, selectionModel()->selectedIndexes()) + foreach (QModelIndex idx, selectionModel()->selectedRows(0)) { if (idx.isValid()) { - if (! useFrameNum && ! rows.contains(idx.row())) + if (! useFrameNum) rows << idx.row(); else if (useFrameNum) { frame_data * frame = getFDataForRow(idx.row()); - if (frame && ! rows.contains(frame->num)) + if (frame) rows << frame->num; } } } - - std::sort(rows.begin(), rows.end(), std::less<int>()); } else if (currentIndex().isValid()) { @@ -467,12 +465,13 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS if (selectionModel()) { - if (selectionModel()->selectedRows(0).count() > 1) + QModelIndexList selRows = selectionModel()->selectedRows(0); + if (selRows.count() > 1) { QList<int> rows; - foreach (QModelIndex idx, selectionModel()->selectedRows(0)) + foreach (QModelIndex idx, selRows) { - if (idx.isValid() && ! rows.contains(idx.row())) + if (idx.isValid()) rows << idx.row(); } @@ -492,14 +491,14 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS return; } - else if (selectionModel()->selectedIndexes().count() > 0 && selectionModel()->selectedIndexes().at(0).isValid()) + else if (selRows.count() > 0 && selRows.at(0).isValid()) { multiSelect = false; - row = selectionModel()->selectedIndexes().at(0).row(); + row = selRows.at(0).row(); } /* Handling empty selection */ - if (selectionModel()->selectedIndexes().count() <= 0) + if (selRows.count() <= 0) { /* Nothing selected, but multiSelect is still active */ if (multiSelect) @@ -872,10 +871,11 @@ void PacketList::keyPressEvent(QKeyEvent *event) if (event->matches(QKeySequence::Copy)) { QStringList content; - if (model() && selectionModel() && selectionModel()->selectedRows(0).count() > 0) + if (model() && selectionModel() && selectionModel()->hasSelection()) { QList<int> rows; - foreach(QModelIndex row, selectionModel()->selectedRows(0)) + QModelIndexList selRows = selectionModel()->selectedRows(0); + foreach(QModelIndex row, selRows) rows.append(row.row()); foreach(int row, rows) @@ -1546,12 +1546,13 @@ void PacketList::markFrame() QModelIndexList frames; - if (selectionModel() && selectionModel()->selectedRows(0).count() > 1) + if (selectionModel() && selectionModel()->hasSelection()) { QList<int> rows; - foreach (QModelIndex idx, selectionModel()->selectedRows(0)) + QModelIndexList selRows = selectionModel()->selectedRows(0); + foreach (QModelIndex idx, selRows) { - if (idx.isValid() && ! rows.contains(idx.row())) + if (idx.isValid()) { frames << idx; rows << idx.row(); @@ -1581,12 +1582,12 @@ void PacketList::ignoreFrame() QModelIndexList frames; - if (selectionModel() && selectionModel()->selectedRows(0).count() > 1) + if (selectionModel() && selectionModel()->hasSelection()) { QList<int> rows; foreach (QModelIndex idx, selectionModel()->selectedRows(0)) { - if (idx.isValid() && ! rows.contains(idx.row())) + if (idx.isValid()) { frames << idx; rows << idx.row(); |