GraphView.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <QWidget>
  3. #include <QPaintEvent>
  4. #include <QPen>
  5. #include <QPainter>
  6. #include <vector>
  7. struct GraphSeries {
  8. std::vector<QPointF>* data;
  9. double minX, maxX;
  10. double minY, maxY;
  11. QString name;
  12. QColor color;
  13. int lineWidth = 2;
  14. double circleRadius = 1.0;
  15. enum class SeriesType{ Line, Dot, LineDot};
  16. SeriesType type;
  17. };
  18. class GraphView :public QWidget
  19. {
  20. Q_OBJECT
  21. public:
  22. GraphView(QWidget* parent, QString title);
  23. ~GraphView();
  24. QString title;
  25. private:
  26. void GraphView::paintEvent(QPaintEvent* event);
  27. //Data
  28. std::vector<GraphSeries> graphSeriesVec;
  29. double minGraphX = 0, maxGraphX = 0, minGraphY = 0, maxGraphY = 0, rangeGraphX = 0, rangeGraphY = 0;
  30. //Visualization
  31. QString xAxisNumbers[11];
  32. QString yAxisNumbers[11];
  33. double hueoffset;
  34. QPen linePen, rectPen, axisPen;
  35. public:
  36. void generateAndAddRandomLine();
  37. void addLine(std::vector<QPointF>& line);
  38. void addLine(std::vector<QPointF>& line, QColor color);
  39. void addDots(std::vector<QPointF>& dots);
  40. void addDots(std::vector<QPointF>& dots, QColor color);
  41. private:
  42. void generateAxisNumberStrings();
  43. void calculateMinMaxGraphXY();
  44. void GraphView::calculateMinMaxXY(std::vector<QPointF>& line, GraphSeries& lgs);
  45. void addSeries(std::vector<QPointF>& line, QColor color, GraphSeries::SeriesType type);
  46. QColor generateNextColorForGraph();
  47. QPointF transformPoint(QPointF& point, double stregth_factorX, double stregth_factorY);
  48. };