CustomLineGraph.h 1.5 KB

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