Qt: Speedup Packetlist

Make dataChanged more specific and remove unnecessary iteration
in case of recoloring

Change-Id: I1ee270623b1cb8ac3907a5d45d6a8c4c5027c322
Reviewed-on: https://code.wireshark.org/review/35135
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2019-11-19 13:11:36 +01:00
parent 1078904981
commit c07aad1015
5 changed files with 31 additions and 44 deletions

View File

@ -25,6 +25,7 @@
#include "frame_tvbuff.h"
#include <ui/qt/utils/color_utils.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include "wireshark_application.h"
#include <ui/qt/main_window.h>
#include <ui/qt/main_status_bar.h>
@ -177,25 +178,24 @@ void PacketListModel::clear() {
void PacketListModel::invalidateAllColumnStrings()
{
PacketListRecord::invalidateAllRecords();
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
emit headerDataChanged(Qt::Horizontal, 0, columnCount() - 1);
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1),
QVector<int>() << Qt::DisplayRole);
}
void PacketListModel::resetColumns()
{
if (cap_file_) {
emit beginResetModel();
PacketListRecord::resetColumns(&cap_file_->cinfo);
emit endResetModel();
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
emit headerDataChanged(Qt::Horizontal, 0, columnCount() - 1);
}
void PacketListModel::resetColorized()
{
foreach (PacketListRecord *record, physical_rows_) {
record->resetColorized();
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
PacketListRecord::resetColorization();
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1),
QVector<int>() << Qt::BackgroundRole << Qt::ForegroundRole);
}
void PacketListModel::toggleFrameMark(const QModelIndexList &indeces)
@ -236,7 +236,8 @@ void PacketListModel::setDisplayedFrameMark(gboolean set)
cf_unmark_frame(cap_file_, record->frameData());
}
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1),
QVector<int>() << Qt::BackgroundRole << Qt::ForegroundRole);
}
void PacketListModel::toggleFrameIgnore(const QModelIndexList &indeces)
@ -277,7 +278,8 @@ void PacketListModel::setDisplayedFrameIgnore(gboolean set)
cf_unignore_frame(cap_file_, record->frameData());
}
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1),
QVector<int>() << Qt::BackgroundRole << Qt::ForegroundRole << Qt::DisplayRole);
}
void PacketListModel::toggleFrameRefTime(const QModelIndex &rt_index)
@ -323,12 +325,6 @@ void PacketListModel::unsetAllFrameRefTime()
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void PacketListModel::applyTimeShift()
{
resetColumns();
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void PacketListModel::setMaximumRowHeight(int height)
{
max_row_height_ = height;
@ -338,18 +334,6 @@ void PacketListModel::setMaximumRowHeight(int height)
emit dataChanged(index(0, 0), index(0, columnCount() - 1));
}
//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
// and filtering. That seems like overkill but it might be something we want
// to do in the future.
int PacketListModel::sort_column_;
int PacketListModel::sort_column_is_numeric_;
int PacketListModel::text_sort_column_;
@ -661,14 +645,9 @@ QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
if (orientation == Qt::Horizontal && section < prefs.num_cols) {
switch (role) {
case Qt::DisplayRole:
return get_column_title(section);
return qVariantFromValue(QString(get_column_title(section)));
case Qt::ToolTipRole:
{
gchar *tooltip = get_column_tooltip(section);
QVariant data(tooltip);
g_free (tooltip);
return data;
}
return qVariantFromValue(gchar_free_to_qstring(get_column_tooltip(section)));
default:
break;
}
@ -757,6 +736,13 @@ gint PacketListModel::appendPacket(frame_data *fdata)
return pos;
}
frame_data *PacketListModel::getRowFdata(QModelIndex idx)
{
if (!idx.isValid())
return Q_NULLPTR;
return getRowFdata(idx.row());
}
frame_data *PacketListModel::getRowFdata(int row) {
if (row < 0 || row >= visible_rows_.count())
return NULL;

View File

@ -48,6 +48,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
gint appendPacket(frame_data *fdata);
frame_data *getRowFdata(QModelIndex idx);
frame_data *getRowFdata(int row);
void ensureRowColorized(int row);
int visibleIndexOf(frame_data *fdata) const;
@ -66,7 +67,6 @@ public:
void setDisplayedFrameIgnore(gboolean set);
void toggleFrameRefTime(const QModelIndex &rt_index);
void unsetAllFrameRefTime();
void applyTimeShift();
void setMaximumRowHeight(int height);

View File

@ -27,6 +27,7 @@
QMap<int, int> PacketListRecord::cinfo_column_;
unsigned PacketListRecord::col_data_ver_ = 1;
unsigned PacketListRecord::rows_color_ver_ = 1;
PacketListRecord::PacketListRecord(frame_data *frameData) :
fdata_(frameData),
@ -34,6 +35,7 @@ PacketListRecord::PacketListRecord(frame_data *frameData) :
line_count_changed_(false),
data_ver_(0),
colorized_(false),
color_ver_(0),
conv_index_(0)
{
}
@ -54,7 +56,7 @@ const QString PacketListRecord::columnString(capture_file *cap_file, int column,
return QString();
}
bool dissect_color = colorized && !colorized_;
bool dissect_color = ( colorized && !colorized_ ) || ( color_ver_ != rows_color_ver_ );
if (column >= col_text_.count() || col_text_.at(column).isNull() || data_ver_ != col_data_ver_ || dissect_color) {
dissect(cap_file, dissect_color);
}
@ -80,11 +82,6 @@ void PacketListRecord::resetColumns(column_info *cinfo)
}
}
void PacketListRecord::resetColorized()
{
colorized_ = false;
}
void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
{
// packet_list_store.c:packet_list_dissect_and_cache_record
@ -175,6 +172,7 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
if (dissect_color) {
colorized_ = true;
color_ver_ = rows_color_ver_;
}
data_ver_ = col_data_ver_;

View File

@ -43,7 +43,8 @@ public:
int columnTextSize(const char *str);
static void invalidateAllRecords() { col_data_ver_++; }
static void resetColumns(column_info *cinfo);
void resetColorized();
static void resetColorization() { rows_color_ver_++; }
inline int lineCount() { return lines_; }
inline int lineCountChanged() { return line_count_changed_; }
@ -60,6 +61,8 @@ private:
static unsigned col_data_ver_;
unsigned data_ver_;
/** Has this record been colorized? */
static unsigned int rows_color_ver_;
unsigned int color_ver_;
bool colorized_;
/** Conversation. Used by RelatedPacketDelegate */

View File

@ -1603,7 +1603,7 @@ void PacketList::unsetAllTimeReferences()
void PacketList::applyTimeShift()
{
packet_list_model_->applyTimeShift();
packet_list_model_->resetColumns();
redrawVisiblePackets();
// XXX emit packetDissectionChanged(); ?
}