Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
customplot.h
1
12
13#ifndef CUSTOMPLOT_H
14#define CUSTOMPLOT_H
15#include <ui/qt/widgets/qcustomplot.h>
16#include "ui/qt/marker_dialog.h"
17
18class QCustomPlot;
19
23class CustomPlot : public QCustomPlot {
24 Q_OBJECT
25public:
30 explicit CustomPlot(QWidget* widget);
31
36
41
46 void setDataPointVisibility(const bool visible);
47
52 QString currentValue() const { return QString::number(tracer()->position->value(), 'g', 4); }
53
57 void mouseReleased();
58
64 bool mousePressed(QPoint pos);
65
70
76 void applyMarkerColors();
77
82 inline int selectedMarker() const { return selected_marker_idx_; }
83
88 void markerVisibilityChanged(const Marker* m);
89
94 void showMarkersDifference(bool show) { marker_diff_visible_ = show; }
95
100 void addMarkerElements(const Marker* marker);
101
106
111 void deleteMarkerElements(const int index);
112
117 void addDataPointsMarker(QCPGraph* graph);
118
124 QString selectedMarker(const int ignoreIdx);
125
130 QVector<Marker*> markers() const { return markers_; }
131
138 Marker* addMarker(double x, bool isPosMarker);
139
144 void deleteMarker(Marker* m);
145
149 void deleteAllMarkers();
150
155 QList<const Marker*> visibleMarkers() const;
156
162 Marker* marker(const QString& name);
163
169 Marker* marker(const int idx);
170
175 Marker* posMarker();
176
181 void markerMoved(const Marker* m);
182
183protected:
188 void mouseMoveEvent(QMouseEvent* event) override;
189
194 void axisRemoved(QCPAxis* axis) override;
195
196private:
203 void markerMoved(const int idx, const double newPos, const bool visible);
204
206 void styleMarkerTitle(QCPItemText* title) const;
207
209 void styleMarkerLine(QCPItemStraightLine* line) const;
210
212 void styleMarkerDiffLine(QCPItemLine* line) const;
213
215 void styleMarkerText(QCPItemText* label) const;
216
222 QList<const Marker*> orderedMarkers(QList<const Marker*> list) const;
223
228 void addTitleMarker(const Marker* marker);
229
234 QCPItemTracer* tracer() const { return findChild<QCPItemTracer*>(); }
235
239 void resetSelectedMarker() { selected_marker_idx_ = -1; }
240
245 void deleteMarkerDataPoint(const int marker_idx);
246
253 QCPItemText* markerTitle(const int idx, const bool create = false);
254
261 QCPItemText* markerDataPoint(const QString& idx, const bool create = false);
262
270 QCPItemStraightLine* markerLine(const int mIdx, const int rectIdx, const bool create = false);
271
279 void updateQCPItemText(QCPItemText* item, const QString& txt, const QPointF pos, QCPAxis* y_axis = Q_NULLPTR);
280
288 void updateDataPointMarker(QCPItemText* item, const double x, QCPGraph* graph, bool visible);
289
295 QString dataPointMarker(const double x) const;
296
303 inline QString itemIndex(int markerIdx, int graphIdx) const { return QString("%1_%2").arg(markerIdx).arg(graphIdx); }
304
313 void addDataPointsMarker(QCPGraph* graph, int graph_idx, const int marker_idx, const double x, bool visible);
314
321 bool canAddDataPoint(const QCPGraph* graph, const double x) const;
322
328 Marker* marker(const std::function<bool(const Marker&)>& predicate);
329
338 template <typename T>
339 typename std::enable_if<std::is_base_of<QCPAbstractItem, T>::value, T*>::type
340 getOrAddQCPItem(QCustomPlot* plot, const QString& objName, const bool create);
341
343 int selected_marker_idx_;
344
346 bool data_point_visible_;
347
349 bool marker_diff_visible_;
350
352 bool dragging_;
353
355 QVector<Marker*> markers_;
356};
357
366template <typename T>
367typename std::enable_if<std::is_base_of<QCPAbstractItem, T>::value, T*>::type
368inline CustomPlot::getOrAddQCPItem(QCustomPlot* plot, const QString& objName, const bool create)
369{
370 T* item = plot->findChild<T*>(objName);
371 if (create && item == nullptr) {
372 item = new T(plot);
373 item->setObjectName(objName);
374 }
375 return item;
376}
377#endif // CUSTOMPLOT_H
Marker * posMarker()
Retrieves the special position marker linked to the tracer.
Definition customplot.cpp:365
void clearMarkerDifferences()
Clears any displayed marker differences.
Definition customplot.cpp:62
void axisRemoved(QCPAxis *axis) override
Handles cleanup when an axis is removed from the plot.
Definition customplot.cpp:411
void mouseReleased()
Handles mouse release logic specific to the plot markers and interactions.
Definition customplot.cpp:472
void markerVisibilityChanged(const Marker *m)
Handles a visibility change for a specific marker.
Definition customplot.cpp:453
CustomPlot(QWidget *widget)
Constructs a new CustomPlot.
Definition customplot.cpp:24
QVector< Marker * > markers() const
Retrieves all markers currently in the plot.
Definition customplot.h:130
void mouseMoveEvent(QMouseEvent *event) override
Handles mouse movement events for tracking and dragging.
Definition customplot.cpp:398
void markerMoved(const Marker *m)
Updates plot visuals when a marker has been moved.
Definition customplot.cpp:380
~CustomPlot()
Destroys the CustomPlot.
Definition customplot.cpp:32
void deleteMarkersElements()
Deletes visual elements for all markers.
Definition customplot.cpp:280
bool mousePressed(QPoint pos)
Handles mouse press logic, returning whether interaction was captured.
Definition customplot.cpp:480
void applyMarkerColors()
Recolors existing marker items from the current theme.
Definition customplot.cpp:97
int selectedMarker() const
Retrieves the index of the currently selected marker.
Definition customplot.h:82
QString currentValue() const
Retrieves the current value traced by the plot.
Definition customplot.h:52
void deleteMarkerElements(const int index)
Deletes visual elements for a specific marker.
Definition customplot.cpp:264
Marker * marker(const QString &name)
Retrieves a marker by its name/identifier.
Definition customplot.cpp:355
void addDataPointsMarker(QCPGraph *graph)
Adds data point markers along a specific graph.
Definition customplot.cpp:309
void showMarkersDifference(bool show)
Toggles the visibility of the difference between markers.
Definition customplot.h:94
void deleteMarker(Marker *m)
Deletes a specific marker.
Definition customplot.cpp:325
QList< const Marker * > visibleMarkers() const
Retrieves a list of all currently visible markers.
Definition customplot.cpp:387
void deleteAllMarkers()
Deletes all markers from the plot.
Definition customplot.cpp:337
void showMarkerDifferences()
Shows the calculated differences between visible markers.
Definition customplot.cpp:123
Marker * addMarker(double x, bool isPosMarker)
Adds a new marker at the specified X coordinate.
Definition customplot.cpp:343
void addMarkerElements(const Marker *marker)
Adds plot elements (lines, labels) associated with a marker.
Definition customplot.cpp:224
void setDataPointVisibility(const bool visible)
Sets the visibility of data points on the plot.
Definition customplot.cpp:37
A widget representing a marker on a graph or timeline.
Definition marker_dialog.h:21