GraphView.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. #include <QWidget>
  3. #include <QPaintEvent>
  4. #include <QAbstractListModel>
  5. #include <QPen>
  6. #include <QPainter>
  7. #include <vector>
  8. #include "RunData.h"
  9. #include "ColorGradient.h"
  10. class GraphView;
  11. class RunData;
  12. struct SolutionPointData;
  13. struct GraphSeries {
  14. std::vector<GraphDataPoint>* data;
  15. double minX, maxX;
  16. double minY, maxY;
  17. RunData* run;
  18. //Settings for visual
  19. QString name;
  20. QColor color;
  21. int lineWidth = 2;
  22. double circleRadius = 2.0;
  23. enum class SeriesType{ Line, Dot, LineDot};
  24. bool useDataPointColor = false;
  25. SeriesType type;
  26. bool hide = false;
  27. };
  28. struct Bound {
  29. double minX = 0, minY = 0, maxX = 0, maxY = 0;
  30. enum class Change{MoveLeft, MoveRight, MoveUp, MoveDown, ZoomOut, ZoomIn, ZoomInX, ZoomInY, ZoomOutX, ZoomOutY, Reset};
  31. Bound() {}
  32. Bound(double minX, double maxX, double minY, double maxY):minX(minX), maxX(maxX), minY(minY), maxY(maxY){}
  33. void move(GraphView* widget,const Change& type, const double changePercentage = 0.1);
  34. void move(GraphView* widget, QPointF& delta, double realPixelWidthX, double realPixelWidthY);
  35. void move(GraphView* widget, QPointF& targetPoint);
  36. };
  37. class GraphView :public QWidget
  38. {
  39. Q_OBJECT
  40. public:
  41. GraphView(QWidget* parent, Bound fixedBound = Bound());
  42. ~GraphView();
  43. QString title;
  44. Bound fixedBound;
  45. //TODO: make fancy
  46. bool useInterval = false;
  47. int maxIter = 0;
  48. int minIter = 0;
  49. std::vector<GraphSeries> graphSeriesVec;
  50. private:
  51. bool useFixedBound;
  52. //Data
  53. Bound totalBound;
  54. Bound actualBound = totalBound;
  55. bool drawTotalBound = false;
  56. double rangeGraphX = 0, rangeGraphY = 0;
  57. double* yArray = nullptr;
  58. QColor* pointColors = nullptr;
  59. std::vector<SolutionPointData>* solVec = nullptr;
  60. int yDoubleDoubleValuesAmount = 0;
  61. //Visualization
  62. QString xAxisNumbers[11];
  63. QString yAxisNumbers[11];
  64. double hueoffset;
  65. QPen linePen, rectPen, axisPen;
  66. GraphSeries* highlightSeries = nullptr;
  67. //Control
  68. QPointF oldPositionForMouseEvent;
  69. QPointF mousePressedValue;
  70. bool mousePressed = false;
  71. public:
  72. void setUseFixedBound(bool value);
  73. void generateAndAddRandomLine();
  74. void addLine(std::vector<GraphDataPoint>* line, RunData* run);
  75. void addLine(std::vector<GraphDataPoint>* line, RunData* run, QColor color);
  76. void addDots(std::vector<GraphDataPoint>* dots, RunData* run);
  77. void addDots(std::vector<GraphDataPoint>* dots, RunData* run, QColor color);
  78. void removeAllSeriesWithRundata(RunData* run);
  79. void removeAllSeries();
  80. void reset();
  81. void calculateRangeXY();
  82. void generateAxisNumberStrings();
  83. void update();
  84. void setDrawBound(bool value);
  85. QColor generateNextColorForGraph();
  86. void resetBound();
  87. void addYMatrix(double* yArray, std::vector<SolutionPointData>& solVec);
  88. void autoZoomOut();
  89. void updateGraphColors(ColorGradient& gradient);
  90. private:
  91. void calculateTotalMatrixBound();
  92. void calculateTotalGraphBound();
  93. void GraphView::calculateMinMaxXY(GraphSeries& lgs);
  94. void addSeries(std::vector<GraphDataPoint>* line, RunData* run, QColor color, GraphSeries::SeriesType type);
  95. QPointF transformGraphToView(QPointF& graphpoint, double stregth_factorX, double stregth_factorY, QPointF& translation) const;
  96. QPointF transformViewToGraph(QPointF& viewpoint) const;
  97. GraphDataPoint findNearestGraphDataPointFromGraphCoordinate(QPointF& graphpoint);
  98. GraphDataPoint findNearestGraphDataPointFromViewCordinate(QPointF& viewpoint);
  99. bool inBoundX(QPointF& point);
  100. bool inBoundY(QPointF& point);
  101. bool inBound(QPointF& point);
  102. //overrides
  103. void keyPressEvent(QKeyEvent* event) override;
  104. void wheelEvent(QWheelEvent* event) override;
  105. void mouseMoveEvent(QMouseEvent* event) override;
  106. void mousePressEvent(QMouseEvent* event) override;
  107. void mouseReleaseEvent(QMouseEvent* event) override;
  108. void paintEvent(QPaintEvent* event) override;
  109. public slots:
  110. void setMaxIter(int value);
  111. void setMinIter(int value);
  112. };