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