diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-02-26 13:02:06 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-03-12 16:29:58 +0000 |
commit | 5ab84900881289546a0aa3beb577af5383898e2e (patch) | |
tree | 35718a51fe7e4131877cd19d02995d5f6a118547 /ui/qt/packet_list_model.cpp | |
parent | 410b40d37145ac217db41ea6bc403c36ab53195d (diff) |
Qt: Allow multiple lines in the packet list.
Remove the setUniformRowHeights(true) call in the PacketList
constructor. This means that the packet list now calculates its height
by querying the Qt::SizeHintRole for every item instead of simply
multiplying item_height * number_of_rows.
Implement SizeHintRole in PacketListModel::data so that size
calculations aren't unbearably slow. We don't have any row text until an
item is drawn (via DisplayRole), so items with multiple lines end up
being rendered twice. Note where we make assumptions on line heights.
Although we call gtk_tree_view_set_fixed_height_mode() in the GTK+ UI we
don't have this problem there. GTK+ is apparently less strict about
enforcing row heights.
Bug: 10924
Change-Id: I98e9f4f5f321c2e03f18498e0a7e7556f88792a1
Reviewed-on: https://code.wireshark.org/review/7430
Petri-Dish: Evan Huus <eapache@gmail.com>
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/packet_list_model.cpp')
-rw-r--r-- | ui/qt/packet_list_model.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp index b10af13a18..56135e4731 100644 --- a/ui/qt/packet_list_model.cpp +++ b/ui/qt/packet_list_model.cpp @@ -38,9 +38,14 @@ #include <QModelIndex> PacketListModel::PacketListModel(QObject *parent, capture_file *cf) : - QAbstractItemModel(parent) + QAbstractItemModel(parent), + row_height_(-1), + line_spacing_(0) { setCaptureFile(cf); + connect(this, SIGNAL(itemHeightChanged(QModelIndex)), + this, SLOT(emitItemHeightChanged(QModelIndex)), + Qt::QueuedConnection); } void PacketListModel::setCaptureFile(capture_file *cf) @@ -50,11 +55,8 @@ void PacketListModel::setCaptureFile(capture_file *cf) } // Packet list records have no children (for now, at least). -QModelIndex PacketListModel::index(int row, int column, const QModelIndex &parent) - const +QModelIndex PacketListModel::index(int row, int column, const QModelIndex &) const { - Q_UNUSED(parent); - if (row >= visible_rows_.count() || row < 0 || !cap_file_ || column >= prefs.num_cols) return QModelIndex(); @@ -64,9 +66,8 @@ QModelIndex PacketListModel::index(int row, int column, const QModelIndex &paren } // Everything is under the root. -QModelIndex PacketListModel::parent(const QModelIndex &index) const +QModelIndex PacketListModel::parent(const QModelIndex &) const { - Q_UNUSED(index); return QModelIndex(); } @@ -133,9 +134,12 @@ int PacketListModel::columnTextSize(const char *str) return fm.width(str); } -void PacketListModel::setMonospaceFont(const QFont &mono_font) +void PacketListModel::setMonospaceFont(const QFont &mono_font, int row_height) { + QFontMetrics fm(mono_font_); mono_font_ = mono_font; + row_height_ = row_height; + line_spacing_ = fm.lineSpacing(); } // The Qt MVC documentation suggests using QSortFilterProxyModel for sorting @@ -235,6 +239,11 @@ bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2) } } +void PacketListModel::emitItemHeightChanged(const QModelIndex &index) +{ + emit dataChanged(index, index); +} + int PacketListModel::rowCount(const QModelIndex &parent) const { if (parent.column() >= prefs.num_cols) @@ -243,10 +252,8 @@ int PacketListModel::rowCount(const QModelIndex &parent) const return visible_rows_.count(); } -int PacketListModel::columnCount(const QModelIndex &parent) const +int PacketListModel::columnCount(const QModelIndex &) const { - Q_UNUSED(parent); - return prefs.num_cols; } @@ -313,7 +320,20 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const case Qt::DisplayRole: { int column = index.column(); - return record->columnString(cap_file_, column); + QVariant column_string = record->columnString(cap_file_, column); + // We don't know an item's sizeHint until we fetch its text here. + // 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()) + emit itemHeightChanged(index); + return column_string; + } + case Qt::SizeHintRole: + { + // We assume that inter-line spacing is 0. + QSize size = QSize(-1, row_height_ + ((record->lineCount() - 1) * line_spacing_)); + return size; } default: return QVariant(); |