1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* @file
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "io_graph_action.h"
#include <ui/qt/main_application.h>
#include <ui/qt/main_window.h>
#include <ui/qt/io_graph_dialog.h>
#include <ui/qt/utils/field_information.h>
#include <ui/io_graph_item.h>
#include <wsutil/filesystem.h>
#include <QMenu>
IOGraphAction::IOGraphAction(QObject *parent, io_graph_item_unit_t unit, QString field) :
QAction(parent),
unit_(unit),
field_(field)
{
setText(unitName(unit));
connect(this, &QAction::triggered, [&](){ emit openIOGraphDialog(unit_, field_); });
}
const QString IOGraphAction::unitName(io_graph_item_unit_t unit) {
switch (unit) {
case IOG_ITEM_UNIT_PACKETS:
if (is_packet_configuration_namespace()) {
return QObject::tr("PACKETS");
}
return QObject::tr("EVENTS");
case IOG_ITEM_UNIT_BYTES:
return QObject::tr("BYTES");
case IOG_ITEM_UNIT_BITS:
return QObject::tr("BITS");
case IOG_ITEM_UNIT_CALC_FRAMES:
return QObject::tr("COUNT FRAMES");
case IOG_ITEM_UNIT_CALC_FIELDS:
return QObject::tr("COUNT FIELDS");
case IOG_ITEM_UNIT_CALC_SUM:
return QObject::tr("SUM");
case IOG_ITEM_UNIT_CALC_MAX:
return QObject::tr("MAX");
case IOG_ITEM_UNIT_CALC_MIN:
return QObject::tr("MIN");
case IOG_ITEM_UNIT_CALC_AVERAGE:
return QObject::tr("AVERAGE");
case IOG_ITEM_UNIT_CALC_THROUGHPUT:
return QObject::tr("THROUGHPUT");
case IOG_ITEM_UNIT_CALC_LOAD:
return QObject::tr("LOAD");
default:
return QObject::tr("UNKNOWN");
}
}
QList<io_graph_item_unit_t> IOGraphAction::unitTypes(const FieldInformation::HeaderInfo& headerinfo)
{
static const QList<io_graph_item_unit_t> simple_types_ = QList<io_graph_item_unit_t>()
<< IOG_ITEM_UNIT_CALC_FRAMES
<< IOG_ITEM_UNIT_CALC_FIELDS;
static const QList<io_graph_item_unit_t> number_types_ = QList<io_graph_item_unit_t>()
<< IOG_ITEM_UNIT_CALC_SUM
<< IOG_ITEM_UNIT_CALC_FRAMES
<< IOG_ITEM_UNIT_CALC_FIELDS
<< IOG_ITEM_UNIT_CALC_MAX
<< IOG_ITEM_UNIT_CALC_MIN
<< IOG_ITEM_UNIT_CALC_THROUGHPUT
<< IOG_ITEM_UNIT_CALC_AVERAGE;
static const QList<io_graph_item_unit_t> time_types_ = QList<io_graph_item_unit_t>(number_types_)
<< IOG_ITEM_UNIT_CALC_LOAD;
switch (headerinfo.type) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
case FT_UINT64:
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
case FT_INT64:
case FT_FLOAT:
case FT_DOUBLE:
return number_types_;
case FT_RELATIVE_TIME:
return time_types_;
default:
return simple_types_;
}
}
QMenu * IOGraphAction::createMenu(const FieldInformation::HeaderInfo& headerinfo, QWidget * parent)
{
MainWindow *mw(nullptr);
if (mainApp)
{
QWidget * mainWin = mainApp->mainWindow();
if (qobject_cast<MainWindow *>(mainWin)) {
mw = qobject_cast<MainWindow *>(mainWin);
}
}
QString title("I/O Graph");
QMenu * submenu = new QMenu(title, parent);
int one_em = submenu->fontMetrics().height();
QString prep_text = QString("%1: %2").arg(title).arg(headerinfo.abbreviation);
prep_text = submenu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40);
QAction * comment = submenu->addAction(prep_text);
comment->setEnabled(false);
submenu->addSeparator();
IOGraphAction *graphAction;
for (const auto &unit : IOGraphAction::unitTypes(headerinfo)) {
graphAction = new IOGraphAction(submenu, unit, headerinfo.abbreviation);
if (mw) {
connect(graphAction, &IOGraphAction::openIOGraphDialog, mw, &MainWindow::showIOGraphDialog);
}
submenu->addAction(graphAction);
}
return submenu;
}
|