#pragma once #include #include //class QCustomPlot; //class QCPAbstractPlottable; //class QCPItemPixmap; //class QCPGraph; using Points2D = QVector; 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 points); void setLines(const QVector lines); void setContours(const QVector 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 m_contourGraphs; QVector m_lineItems; private slots: void graphClicked(QCPAbstractPlottable * plottable); void onCustomReplot(); void updateCustomPlotSize(); }; //Q_DECLARE_METATYPE(QCustomPlot)