Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
customplot.h
1
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
75 inline int selectedMarker() const { return selected_marker_idx_; }
76
81 void markerVisibilityChanged(const Marker* m);
82
87 void showMarkersDifference(bool show) { marker_diff_visible_ = show; }
88
93 void addMarkerElements(const Marker* marker);
94
99
104 void deleteMarkerElements(const int index);
105
110 void addDataPointsMarker(QCPGraph* graph);
111
117 QString selectedMarker(const int ignoreIdx);
118
123 QVector<Marker*> markers() const { return markers_; }
124
131 Marker* addMarker(double x, bool isPosMarker);
132
137 void deleteMarker(Marker* m);
138
142 void deleteAllMarkers();
143
148 QList<const Marker*> visibleMarkers() const;
149
155 Marker* marker(const QString& name);
156
162 Marker* marker(const int idx);
163
168 Marker* posMarker();
169
174 void markerMoved(const Marker* m);
175
176protected:
181 void mouseMoveEvent(QMouseEvent* event) override;
182
187 void axisRemoved(QCPAxis* axis) override;
188
189private:
196 void markerMoved(const int idx, const double newPos, const bool visible);
197
203 QList<const Marker*> orderedMarkers(QList<const Marker*> list) const;
204
209 void addTitleMarker(const Marker* marker);
210
215 QCPItemTracer* tracer() const { return findChild<QCPItemTracer*>(); }
216
220 void resetSelectedMarker() { selected_marker_idx_ = -1; }
221
226 void deleteMarkerDataPoint(const int marker_idx);
227
234 QCPItemText* markerTitle(const int idx, const bool create = false);
235
242 QCPItemText* markerDataPoint(const QString& idx, const bool create = false);
243
251 QCPItemStraightLine* markerLine(const int mIdx, const int rectIdx, const bool create = false);
252
260 void updateQCPItemText(QCPItemText* item, const QString& txt, const QPointF pos, QCPAxis* y_axis = Q_NULLPTR);
261
269 void updateDataPointMarker(QCPItemText* item, const double x, QCPGraph* graph, bool visible);
270
276 QString dataPointMarker(const double x) const;
277
284 inline QString itemIndex(int markerIdx, int graphIdx) const { return QString("%1_%2").arg(markerIdx).arg(graphIdx); }
285
294 void addDataPointsMarker(QCPGraph* graph, int graph_idx, const int marker_idx, const double x, bool visible);
295
302 bool canAddDataPoint(const QCPGraph* graph, const double x) const;
303
309 Marker* marker(const std::function<bool(const Marker&)>& predicate);
310
319 template <typename T>
320 typename std::enable_if<std::is_base_of<QCPAbstractItem, T>::value, T*>::type
321 getOrAddQCPItem(QCustomPlot* plot, const QString& objName, const bool create);
322
324 int selected_marker_idx_;
325
327 bool data_point_visible_;
328
330 bool marker_diff_visible_;
331
333 bool dragging_;
334
336 QVector<Marker*> markers_;
337};
338
347template <typename T>
348typename std::enable_if<std::is_base_of<QCPAbstractItem, T>::value, T*>::type
349inline CustomPlot::getOrAddQCPItem(QCustomPlot* plot, const QString& objName, const bool create)
350{
351 T* item = plot->findChild<T*>(objName);
352 if (create && item == nullptr) {
353 item = new T(plot);
354 item->setObjectName(objName);
355 }
356 return item;
357}
358#endif // CUSTOMPLOT_H
An extended QCustomPlot widget supporting markers, data points, and their interactions.
Definition customplot.h:23
Marker * posMarker()
Retrieves the special position marker linked to the tracer.
Definition customplot.cpp:316
void clearMarkerDifferences()
Clears any displayed marker differences.
Definition customplot.cpp:60
void axisRemoved(QCPAxis *axis) override
Handles cleanup when an axis is removed from the plot.
Definition customplot.cpp:362
void mouseReleased()
Handles mouse release logic specific to the plot markers and interactions.
Definition customplot.cpp:423
void markerVisibilityChanged(const Marker *m)
Handles a visibility change for a specific marker.
Definition customplot.cpp:404
QVector< Marker * > markers() const
Retrieves all markers currently in the plot.
Definition customplot.h:123
void mouseMoveEvent(QMouseEvent *event) override
Handles mouse movement events for tracking and dragging.
Definition customplot.cpp:349
void markerMoved(const Marker *m)
Updates plot visuals when a marker has been moved.
Definition customplot.cpp:331
~CustomPlot()
Destroys the CustomPlot.
Definition customplot.cpp:30
void deleteMarkersElements()
Deletes visual elements for all markers.
Definition customplot.cpp:231
bool mousePressed(QPoint pos)
Handles mouse press logic, returning whether interaction was captured.
Definition customplot.cpp:431
int selectedMarker() const
Retrieves the index of the currently selected marker.
Definition customplot.h:75
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:215
Marker * marker(const QString &name)
Retrieves a marker by its name/identifier.
Definition customplot.cpp:306
void addDataPointsMarker(QCPGraph *graph)
Adds data point markers along a specific graph.
Definition customplot.cpp:260
void showMarkersDifference(bool show)
Toggles the visibility of the difference between markers.
Definition customplot.h:87
void deleteMarker(Marker *m)
Deletes a specific marker.
Definition customplot.cpp:276
QList< const Marker * > visibleMarkers() const
Retrieves a list of all currently visible markers.
Definition customplot.cpp:338
void deleteAllMarkers()
Deletes all markers from the plot.
Definition customplot.cpp:288
void showMarkerDifferences()
Shows the calculated differences between visible markers.
Definition customplot.cpp:70
Marker * addMarker(double x, bool isPosMarker)
Adds a new marker at the specified X coordinate.
Definition customplot.cpp:294
void addMarkerElements(const Marker *marker)
Adds plot elements (lines, labels) associated with a marker.
Definition customplot.cpp:172
void setDataPointVisibility(const bool visible)
Sets the visibility of data points on the plot.
Definition customplot.cpp:35
A widget representing a marker on a graph or timeline.
Definition marker_dialog.h:21