forked from osmocom/wireshark
Revert "Qt: Remove unnecessary ColumnText object"
This has to be a complete overhaul of PacketListRecord. For now it is reverted
This reverts commit d95262bf74
.
Change-Id: Id72dc6911f68c9b811110332588b3da474791d31
Reviewed-on: https://code.wireshark.org/review/33666
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
d7ef3118b1
commit
a9d7c2b94f
|
@ -318,7 +318,7 @@ void PacketListModel::sort(int column, Qt::SortOrder order)
|
|||
emit pushProgressStatus(tr("Dissecting"), true, true, &stop_flag);
|
||||
int row_num = 0;
|
||||
foreach (PacketListRecord *row, physical_rows_) {
|
||||
row->ensureDissection(sort_cap_file_, column);
|
||||
row->columnString(sort_cap_file_, column);
|
||||
row_num++;
|
||||
if (busy_timer_.elapsed() > busy_timeout_) {
|
||||
if (stop_flag) {
|
||||
|
@ -458,7 +458,7 @@ bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2)
|
|||
// Column comes directly from frame data
|
||||
cmp_val = frame_data_compare(sort_cap_file_->epan, r1->frameData(), r2->frameData(), sort_cap_file_->cinfo.columns[sort_column_].col_fmt);
|
||||
} else {
|
||||
if (r1->columnString(sort_cap_file_, sort_column_).compare(r2->columnString(sort_cap_file_, sort_column_)) == 0) {
|
||||
if (r1->columnString(sort_cap_file_, sort_column_).constData() == r2->columnString(sort_cap_file_, sort_column_).constData()) {
|
||||
cmp_val = 0;
|
||||
} else if (sort_column_is_numeric_) {
|
||||
// Custom column with numeric data (or something like a port number).
|
||||
|
@ -478,7 +478,7 @@ bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2)
|
|||
cmp_val = 1;
|
||||
}
|
||||
} else {
|
||||
cmp_val = r1->columnString(sort_cap_file_, sort_column_).compare(r2->columnString(sort_cap_file_, sort_column_));
|
||||
cmp_val = strcmp(r1->columnString(sort_cap_file_, sort_column_).constData(), r2->columnString(sort_cap_file_, sort_column_).constData());
|
||||
}
|
||||
|
||||
if (cmp_val == 0) {
|
||||
|
@ -595,7 +595,7 @@ QVariant PacketListModel::data(const QModelIndex &d_index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
{
|
||||
int column = d_index.column();
|
||||
QString column_string = record->columnString(cap_file_, column, true);
|
||||
QByteArray column_string = record->columnString(cap_file_, column, true);
|
||||
// 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
|
||||
|
@ -741,7 +741,7 @@ void PacketListModel::ensureRowColorized(int row)
|
|||
if (!record)
|
||||
return;
|
||||
if (!record->colorized()) {
|
||||
record->ensureDissection(cap_file_, 1, true);
|
||||
record->columnString(cap_file_, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,10 +23,21 @@
|
|||
|
||||
#include <QStringList>
|
||||
|
||||
class ColumnTextList : public QList<const char *> {
|
||||
public:
|
||||
// Allocate our records using wmem.
|
||||
static void *operator new(size_t size) {
|
||||
return wmem_alloc(wmem_file_scope(), size);
|
||||
}
|
||||
|
||||
static void operator delete(void *) {}
|
||||
};
|
||||
|
||||
QMap<int, int> PacketListRecord::cinfo_column_;
|
||||
unsigned PacketListRecord::col_data_ver_ = 1;
|
||||
|
||||
PacketListRecord::PacketListRecord(frame_data *frameData, struct _GStringChunk *string_cache_pool) :
|
||||
col_text_(0),
|
||||
fdata_(frameData),
|
||||
lines_(1),
|
||||
line_count_changed_(false),
|
||||
|
@ -44,30 +55,21 @@ void *PacketListRecord::operator new(size_t size)
|
|||
|
||||
// We might want to return a const char * instead. This would keep us from
|
||||
// creating excessive QByteArrays, e.g. in PacketListModel::recordLessThan.
|
||||
const QString PacketListRecord::columnString(capture_file *cap_file, int column, bool colorized)
|
||||
{
|
||||
if ( ensureDissection(cap_file, column, colorized) )
|
||||
return col_text_.at(column);
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool PacketListRecord::ensureDissection(capture_file *cap_file, int column, bool colorized)
|
||||
const QByteArray PacketListRecord::columnString(capture_file *cap_file, int column, bool colorized)
|
||||
{
|
||||
// packet_list_store.c:packet_list_get_value
|
||||
Q_ASSERT(fdata_);
|
||||
g_assert(fdata_);
|
||||
|
||||
if (!cap_file || column < 0 || column > cap_file->cinfo.num_cols) {
|
||||
return false;
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
bool dissect_color = colorized && !colorized_;
|
||||
if (col_text_.isEmpty() || column >= col_text_.size() || data_ver_ != col_data_ver_ || dissect_color) {
|
||||
if (!col_text_ || column >= col_text_->size() || !col_text_->at(column) || data_ver_ != col_data_ver_ || dissect_color) {
|
||||
dissect(cap_file, dissect_color);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return col_text_->value(column, QByteArray());
|
||||
}
|
||||
|
||||
void PacketListRecord::resetColumns(column_info *cinfo)
|
||||
|
@ -102,7 +104,8 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
|
|||
wtap_rec rec; /* Record metadata */
|
||||
Buffer buf; /* Record data */
|
||||
|
||||
gboolean dissect_columns = col_text_.isEmpty() || data_ver_ != col_data_ver_;
|
||||
if (!col_text_) col_text_ = new ColumnTextList;
|
||||
gboolean dissect_columns = col_text_->isEmpty() || data_ver_ != col_data_ver_;
|
||||
|
||||
if (!cap_file) {
|
||||
return;
|
||||
|
@ -203,8 +206,11 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
return;
|
||||
}
|
||||
|
||||
col_text_.clear();
|
||||
|
||||
if (col_text_) {
|
||||
col_text_->clear();
|
||||
} else {
|
||||
col_text_ = new ColumnTextList;
|
||||
}
|
||||
lines_ = 1;
|
||||
line_count_changed_ = false;
|
||||
|
||||
|
@ -217,7 +223,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
/* Column based on frame_data or it already contains a value */
|
||||
if (text_col < 0) {
|
||||
col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
|
||||
col_text_.append(cinfo->columns[column].col_data);
|
||||
col_text_->append(cinfo->columns[column].col_data);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -234,7 +240,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
// XXX - ui/gtk/packet_list_store.c uses G_MAXUSHORT. We don't do proper UTF8
|
||||
// truncation in either case.
|
||||
int col_text_len = MIN(qstrlen(cinfo->col_data[column]) + 1, COL_MAX_INFO_LEN);
|
||||
col_text_.append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len));
|
||||
col_text_->append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len));
|
||||
break;
|
||||
}
|
||||
/* !! FALL-THROUGH!! */
|
||||
|
@ -261,9 +267,9 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
|
||||
/* Use the unresolved value in col_expr_val */
|
||||
// XXX Use QContiguousCache?
|
||||
col_text_.append(cinfo->col_expr.col_expr_val[column]);
|
||||
col_text_->append(cinfo->col_expr.col_expr_val[column]);
|
||||
} else {
|
||||
col_text_.append(cinfo->columns[column].col_data);
|
||||
col_text_->append(cinfo->columns[column].col_data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -285,7 +291,7 @@ void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|||
// https://git.gnome.org/browse/glib/tree/glib/gstringchunk.c
|
||||
// We might be better off adding the equivalent functionality to
|
||||
// wmem_tree.
|
||||
col_text_.append(g_string_chunk_insert_const(string_cache_pool_, col_str));
|
||||
col_text_->append(g_string_chunk_insert_const(string_cache_pool_, col_str));
|
||||
for (int i = 0; col_str[i]; i++) {
|
||||
if (col_str[i] == '\n') col_lines++;
|
||||
}
|
||||
|
|
|
@ -38,15 +38,13 @@ public:
|
|||
static void operator delete(void *) {}
|
||||
|
||||
// Return the string value for a column. Data is cached if possible.
|
||||
const QString columnString(capture_file *cap_file, int column, bool colorized = false);
|
||||
const QByteArray columnString(capture_file *cap_file, int column, bool colorized = false);
|
||||
frame_data *frameData() const { return fdata_; }
|
||||
// packet_list->col_to_text in gtk/packet_list_store.c
|
||||
static int textColumn(int column) { return cinfo_column_.value(column, -1); }
|
||||
bool colorized() { return colorized_; }
|
||||
struct conversation *conversation() { return conv_; }
|
||||
|
||||
bool ensureDissection(capture_file * cap_file, int column, bool colorized = false);
|
||||
|
||||
int columnTextSize(const char *str);
|
||||
static void invalidateAllRecords() { col_data_ver_++; }
|
||||
static void resetColumns(column_info *cinfo);
|
||||
|
@ -55,7 +53,8 @@ public:
|
|||
inline int lineCountChanged() { return line_count_changed_; }
|
||||
|
||||
private:
|
||||
QStringList col_text_;
|
||||
/** The column text for some columns */
|
||||
ColumnTextList *col_text_;
|
||||
|
||||
frame_data *fdata_;
|
||||
int lines_;
|
||||
|
|
Loading…
Reference in New Issue