aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-11-19 13:11:36 +0100
committerRoland Knall <rknall@gmail.com>2019-11-19 14:18:11 +0000
commitc07aad10159327ef09041c80c2de71ce576505fb (patch)
treed28fdfab25fdd98055453b2e2770477f412d248e
parent10789049817eba945c748dafa3cf8440e40f57f0 (diff)
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>
-rw-r--r--ui/qt/models/packet_list_model.cpp56
-rw-r--r--ui/qt/models/packet_list_model.h2
-rw-r--r--ui/qt/models/packet_list_record.cpp10
-rw-r--r--ui/qt/models/packet_list_record.h5
-rw-r--r--ui/qt/packet_list.cpp2
5 files changed, 31 insertions, 44 deletions
diff --git a/ui/qt/models/packet_list_model.cpp b/ui/qt/models/packet_list_model.cpp
index 2dee702ac8..3bd0cfd4f6 100644
--- a/ui/qt/models/packet_list_model.cpp
+++ b/ui/qt/models/packet_list_model.cpp
@@ -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;
diff --git a/ui/qt/models/packet_list_model.h b/ui/qt/models/packet_list_model.h
index a886009c00..2bb0621c44 100644
--- a/ui/qt/models/packet_list_model.h
+++ b/ui/qt/models/packet_list_model.h
@@ -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);
diff --git a/ui/qt/models/packet_list_record.cpp b/ui/qt/models/packet_list_record.cpp
index dd0ff360eb..893d5645a6 100644
--- a/ui/qt/models/packet_list_record.cpp
+++ b/ui/qt/models/packet_list_record.cpp
@@ -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_;
diff --git a/ui/qt/models/packet_list_record.h b/ui/qt/models/packet_list_record.h
index 99a2a2b5ad..0e3f7df72b 100644
--- a/ui/qt/models/packet_list_record.h
+++ b/ui/qt/models/packet_list_record.h
@@ -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 */
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp
index f041fcac57..bb91850f37 100644
--- a/ui/qt/packet_list.cpp
+++ b/ui/qt/packet_list.cpp
@@ -1603,7 +1603,7 @@ void PacketList::unsetAllTimeReferences()
void PacketList::applyTimeShift()
{
- packet_list_model_->applyTimeShift();
+ packet_list_model_->resetColumns();
redrawVisiblePackets();
// XXX emit packetDissectionChanged(); ?
}