summaryrefslogtreecommitdiff
path: root/ui/qt/packet_list_model.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-09-16 10:46:45 -0700
committerGerald Combs <gerald@wireshark.org>2015-09-17 19:37:48 +0000
commitae4d99b670c97e418e9d14417827326d912e76fb (patch)
treea4bfe18a2b80b3c356f13a63fd140613e2fb1880 /ui/qt/packet_list_model.cpp
parentdabdc30686c6cbce23691bbed01edbea44efb504 (diff)
downloadwireshark-ae4d99b670c97e418e9d14417827326d912e76fb.tar.gz
Packet list speedups.
beginInsertRows + endInsertRows is expensive. Instead of calling them each time we add a packet to the list, queue up a list of visible packets and flush it during the next UI update. Assume that none of our column data has newlines. Enable uniformRowHeights and only disable it when we need to. Note that this requires further work. Ping-Bug: 11515 Ping-Bug: 10924 Change-Id: Ifbdd2964b174247a4745d4889ebda5bf3b886ba4 Reviewed-on: https://code.wireshark.org/review/10553 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/packet_list_model.cpp')
-rw-r--r--ui/qt/packet_list_model.cpp60
1 files changed, 41 insertions, 19 deletions
diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp
index 404dda58ab..70cc7f3f4e 100644
--- a/ui/qt/packet_list_model.cpp
+++ b/ui/qt/packet_list_model.cpp
@@ -46,7 +46,7 @@
PacketListModel::PacketListModel(QObject *parent, capture_file *cf) :
QAbstractItemModel(parent),
- size_hint_enabled_(true),
+ uniform_row_heights_(true),
row_height_(-1),
line_spacing_(0)
{
@@ -88,7 +88,6 @@ int PacketListModel::packetNumberToRow(int packet_num) const
guint PacketListModel::recreateVisibleRows()
{
int pos = visible_rows_.count();
- PacketListRecord *record;
beginResetModel();
visible_rows_.clear();
@@ -96,7 +95,7 @@ guint PacketListModel::recreateVisibleRows()
endResetModel();
beginInsertRows(QModelIndex(), pos, pos);
- foreach (record, physical_rows_) {
+ foreach (PacketListRecord *record, physical_rows_) {
if (record->frameData()->flags.passed_dfilter || record->frameData()->flags.ref_time) {
visible_rows_ << record;
number_to_row_[record->frameData()->num] = visible_rows_.count() - 1;
@@ -114,6 +113,7 @@ void PacketListModel::clear() {
number_to_row_.clear();
PacketListRecord::clearStringPool();
endResetModel();
+ uniform_row_heights_ = true;
}
void PacketListModel::resetColumns()
@@ -389,8 +389,13 @@ bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2)
}
}
+// ::data is const so we have to make changes here.
void PacketListModel::emitItemHeightChanged(const QModelIndex &ih_index)
{
+ if (uniform_row_heights_) {
+ uniform_row_heights_ = false;
+ emit rowHeightsVary();
+ }
emit dataChanged(ih_index, ih_index);
}
@@ -475,20 +480,16 @@ QVariant PacketListModel::data(const QModelIndex &d_index, int role) const
// Assume each line count is 1. If the line count changes, emit
// itemHeightChanged which triggers another redraw (including a
// fetch of SizeHintRole and DisplayRole) in the next event loop.
- if (column == 0 && record->lineCountChanged())
+ if (column == 0 && record->lineCountChanged()) {
emit itemHeightChanged(d_index);
+ }
return column_string;
}
case Qt::SizeHintRole:
{
- if (size_hint_enabled_) {
- // We assume that inter-line spacing is 0.
- QSize size = QSize(-1, row_height_ + ((record->lineCount() - 1) * line_spacing_));
- return size;
- } else {
- // Used by PacketList::sizeHintForColumn
- return QVariant();
- }
+ // We assume that inter-line spacing is 0.
+ QSize size = QSize(-1, row_height_ + ((record->lineCount() - 1) * line_spacing_));
+ return size;
}
default:
return QVariant();
@@ -514,21 +515,42 @@ QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
return QVariant();
}
+void PacketListModel::flushVisibleRows()
+{
+ gint pos = visible_rows_.count();
+
+ if (new_visible_rows_.count() > 0) {
+ beginInsertRows(QModelIndex(), pos, pos + new_visible_rows_.count());
+ foreach (PacketListRecord *record, new_visible_rows_) {
+ frame_data *fdata = record->frameData();
+
+ visible_rows_ << record;
+ number_to_row_[fdata->num] = visible_rows_.count() - 1;
+ }
+ endInsertRows();
+ new_visible_rows_.clear();
+ }
+}
+
+// XXX Pass in cinfo from packet_list_append so that we can fill in
+// line counts?
gint PacketListModel::appendPacket(frame_data *fdata)
{
PacketListRecord *record = new PacketListRecord(fdata);
- gint pos = visible_rows_.count();
+ gint pos = -1;
physical_rows_ << record;
if (fdata->flags.passed_dfilter || fdata->flags.ref_time) {
- beginInsertRows(QModelIndex(), pos, pos);
- visible_rows_ << record;
- number_to_row_[fdata->num] = visible_rows_.count() - 1;
- endInsertRows();
- } else {
- pos = -1;
+ new_visible_rows_ << record;
+ if (new_visible_rows_.count() < 2) {
+ // This is the first queued packet. Schedule an insertion for
+ // the next UI update.
+ QTimer::singleShot(0, this, SLOT(flushVisibleRows()));
+ }
+ pos = visible_rows_.count() + new_visible_rows_.count() - 1;
}
+
return pos;
}