summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-07-16 12:07:49 -0700
committerGerald Combs <gerald@wireshark.org>2015-07-16 19:13:14 +0000
commit41ed7127a566a2758c8a5a0716ea0276f4182ed0 (patch)
treea52751f7cae2405df1e2b7486afddc66faeff578 /ui
parentb1e0f439e1231b4bb3feff5d6449a6ca56c016da (diff)
downloadwireshark-41ed7127a566a2758c8a5a0716ea0276f4182ed0.tar.gz
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>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/packet_list.cpp122
-rw-r--r--ui/qt/packet_list.h3
-rw-r--r--ui/qt/packet_list_model.cpp125
-rw-r--r--ui/qt/packet_list_model.h12
-rw-r--r--ui/qt/packet_list_record.cpp1
5 files changed, 137 insertions, 126 deletions
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp
index 14452438c7..4f295971d0 100644
--- a/ui/qt/packet_list.cpp
+++ b/ui/qt/packet_list.cpp
@@ -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()
{
for (int i = 0; i < prefs.num_cols; i++) {
@@ -1040,105 +1001,50 @@ void PacketList::goToPacket(int packet, int hf_id)
void PacketList::markFrame()
{
- int row = currentIndex().row();
- frame_data *fdata;
-
if (!cap_file_ || !packet_list_model_) return;
- fdata = packet_list_model_->getRowFdata(row);
-
- if (!fdata) return;
-
- setFrameMark(!fdata->flags.marked, fdata);
- markFramesReady();
+ packet_list_model_->toggleFrameMark(currentIndex());
+ packets_bar_update();
}
void PacketList::markAllDisplayedFrames(bool set)
{
- guint32 framenum;
- frame_data *fdata;
-
if (!cap_file_ || !packet_list_model_) return;
- for (framenum = 1; framenum <= cap_file_->count; framenum++) {
- fdata = frame_data_sequence_find(cap_file_->frames, framenum);
- if (fdata->flags.passed_dfilter)
- setFrameMark(set, fdata);
- }
- markFramesReady();
+ packet_list_model_->setDisplayedFrameMark(set);
+ packets_bar_update();
}
void PacketList::ignoreFrame()
{
- int row = currentIndex().row();
- frame_data *fdata;
-
if (!cap_file_ || !packet_list_model_) return;
- fdata = packet_list_model_->getRowFdata(row);
- if (!fdata) return;
-
- setFrameIgnore(!fdata->flags.ignored, fdata);
+ packet_list_model_->toggleFrameIgnore(currentIndex());
+ int sb_val = verticalScrollBar()->value(); // Surely there's a better way to keep our position?
+ setUpdatesEnabled(false);
emit packetDissectionChanged();
+ setUpdatesEnabled(true);
+ verticalScrollBar()->setValue(sb_val);
}
void PacketList::ignoreAllDisplayedFrames(bool set)
{
- guint32 framenum;
- frame_data *fdata;
-
if (!cap_file_ || !packet_list_model_) return;
- for (framenum = 1; framenum <= cap_file_->count; framenum++) {
- fdata = frame_data_sequence_find(cap_file_->frames, framenum);
- if (!set || fdata->flags.passed_dfilter)
- setFrameIgnore(set, fdata);
- }
+ packet_list_model_->setDisplayedFrameIgnore(set);
emit packetDissectionChanged();
}
void PacketList::setTimeReference()
{
- if (!cap_file_) return;
-
- 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();
+ if (!cap_file_ || !packet_list_model_) return;
+ packet_list_model_->toggleFrameRefTime(currentIndex());
}
void PacketList::unsetAllTimeReferences()
{
- if (!cap_file_) return;
-
- /* 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();
+ if (!cap_file_ || !packet_list_model_) return;
+ packet_list_model_->unsetAllFrameRefTime();
}
void PacketList::showHeaderMenu(QPoint pos)
diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h
index 715a4ebb04..d1059aabc1 100644
--- a/ui/qt/packet_list.h
+++ b/ui/qt/packet_list.h
@@ -102,9 +102,6 @@ private:
bool tail_at_end_;
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 setColumnVisibility();
int sizeHintForColumn(int column) const;
diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp
index 8a3e443d52..3de636d947 100644
--- a/ui/qt/packet_list_model.cpp
+++ b/ui/qt/packet_list_model.cpp
@@ -21,6 +21,8 @@
#include "packet_list_model.h"
+#include "file.h"
+
#include <wsutil/nstime.h>
#include <epan/column.h>
#include <epan/prefs.h>
@@ -119,14 +121,113 @@ void PacketListModel::resetColumns()
void PacketListModel::resetColorized()
{
- PacketListRecord *record;
-
- foreach (record, physical_rows_) {
+ foreach (PacketListRecord *record, physical_rows_) {
record->resetColorized();
}
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)
{
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
@@ -250,12 +351,12 @@ int PacketListModel::columnCount(const QModelIndex &) const
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();
- PacketListRecord *record = static_cast<PacketListRecord*>(index.internalPointer());
+ PacketListRecord *record = static_cast<PacketListRecord*>(d_index.internalPointer());
if (!record)
return QVariant();
const frame_data *fdata = record->frameData();
@@ -266,7 +367,7 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
case Qt::FontRole:
return mono_font_;
case Qt::TextAlignmentRole:
- switch(recent_get_column_xalign(index.column())) {
+ switch(recent_get_column_xalign(d_index.column())) {
case COLUMN_XALIGN_RIGHT:
return Qt::AlignRight;
break;
@@ -278,7 +379,7 @@ QVariant PacketListModel::data(const QModelIndex &index, int role) const
break;
case COLUMN_XALIGN_DEFAULT:
default:
- if (right_justify_column(index.column(), cap_file_)) {
+ if (right_justify_column(d_index.column(), cap_file_)) {
return Qt::AlignRight;
}
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);
case Qt::DisplayRole:
{
- int column = index.column();
+ int column = d_index.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);
+ emit itemHeightChanged(d_index);
return column_string;
}
case Qt::SizeHintRole:
diff --git a/ui/qt/packet_list_model.h b/ui/qt/packet_list_model.h
index d0644c55b9..0c7772fef5 100644
--- a/ui/qt/packet_list_model.h
+++ b/ui/qt/packet_list_model.h
@@ -53,7 +53,7 @@ public:
int rowCount(const QModelIndex &parent = 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,
int role = Qt::DisplayRole) const;
@@ -62,11 +62,17 @@ public:
int visibleIndexOf(frame_data *fdata) const;
void resetColumns();
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; }
signals:
void goToPacket(int);
- void itemHeightChanged(const QModelIndex &index) const;
+ void itemHeightChanged(const QModelIndex &ih_index) const;
public slots:
void setMonospaceFont(const QFont &mono_font, int row_height);
@@ -91,7 +97,7 @@ private:
static bool recordLessThan(PacketListRecord *r1, PacketListRecord *r2);
private slots:
- void emitItemHeightChanged(const QModelIndex &index);
+ void emitItemHeightChanged(const QModelIndex &ih_index);
};
#endif // PACKET_LIST_MODEL_H
diff --git a/ui/qt/packet_list_record.cpp b/ui/qt/packet_list_record.cpp
index 9211f9b371..f09b508700 100644
--- a/ui/qt/packet_list_record.cpp
+++ b/ui/qt/packet_list_record.cpp
@@ -171,6 +171,7 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
ws_buffer_free(&buf);
}
+#include <QDebug>
//#define MINIMIZE_STRING_COPYING 1
void PacketListRecord::cacheColumnStrings(column_info *cinfo)
{