1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #pragma once
- #include <QWidget>
- #include <QPaintEvent>
- #include <QPen>
- #include <QPainter>
- #include <vector>
- class GraphView;
- struct GraphSeries {
- std::vector<QPointF>* data;
- double minX, maxX;
- double minY, maxY;
- QString name;
- QColor color;
- int lineWidth = 2;
- double circleRadius = 1.0;
- enum class SeriesType{ Line, Dot, LineDot};
- SeriesType type;
- std::pair<std::vector<QPointF>::iterator, std::vector<QPointF>::iterator> getFirstLastIndexInSeriesThatsInBound(int minX, int maxX);
- };
- struct Bound {
- double minX = 0, minY = 0, maxX = 0, maxY = 0;
- enum class Change{MoveLeft, MoveRight, MoveUp, MoveDown, ZoomOut, ZoomIn, Reset};
- Bound() {}
- Bound(double minX, double maxX, double minY, double maxY):minX(minX), maxX(maxX), minY(minY), maxY(maxY){}
- void move(GraphView* widget,const Change& type, const double changePercentage = 0.1);
- };
- class GraphView :public QWidget
- {
- Q_OBJECT
- public:
- GraphView(QWidget* parent, QString title, Bound fixedBound);
- ~GraphView();
- QString title;
- Bound fixedBound;
- private:
- bool useFixedBound;
- void paintEvent(QPaintEvent* event) override;
- //Data
- std::vector<GraphSeries> graphSeriesVec;
- Bound totalBound;
- Bound actualBound = totalBound;
- double rangeGraphX = 0, rangeGraphY = 0;
-
-
- //Visualization
- QString xAxisNumbers[11];
- QString yAxisNumbers[11];
- double hueoffset;
- QPen linePen, rectPen, axisPen;
- public:
- void setUseFixedBound(bool value);
- void generateAndAddRandomLine();
- void addLine(std::vector<QPointF>& line);
- void addLine(std::vector<QPointF>& line, QColor color);
- void addDots(std::vector<QPointF>& dots);
- void addDots(std::vector<QPointF>& dots, QColor color);
- void calculateRangeXY();
- void generateAxisNumberStrings();
- private:
- void calculateTotalGraphBound();
- void GraphView::calculateMinMaxXY(GraphSeries& lgs);
- void addSeries(std::vector<QPointF>& line, QColor color, GraphSeries::SeriesType type);
- QColor generateNextColorForGraph();
- QPointF transformPoint(QPointF& point, double stregth_factorX, double stregth_factorY) const;
- bool inBoundX(QPointF& point);
- void keyPressEvent(QKeyEvent* event) override;
- void wheelEvent(QWheelEvent* event) override;
- };
|