CustomplotTracer.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef CUSTOMPLOTTRACER_H
  2. #define CUSTOMPLOTTRACER_H
  3. #include "CustomplotHead.h"
  4. //自定义图层绘制十字线,也叫游标,定位线
  5. class CustomPlotTracer : public QCPLayerable
  6. {
  7. Q_OBJECT
  8. public:
  9. explicit CustomPlotTracer(QCustomPlot *parentPlot);
  10. protected:
  11. void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  12. void draw(QCPPainter *painter);
  13. private:
  14. bool showLineh; //显示横线
  15. bool showLinev; //显示竖线
  16. int lineWidth; //十字线宽度
  17. QColor lineColor; //十字线颜色
  18. double x, y; //当前鼠标坐标
  19. double dX, dY; //曲线区域坐标
  20. double dWidth, dHeight; //曲线区域宽高
  21. QPoint movePos; //按下鼠标坐标
  22. QCustomPlot *customPlot; //图表对象
  23. public:
  24. bool getShowLineh() const;
  25. bool getShowLinev() const;
  26. int getLineWidth() const;
  27. QColor getLineColor() const;
  28. private slots:
  29. void mouseMove(QMouseEvent *event);
  30. public Q_SLOTS:
  31. //设置是否显示横线竖线+十字线宽度+颜色
  32. void setShowLineh(bool showLineh);
  33. void setShowLinev(bool showLinev);
  34. void setLineWidth(int lineWidth);
  35. void setLineColor(const QColor &lineColor);
  36. //绘制十字线
  37. void drawLine();
  38. };
  39. #endif // CUSTOMPLOTTRACER_H