summaryrefslogtreecommitdiff
path: root/QmlCustomPlot.h
diff options
context:
space:
mode:
authorNikita Kostovsky <luntik2012@gmail.com>2024-11-09 17:28:58 +0100
committerNikita Kostovsky <luntik2012@gmail.com>2024-11-09 17:28:58 +0100
commitce03d5bff5ca0c06ac884628c8ef65b902de669f (patch)
tree73876d28c78d0f5f90e4cdd0ba9bb9da9850d1c9 /QmlCustomPlot.h
Initial commit
Diffstat (limited to 'QmlCustomPlot.h')
-rw-r--r--QmlCustomPlot.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/QmlCustomPlot.h b/QmlCustomPlot.h
new file mode 100644
index 0000000..c56038c
--- /dev/null
+++ b/QmlCustomPlot.h
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <QQuickPaintedItem>
+#include <qcustomplot.h>
+
+//class QCustomPlot;
+//class QCPAbstractPlottable;
+//class QCPItemPixmap;
+//class QCPGraph;
+using Points2D = QVector<QVector2D>;
+
+class QmlCustomPlot : public QQuickPaintedItem
+{
+ Q_OBJECT
+ QML_ELEMENT
+ Q_PROPERTY(QCustomPlot* plot READ plot WRITE setPlot NOTIFY plotChanged)
+ Q_PROPERTY(int fps READ fps WRITE setFps NOTIFY fpsChanged)
+
+public:
+ QmlCustomPlot(QQuickItem* parent = nullptr);
+ ~QmlCustomPlot() Q_DECL_OVERRIDE;
+
+ void paint(QPainter* painter) Q_DECL_OVERRIDE;
+
+ Q_INVOKABLE void initCustomPlot();
+
+public:
+ QCustomPlot* plot() const;
+ int fps() const;
+
+public slots:
+ void setPlot(QCustomPlot *plot);
+ void setPoints(const QVector<QVector2D> points);
+ void setLines(const QVector<QLineF> lines);
+ void setContours(const QVector<Points2D> contours);
+ void setFps(int fps);
+
+signals:
+ void plotChanged();
+ void fpsChanged();
+
+protected:
+ void routeMouseEvents(QMouseEvent* event);
+ void routeWheelEvents(QWheelEvent* event);
+
+ void mousePressEvent(QMouseEvent* event) override;
+ void mouseReleaseEvent(QMouseEvent* event) override;
+ void mouseMoveEvent(QMouseEvent* event) override;
+ void mouseDoubleClickEvent(QMouseEvent* event) override;
+ void wheelEvent(QWheelEvent *event) override;
+
+ void timerEvent(QTimerEvent *event) override;
+
+private:
+ QCustomPlot* m_plot = nullptr;
+ int m_timerId;
+ QCPItemPixmap* m_bg = nullptr;
+ int m_fps = 0;
+ int m_fpsCounter = 0;
+
+ QCPGraph * m_profileGraph = nullptr;
+ QVector<QCPGraph *> m_contourGraphs;
+
+ QVector<QCPItemLine *> m_lineItems;
+
+private slots:
+ void graphClicked(QCPAbstractPlottable * plottable);
+ void onCustomReplot();
+ void updateCustomPlotSize();
+};
+
+//Q_DECLARE_METATYPE(QCustomPlot)