Plott.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include <QWidget>
  3. #include <QPointF>
  4. #include <QPainter>
  5. #include <QMenu>
  6. struct VisibleWindow {
  7. double xMin, xMax, yMin, yMax;
  8. VisibleWindow(double xMin, double xMax, double yMin, double yMax):
  9. xMin(xMin), xMax(xMax), yMin(yMin), yMax(yMax){}
  10. void moveUp(double percent);
  11. void moveDown(double percent);
  12. void moveLeft(double percent);
  13. void moveRight(double percent);
  14. void ZoomIn(double percent);
  15. void ZoomInX(double percent);
  16. void ZoomInY(double percent);
  17. void ZoomOut(double percent);
  18. void ZoomOutX(double percent);
  19. void ZoomOutY(double percent);
  20. double rangeX() const;
  21. double rangeY() const;
  22. bool inBoundX(QPointF point) const;
  23. bool inBoundY(QPointF point) const;
  24. bool inBound(QPointF point) const;
  25. };
  26. class Plott : public QWidget
  27. {
  28. Q_OBJECT
  29. public:
  30. //Grid
  31. bool enableGrid = false;
  32. Plott(QWidget *parent);
  33. ~Plott();
  34. //Setter
  35. void setVisibleWindow(double xMin, double xMax, double yMin, double yMax);
  36. void setDefaultVisibleWindow(double xMin, double xMax, double yMin, double yMax);
  37. void setAxisLegend(QString xAxisLegend, QString yAxisLegend);
  38. //sets the window to the default window
  39. void virtual resetToDefaultWindow();
  40. QPointF transformGraphToView(QPointF graphpoint) const;
  41. QPointF transformGraphToView(QPointF graphpoint, double stregth_factorX, double stregth_factorY, QPointF translation) const;
  42. QPointF transformViewToGraph(QPointF viewpoint) const;
  43. QPointF transformViewToGraph(QPointF viewpoint, double stregth_factorX, double stregth_factorY, QPointF translation) const;
  44. protected:
  45. //Represent the visual area in graph space that is shown in view space
  46. VisibleWindow window = VisibleWindow(0.0, 10, 0, 10);
  47. VisibleWindow defaultWindow = VisibleWindow(0.0, 10, 0, 10);
  48. virtual void drawData(QPainter& painter);
  49. //Returns the area in view space where
  50. QRect getDisplayRect() const;
  51. //Display
  52. virtual void paintEvent(QPaintEvent* event) override;
  53. //Process user input events
  54. virtual void keyPressEvent(QKeyEvent* event) override;
  55. virtual void wheelEvent(QWheelEvent* event) override;
  56. virtual void mouseMoveEvent(QMouseEvent* event) override;
  57. virtual void mousePressEvent(QMouseEvent* event) override;
  58. virtual void mouseReleaseEvent(QMouseEvent* event) override;
  59. virtual void handleSelectedWindow(VisibleWindow& window, QMouseEvent* event);
  60. void setWindow(VisibleWindow& window);
  61. private:
  62. //Axis Legends
  63. QString xAxisLegend = "X Legende", yAxisLegend = "Y Legend";
  64. //MouseControl
  65. bool isLeftMousePressed = false;
  66. bool isRightMousePressed = false;
  67. QPointF oldPositionForMouseEvent;
  68. QPointF mousePressedValue;
  69. };