Qt: Reduce PacketListHeader complexity

Propagating the capture_file was required for a single
function as was the cast for the model. Both are not
needed, as the functionality can be either moved to
PacketListModel or was already included in PacketList
This commit is contained in:
Roland Knall 2022-06-29 14:45:48 +02:00 committed by Roland Knall
parent 5fb2324692
commit 413b383224
5 changed files with 12 additions and 19 deletions

View File

@ -650,6 +650,8 @@ QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
return QVariant::fromValue(QString(get_column_title(section)));
case Qt::ToolTipRole:
return QVariant::fromValue(gchar_free_to_qstring(get_column_tooltip(section)));
case PacketListModel::HEADER_CAN_RESOLVE:
return (bool)resolve_column(section, cap_file_);
default:
break;
}

View File

@ -32,6 +32,11 @@ class PacketListModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum {
HEADER_CAN_RESOLVE = Qt::UserRole,
};
explicit PacketListModel(QObject *parent = 0, capture_file *cf = NULL);
~PacketListModel();
void setCaptureFile(capture_file *cf);

View File

@ -216,7 +216,7 @@ PacketList::PacketList(QWidget *parent) :
proto_prefs_menus_.setTitle(tr("Protocol Preferences"));
packet_list_header_ = new PacketListHeader(header()->orientation(), cap_file_);
packet_list_header_ = new PacketListHeader(header()->orientation());
connect(packet_list_header_, &PacketListHeader::resetColumnWidth, this, &PacketList::setRecentColumnWidth);
connect(packet_list_header_, &PacketListHeader::updatePackets, this, &PacketList::updatePackets);
connect(packet_list_header_, &PacketListHeader::showColumnPreferences, this, &PacketList::showProtocolPreferences);
@ -1526,7 +1526,6 @@ void PacketList::setCaptureFile(capture_file *cf)
{
cap_file_ = cf;
packet_list_model_->setCaptureFile(cf);
packet_list_header_->setCaptureFile(cf);
if (cf) {
if (columns_changed_) {
columnsChanged();
@ -1742,6 +1741,7 @@ void PacketList::applyTimeShift()
void PacketList::updatePackets(bool redraw)
{
if (redraw) {
packet_list_model_->resetColumns();
redrawVisiblePackets();
} else {
update();

View File

@ -29,9 +29,8 @@
#include <ui/qt/utils/wireshark_mime_data.h>
#include <ui/qt/widgets/packet_list_header.h>
PacketListHeader::PacketListHeader(Qt::Orientation orientation, capture_file * cap_file, QWidget *parent) :
PacketListHeader::PacketListHeader(Qt::Orientation orientation, QWidget *parent) :
QHeaderView(orientation, parent),
cap_file_(cap_file),
sectionIdx(-1),
lastSize(-1)
{
@ -174,11 +173,6 @@ void PacketListHeader::mouseMoveEvent(QMouseEvent *e)
QHeaderView::mouseMoveEvent(e);
}
void PacketListHeader::setCaptureFile(capture_file *cap_file)
{
this->cap_file_ = cap_file;
}
void PacketListHeader::contextMenuEvent(QContextMenuEvent *event)
{
int sectionIdx = logicalIndexAt(event->pos());
@ -217,7 +211,7 @@ void PacketListHeader::contextMenuEvent(QContextMenuEvent *event)
connect(action, &QAction::triggered, this, &PacketListHeader::resizeToWidth);
action = contextMenu->addAction(tr("Resolve Names"));
bool canResolve = resolve_column(sectionIdx, cap_file_);
bool canResolve = model()->headerData(sectionIdx, Qt::Horizontal, PacketListModel::HEADER_CAN_RESOLVE).toBool();
action->setEnabled(canResolve);
action->setCheckable(true);
action->setChecked(canResolve && get_column_resolved(sectionIdx));
@ -323,14 +317,9 @@ void PacketListHeader::doResolveNames()
if (!menu)
return;
PacketListModel * plmModel = qobject_cast<PacketListModel *>(model());
if (!plmModel)
return;
int section = menu->property("column").toInt();
set_column_resolved(section, action->isChecked());
plmModel->resetColumns();
prefs_main_write();
emit updatePackets(true);
}

View File

@ -23,9 +23,7 @@ class PacketListHeader : public QHeaderView
Q_OBJECT
public:
PacketListHeader(Qt::Orientation orientation, capture_file * cap_file, QWidget *parent = nullptr);
void setCaptureFile(capture_file * cap_file);
PacketListHeader(Qt::Orientation orientation, QWidget *parent = nullptr);
protected:
virtual void dropEvent(QDropEvent *event) override;
@ -59,7 +57,6 @@ signals:
private:
capture_file * cap_file_;
int sectionIdx;
int lastSize;