forked from osmocom/wireshark
Qt: Frame flag updates.
Move frame flag (mark, ignore, ref_time) member functions from PacketList to PacketListModel. They arguably belong there and we can emit dataChanged to signal updates. Rename some variables named "index" since they shadow a function name. Change-Id: I9a731a76e4e63e562b561c29d13915278d5a7dbb Reviewed-on: https://code.wireshark.org/review/9663 Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
b1e0f439e1
commit
41ed7127a5
|
@ -587,45 +587,6 @@ void PacketList::timerEvent(QTimerEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::markFramesReady()
|
|
||||||
{
|
|
||||||
packets_bar_update();
|
|
||||||
redrawVisiblePackets();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PacketList::setFrameMark(gboolean set, frame_data *fdata)
|
|
||||||
{
|
|
||||||
if (set)
|
|
||||||
cf_mark_frame(cap_file_, fdata);
|
|
||||||
else
|
|
||||||
cf_unmark_frame(cap_file_, fdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PacketList::setFrameIgnore(gboolean set, frame_data *fdata)
|
|
||||||
{
|
|
||||||
if (set)
|
|
||||||
cf_ignore_frame(cap_file_, fdata);
|
|
||||||
else
|
|
||||||
cf_unignore_frame(cap_file_, fdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PacketList::setFrameReftime(gboolean set, frame_data *fdata)
|
|
||||||
{
|
|
||||||
if (!fdata || !cap_file_) return;
|
|
||||||
if (set) {
|
|
||||||
fdata->flags.ref_time=1;
|
|
||||||
cap_file_->ref_time_count++;
|
|
||||||
} else {
|
|
||||||
fdata->flags.ref_time=0;
|
|
||||||
cap_file_->ref_time_count--;
|
|
||||||
}
|
|
||||||
cf_reftime_packets(cap_file_);
|
|
||||||
if (!fdata->flags.ref_time && !fdata->flags.passed_dfilter) {
|
|
||||||
cap_file_->displayed_count--;
|
|
||||||
packet_list_model_->recreateVisibleRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PacketList::setColumnVisibility()
|
void PacketList::setColumnVisibility()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < prefs.num_cols; i++) {
|
for (int i = 0; i < prefs.num_cols; i++) {
|
||||||
|
@ -1040,105 +1001,50 @@ void PacketList::goToPacket(int packet, int hf_id)
|
||||||
|
|
||||||
void PacketList::markFrame()
|
void PacketList::markFrame()
|
||||||
{
|
{
|
||||||
int row = currentIndex().row();
|
|
||||||
frame_data *fdata;
|
|
||||||
|
|
||||||
if (!cap_file_ || !packet_list_model_) return;
|
if (!cap_file_ || !packet_list_model_) return;
|
||||||
|
|
||||||
fdata = packet_list_model_->getRowFdata(row);
|
packet_list_model_->toggleFrameMark(currentIndex());
|
||||||
|
packets_bar_update();
|
||||||
if (!fdata) return;
|
|
||||||
|
|
||||||
setFrameMark(!fdata->flags.marked, fdata);
|
|
||||||
markFramesReady();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::markAllDisplayedFrames(bool set)
|
void PacketList::markAllDisplayedFrames(bool set)
|
||||||
{
|
{
|
||||||
guint32 framenum;
|
|
||||||
frame_data *fdata;
|
|
||||||
|
|
||||||
if (!cap_file_ || !packet_list_model_) return;
|
if (!cap_file_ || !packet_list_model_) return;
|
||||||
|
|
||||||
for (framenum = 1; framenum <= cap_file_->count; framenum++) {
|
packet_list_model_->setDisplayedFrameMark(set);
|
||||||
fdata = frame_data_sequence_find(cap_file_->frames, framenum);
|
packets_bar_update();
|
||||||
if (fdata->flags.passed_dfilter)
|
|
||||||
setFrameMark(set, fdata);
|
|
||||||
}
|
|
||||||
markFramesReady();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::ignoreFrame()
|
void PacketList::ignoreFrame()
|
||||||
{
|
{
|
||||||
int row = currentIndex().row();
|
|
||||||
frame_data *fdata;
|
|
||||||
|
|
||||||
if (!cap_file_ || !packet_list_model_) return;
|
if (!cap_file_ || !packet_list_model_) return;
|
||||||
|
|
||||||
fdata = packet_list_model_->getRowFdata(row);
|
packet_list_model_->toggleFrameIgnore(currentIndex());
|
||||||
if (!fdata) return;
|
int sb_val = verticalScrollBar()->value(); // Surely there's a better way to keep our position?
|
||||||
|
setUpdatesEnabled(false);
|
||||||
setFrameIgnore(!fdata->flags.ignored, fdata);
|
|
||||||
emit packetDissectionChanged();
|
emit packetDissectionChanged();
|
||||||
|
setUpdatesEnabled(true);
|
||||||
|
verticalScrollBar()->setValue(sb_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::ignoreAllDisplayedFrames(bool set)
|
void PacketList::ignoreAllDisplayedFrames(bool set)
|
||||||
{
|
{
|
||||||
guint32 framenum;
|
|
||||||
frame_data *fdata;
|
|
||||||
|
|
||||||
if (!cap_file_ || !packet_list_model_) return;
|
if (!cap_file_ || !packet_list_model_) return;
|
||||||
|
|
||||||
for (framenum = 1; framenum <= cap_file_->count; framenum++) {
|
packet_list_model_->setDisplayedFrameIgnore(set);
|
||||||
fdata = frame_data_sequence_find(cap_file_->frames, framenum);
|
|
||||||
if (!set || fdata->flags.passed_dfilter)
|
|
||||||
setFrameIgnore(set, fdata);
|
|
||||||
}
|
|
||||||
emit packetDissectionChanged();
|
emit packetDissectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::setTimeReference()
|
void PacketList::setTimeReference()
|
||||||
{
|
{
|
||||||
if (!cap_file_) return;
|
if (!cap_file_ || !packet_list_model_) return;
|
||||||
|
packet_list_model_->toggleFrameRefTime(currentIndex());
|
||||||
if (cap_file_->current_frame) {
|
|
||||||
if(recent.gui_time_format != TS_RELATIVE && cap_file_->current_frame->flags.ref_time==0) {
|
|
||||||
int ret = QMessageBox::question(
|
|
||||||
this,
|
|
||||||
tr("Change Time Display Format?"),
|
|
||||||
tr("Time References don't work well with the currently selected Time Display Format.\n"
|
|
||||||
"Do you want to switch to \"Seconds Since Beginning of Capture\" now?"),
|
|
||||||
QMessageBox::Yes | QMessageBox::No
|
|
||||||
);
|
|
||||||
if (ret == QMessageBox::Yes) {
|
|
||||||
timestamp_set_type(TS_RELATIVE);
|
|
||||||
recent.gui_time_format = TS_RELATIVE;
|
|
||||||
cf_timestamp_auto_precision(cap_file_);
|
|
||||||
setFrameReftime(!cap_file_->current_frame->flags.ref_time,
|
|
||||||
cap_file_->current_frame);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setFrameReftime(!cap_file_->current_frame->flags.ref_time,
|
|
||||||
cap_file_->current_frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
redrawVisiblePackets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::unsetAllTimeReferences()
|
void PacketList::unsetAllTimeReferences()
|
||||||
{
|
{
|
||||||
if (!cap_file_) return;
|
if (!cap_file_ || !packet_list_model_) return;
|
||||||
|
packet_list_model_->unsetAllFrameRefTime();
|
||||||
/* XXX: we might need a progressbar here */
|
|
||||||
guint32 framenum;
|
|
||||||
frame_data *fdata;
|
|
||||||
for (framenum = 1; framenum <= cap_file_->count && cap_file_->ref_time_count > 0; framenum++) {
|
|
||||||
fdata = frame_data_sequence_find(cap_file_->frames, framenum);
|
|
||||||
if (fdata->flags.ref_time == 1) {
|
|
||||||
setFrameReftime(FALSE, fdata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
redrawVisiblePackets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::showHeaderMenu(QPoint pos)
|
void PacketList::showHeaderMenu(QPoint pos)
|
||||||
|
|
|
@ -102,9 +102,6 @@ private:
|
||||||
bool tail_at_end_;
|
bool tail_at_end_;
|
||||||
bool rows_inserted_;
|
bool rows_inserted_;
|
||||||
|
|
||||||
void markFramesReady();
|
|
||||||
void setFrameMark(gboolean set, frame_data *fdata);
|
|
||||||
void setFrameIgnore(gboolean set, frame_data *fdata);
|
|
||||||
void setFrameReftime(gboolean set, frame_data *fdata);
|
void setFrameReftime(gboolean set, frame_data *fdata);
|
||||||
void setColumnVisibility();
|
void setColumnVisibility();
|
||||||
int sizeHintForColumn(int column) const;
|
int sizeHintForColumn(int column) const;
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include "packet_list_model.h"
|
#include "packet_list_model.h"
|
||||||
|
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
#include <wsutil/nstime.h>
|
#include <wsutil/nstime.h>
|
||||||
#include <epan/column.h>
|
#include <epan/column.h>
|
||||||
#include <epan/prefs.h>
|
#include <epan/prefs.h>
|
||||||
|
@ -119,14 +121,113 @@ void PacketListModel::resetColumns()
|
||||||
|
|
||||||
void PacketListModel::resetColorized()
|
void PacketListModel::resetColorized()
|
||||||
{
|
{
|
||||||
PacketListRecord *record;
|
foreach (PacketListRecord *record, physical_rows_) {
|
||||||
|
|
||||||
foreach (record, physical_rows_) {
|
|
||||||
record->resetColorized();
|
record->resetColorized();
|
||||||
}
|
}
|
||||||
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PacketListModel::toggleFrameMark(const QModelIndex &fm_index)
|
||||||
|
{
|
||||||
|
if (!cap_file_ || !fm_index.isValid()) return;
|
||||||
|
|
||||||
|
PacketListRecord *record = static_cast<PacketListRecord*>(fm_index.internalPointer());
|
||||||
|
if (!record) return;
|
||||||
|
|
||||||
|
frame_data *fdata = record->frameData();
|
||||||
|
if (!fdata) return;
|
||||||
|
|
||||||
|
if (fdata->flags.marked)
|
||||||
|
cf_unmark_frame(cap_file_, fdata);
|
||||||
|
else
|
||||||
|
cf_mark_frame(cap_file_, fdata);
|
||||||
|
|
||||||
|
dataChanged(fm_index, fm_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketListModel::setDisplayedFrameMark(gboolean set)
|
||||||
|
{
|
||||||
|
foreach (PacketListRecord *record, visible_rows_) {
|
||||||
|
if (set) {
|
||||||
|
cf_mark_frame(cap_file_, record->frameData());
|
||||||
|
} else {
|
||||||
|
cf_unmark_frame(cap_file_, record->frameData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketListModel::toggleFrameIgnore(const QModelIndex &i_index)
|
||||||
|
{
|
||||||
|
if (!cap_file_ || !i_index.isValid()) return;
|
||||||
|
|
||||||
|
PacketListRecord *record = static_cast<PacketListRecord*>(i_index.internalPointer());
|
||||||
|
if (!record) return;
|
||||||
|
|
||||||
|
frame_data *fdata = record->frameData();
|
||||||
|
if (!fdata) return;
|
||||||
|
|
||||||
|
if (fdata->flags.ignored)
|
||||||
|
cf_unignore_frame(cap_file_, fdata);
|
||||||
|
else
|
||||||
|
cf_ignore_frame(cap_file_, fdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketListModel::setDisplayedFrameIgnore(gboolean set)
|
||||||
|
{
|
||||||
|
foreach (PacketListRecord *record, visible_rows_) {
|
||||||
|
if (set) {
|
||||||
|
cf_ignore_frame(cap_file_, record->frameData());
|
||||||
|
} else {
|
||||||
|
cf_unignore_frame(cap_file_, record->frameData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketListModel::toggleFrameRefTime(const QModelIndex &rt_index)
|
||||||
|
{
|
||||||
|
if (!cap_file_ || !rt_index.isValid()) return;
|
||||||
|
|
||||||
|
PacketListRecord *record = static_cast<PacketListRecord*>(rt_index.internalPointer());
|
||||||
|
if (!record) return;
|
||||||
|
|
||||||
|
frame_data *fdata = record->frameData();
|
||||||
|
if (!fdata) return;
|
||||||
|
|
||||||
|
if (fdata->flags.ref_time) {
|
||||||
|
fdata->flags.ref_time=0;
|
||||||
|
cap_file_->ref_time_count--;
|
||||||
|
} else {
|
||||||
|
fdata->flags.ref_time=1;
|
||||||
|
cap_file_->ref_time_count++;
|
||||||
|
}
|
||||||
|
cf_reftime_packets(cap_file_);
|
||||||
|
if (!fdata->flags.ref_time && !fdata->flags.passed_dfilter) {
|
||||||
|
cap_file_->displayed_count--;
|
||||||
|
}
|
||||||
|
record->resetColumns(&cap_file_->cinfo);
|
||||||
|
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketListModel::unsetAllFrameRefTime()
|
||||||
|
{
|
||||||
|
if (!cap_file_) return;
|
||||||
|
|
||||||
|
/* XXX: we might need a progressbar here */
|
||||||
|
|
||||||
|
foreach (PacketListRecord *record, physical_rows_) {
|
||||||
|
frame_data *fdata = record->frameData();
|
||||||
|
if (fdata->flags.ref_time) {
|
||||||
|
fdata->flags.ref_time = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cap_file_->ref_time_count = 0;
|
||||||
|
cf_reftime_packets(cap_file_);
|
||||||
|
PacketListRecord::resetColumns(&cap_file_->cinfo);
|
||||||
|
dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
void PacketListModel::setMonospaceFont(const QFont &mono_font, int row_height)
|
void PacketListModel::setMonospaceFont(const QFont &mono_font, int row_height)
|
||||||
{
|
{
|
||||||
QFontMetrics fm(mono_font_);
|
QFontMetrics fm(mono_font_);
|
||||||
|
@ -232,9 +333,9 @@ bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketListModel::emitItemHeightChanged(const QModelIndex &index)
|
void PacketListModel::emitItemHeightChanged(const QModelIndex &ih_index)
|
||||||
{
|
{
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(ih_index, ih_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PacketListModel::rowCount(const QModelIndex &parent) const
|
int PacketListModel::rowCount(const QModelIndex &parent) const
|
||||||
|
@ -250,12 +351,12 @@ int PacketListModel::columnCount(const QModelIndex &) const
|
||||||
return prefs.num_cols;
|
return prefs.num_cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PacketListModel::data(const QModelIndex &index, int role) const
|
QVariant PacketListModel::data(const QModelIndex &d_index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!d_index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
PacketListRecord *record = static_cast<PacketListRecord*>(index.internalPointer());
|
PacketListRecord *record = static_cast<PacketListRecord*>(d_index.internalPointer());
|
||||||
if (!record)
|
if (!record)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
const frame_data *fdata = record->frameData();
|
const frame_data *fdata = record->frameData();
|
||||||
|
@ -266,7 +367,7 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::FontRole:
|
case Qt::FontRole:
|
||||||
return mono_font_;
|
return mono_font_;
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
switch(recent_get_column_xalign(index.column())) {
|
switch(recent_get_column_xalign(d_index.column())) {
|
||||||
case COLUMN_XALIGN_RIGHT:
|
case COLUMN_XALIGN_RIGHT:
|
||||||
return Qt::AlignRight;
|
return Qt::AlignRight;
|
||||||
break;
|
break;
|
||||||
|
@ -278,7 +379,7 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
|
||||||
break;
|
break;
|
||||||
case COLUMN_XALIGN_DEFAULT:
|
case COLUMN_XALIGN_DEFAULT:
|
||||||
default:
|
default:
|
||||||
if (right_justify_column(index.column(), cap_file_)) {
|
if (right_justify_column(d_index.column(), cap_file_)) {
|
||||||
return Qt::AlignRight;
|
return Qt::AlignRight;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -312,14 +413,14 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
|
||||||
return QColor(color->red >> 8, color->green >> 8, color->blue >> 8);
|
return QColor(color->red >> 8, color->green >> 8, color->blue >> 8);
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
{
|
{
|
||||||
int column = index.column();
|
int column = d_index.column();
|
||||||
QVariant column_string = 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.
|
// 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
|
// Assume each line count is 1. If the line count changes, emit
|
||||||
// itemHeightChanged which triggers another redraw (including a
|
// itemHeightChanged which triggers another redraw (including a
|
||||||
// fetch of SizeHintRole and DisplayRole) in the next event loop.
|
// fetch of SizeHintRole and DisplayRole) in the next event loop.
|
||||||
if (column == 0 && record->lineCountChanged())
|
if (column == 0 && record->lineCountChanged())
|
||||||
emit itemHeightChanged(index);
|
emit itemHeightChanged(d_index);
|
||||||
return column_string;
|
return column_string;
|
||||||
}
|
}
|
||||||
case Qt::SizeHintRole:
|
case Qt::SizeHintRole:
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex & = QModelIndex()) const;
|
int columnCount(const QModelIndex & = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &d_index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const;
|
int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
@ -62,11 +62,17 @@ public:
|
||||||
int visibleIndexOf(frame_data *fdata) const;
|
int visibleIndexOf(frame_data *fdata) const;
|
||||||
void resetColumns();
|
void resetColumns();
|
||||||
void resetColorized();
|
void resetColorized();
|
||||||
|
void toggleFrameMark(const QModelIndex &fm_index);
|
||||||
|
void setDisplayedFrameMark(gboolean set);
|
||||||
|
void toggleFrameIgnore(const QModelIndex &i_index);
|
||||||
|
void setDisplayedFrameIgnore(gboolean set);
|
||||||
|
void toggleFrameRefTime(const QModelIndex &rt_index);
|
||||||
|
void unsetAllFrameRefTime();
|
||||||
void setSizeHintEnabled(bool enable) { size_hint_enabled_ = enable; }
|
void setSizeHintEnabled(bool enable) { size_hint_enabled_ = enable; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void goToPacket(int);
|
void goToPacket(int);
|
||||||
void itemHeightChanged(const QModelIndex &index) const;
|
void itemHeightChanged(const QModelIndex &ih_index) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setMonospaceFont(const QFont &mono_font, int row_height);
|
void setMonospaceFont(const QFont &mono_font, int row_height);
|
||||||
|
@ -91,7 +97,7 @@ private:
|
||||||
static bool recordLessThan(PacketListRecord *r1, PacketListRecord *r2);
|
static bool recordLessThan(PacketListRecord *r1, PacketListRecord *r2);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void emitItemHeightChanged(const QModelIndex &index);
|
void emitItemHeightChanged(const QModelIndex &ih_index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PACKET_LIST_MODEL_H
|
#endif // PACKET_LIST_MODEL_H
|
||||||
|
|
|
@ -171,6 +171,7 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
|
||||||
ws_buffer_free(&buf);
|
ws_buffer_free(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
//#define MINIMIZE_STRING_COPYING 1
|
//#define MINIMIZE_STRING_COPYING 1
|
||||||
void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue