1 /* io_graph_dialog.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef IO_GRAPH_DIALOG_H
11 #define IO_GRAPH_DIALOG_H
12 
13 #include <config.h>
14 
15 #include <glib.h>
16 
17 #include "epan/epan_dissect.h"
18 #include "epan/prefs.h"
19 #include "ui/preference_utils.h"
20 
21 #include "ui/io_graph_item.h"
22 
23 #include "wireshark_dialog.h"
24 
25 #include <ui/qt/models/uat_model.h>
26 #include <ui/qt/models/uat_delegate.h>
27 
interface_number(this: &UsbInterface) -> u828 #include <QIcon>
29 #include <QMenu>
30 #include <QTextStream>
31 
32 class QRubberBand;
33 class QTimer;
34 
35 class QCPBars;
36 class QCPGraph;
37 class QCPItemTracer;
38 class QCustomPlot;
39 class QCPAxisTicker;
alternate(this: &UsbInterface) -> UsbAlternateInterface40 class QCPAxisTickerDateTime;
41 
42 // GTK+ sets this to 100000 (NUM_IO_ITEMS)
43 const int max_io_items_ = 250000;
44 
45 // XXX - Move to its own file?
46 class IOGraph : public QObject {
47 Q_OBJECT
48 public:
49     // COUNT_TYPE_* in gtk/io_graph.c
50     enum PlotStyles { psLine, psImpulse, psBar, psStackedBar, psDot, psSquare, psDiamond, psCross, psPlus, psCircle };
alternates(this: &UsbInterface) -> ::js_sys::Array51 
52     explicit IOGraph(QCustomPlot *parent);
53     ~IOGraph();
54     const QString configError() { return config_err_; }
55     const QString name() { return name_; }
56     void setName(const QString &name);
57     const QString filter() { return filter_; }
58     void setFilter(const QString &filter);
59     void applyCurrentColor();
60     bool visible() { return visible_; }
61     void setVisible(bool visible);
claimed(this: &UsbInterface) -> bool62     QRgb color();
63     void setColor(const QRgb color);
64     void setPlotStyle(int style);
65     const QString valueUnitLabel();
66     void setValueUnits(int val_units);
67     const QString valueUnitField() { return vu_field_; }
68     void setValueUnitField(const QString &vu_field);
69     unsigned int movingAveragePeriod() { return moving_avg_period_; }
70     void setInterval(int interval);
71     bool addToLegend();
72     bool removeFromLegend();
73     QCPGraph *graph() { return graph_; }
74     QCPBars *bars() { return bars_; }
75     double startOffset();
76     int packetFromTime(double ts);
77     bool hasItemToShow(int idx, double value) const;
78     double getItemValue(int idx, const capture_file *cap_file) const;
79     int maxInterval () const { return cur_idx_; }
80     QString scaledValueUnit() const { return scaled_value_unit_; }
81 
82     void clearAllData();
83 
84     unsigned int moving_avg_period_;
85     unsigned int y_axis_factor_;
86 
87 public slots:
88     void recalcGraphData(capture_file *cap_file, bool enable_scaling);
89     void captureEvent(CaptureEvent e);
90     void reloadValueUnitField();
91 
92 signals:
93     void requestReplot();
94     void requestRecalc();
95     void requestRetap();
96 
97 private:
98     // Callbacks for register_tap_listener
99     static void tapReset(void *iog_ptr);
100     static tap_packet_status tapPacket(void *iog_ptr, packet_info *pinfo, epan_dissect_t *edt, const void *data);
101     static void tapDraw(void *iog_ptr);
102 
103     void calculateScaledValueUnit();
104     template<class DataMap> double maxValueFromGraphData(const DataMap &map);
105     template<class DataMap> void scaleGraphData(DataMap &map, int scalar);
106 
107     QCustomPlot *parent_;
108     QString config_err_;
109     QString name_;
110     bool visible_;
111     QCPGraph *graph_;
112     QCPBars *bars_;
113     QString filter_;
114     QBrush color_;
115     io_graph_item_unit_t val_units_;
116     QString vu_field_;
117     int hf_index_;
118     int interval_;
119     double start_time_;
120     QString scaled_value_unit_;
121 
122     // Cached data. We should be able to change the Y axis without retapping as
123     // much as is feasible.
124     io_graph_item_t items_[max_io_items_];
125     int cur_idx_;
126 };
127 
128 namespace Ui {
129 class IOGraphDialog;
130 }
131 
132 class IOGraphDialog : public WiresharkDialog
133 {
134     Q_OBJECT
135 
136 public:
137     explicit IOGraphDialog(QWidget &parent, CaptureFile &cf, QString displayFilter = QString());
138     ~IOGraphDialog();
139 
140     enum UatColumns { colEnabled = 0, colName, colDFilter, colColor, colStyle, colYAxis, colYField, colSMAPeriod, colYAxisFactor, colMaxNum};
141 
142     void addGraph(bool checked, QString name, QString dfilter, QRgb color_idx, IOGraph::PlotStyles style,
143                   io_graph_item_unit_t value_units, QString yfield, int moving_average, int yaxisfactor);
144     void addGraph(bool copy_from_current = false);
145     void addDefaultGraph(bool enabled, int idx = 0);
146     void syncGraphSettings(int row);
147 
148 public slots:
149     void scheduleReplot(bool now = false);
150     void scheduleRecalc(bool now = false);
151     void scheduleRetap(bool now = false);
152     void modelRowsReset();
153     void reloadFields();
154 
155 protected:
156     void keyPressEvent(QKeyEvent *event);
157     void reject();
158 
159 signals:
160     void goToPacket(int packet_num);
161     void recalcGraphData(capture_file *cap_file, bool enable_scaling);
162     void intervalChanged(int interval);
163     void reloadValueUnitFields();
164 
165 private:
166     Ui::IOGraphDialog *ui;
167 
168     //Model and delegate were chosen over UatFrame because add/remove/copy
169     //buttons would need realignment (UatFrame has its own)
170     UatModel *uat_model_;
171     UatDelegate *uat_delegate_;
172 
173     // XXX - This needs to stay synced with UAT index
174     QVector<IOGraph*> ioGraphs_;
175 
176     QString hint_err_;
177     QCPGraph *base_graph_;
178     QCPItemTracer *tracer_;
179     guint32 packet_num_;
180     double start_time_;
181     bool mouse_drags_;
182     QRubberBand *rubber_band_;
183     QPoint rb_origin_;
184     QMenu ctx_menu_;
185     QTimer *stat_timer_;
186     bool need_replot_; // Light weight: tell QCP to replot existing data
187     bool need_recalc_; // Medium weight: recalculate values, then replot
188     bool need_retap_; // Heavy weight: re-read packet data
189     bool auto_axes_;
190 
191     QSharedPointer<QCPAxisTicker> number_ticker_;
192     QSharedPointer<QCPAxisTickerDateTime> datetime_ticker_;
193 
194 
195 //    void fillGraph();
196     void zoomAxes(bool in);
197     void zoomXAxis(bool in);
198     void zoomYAxis(bool in);
199     void panAxes(int x_pixels, int y_pixels);
200     void toggleTracerStyle(bool force_default = false);
201     void getGraphInfo();
202     void updateLegend();
203     QRectF getZoomRanges(QRect zoom_rect);
204     void createIOGraph(int currentRow);
205     void loadProfileGraphs();
206     void makeCsv(QTextStream &stream) const;
207     bool saveCsv(const QString &file_name) const;
208     IOGraph *currentActiveGraph() const;
209     bool graphIsEnabled(int row) const;
210 
211 private slots:
212     void copyFromProfile(QString filename);
213     void updateWidgets();
214     void graphClicked(QMouseEvent *event);
215     void mouseMoved(QMouseEvent *event);
216     void mouseReleased(QMouseEvent *event);
217 
218     void resetAxes();
219     void updateStatistics(void);
220     void copyAsCsvClicked();
221 
222     void on_intervalComboBox_currentIndexChanged(int index);
223     void on_todCheckBox_toggled(bool checked);
224     void modelDataChanged(const QModelIndex &index);
225     void on_graphUat_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
226 
227     void on_resetButton_clicked();
228     void on_logCheckBox_toggled(bool checked);
229     void on_automaticUpdateCheckBox_toggled(bool checked);
230     void on_newToolButton_clicked();
231     void on_deleteToolButton_clicked();
232     void on_copyToolButton_clicked();
233     void on_clearToolButton_clicked();
234     void on_dragRadioButton_toggled(bool checked);
235     void on_zoomRadioButton_toggled(bool checked);
236     void on_actionReset_triggered();
237     void on_actionZoomIn_triggered();
238     void on_actionZoomInX_triggered();
239     void on_actionZoomInY_triggered();
240     void on_actionZoomOut_triggered();
241     void on_actionZoomOutX_triggered();
242     void on_actionZoomOutY_triggered();
243     void on_actionMoveUp10_triggered();
244     void on_actionMoveLeft10_triggered();
245     void on_actionMoveRight10_triggered();
246     void on_actionMoveDown10_triggered();
247     void on_actionMoveUp1_triggered();
248     void on_actionMoveLeft1_triggered();
249     void on_actionMoveRight1_triggered();
250     void on_actionMoveDown1_triggered();
251     void on_actionGoToPacket_triggered();
252     void on_actionDragZoom_triggered();
253     void on_actionToggleTimeOrigin_triggered();
254     void on_actionCrosshairs_triggered();
255     void on_buttonBox_helpRequested();
256     void on_buttonBox_accepted();
257 };
258 
259 #endif // IO_GRAPH_DIALOG_H
260