OGS
DiagramScene.h
Go to the documentation of this file.
1
15#pragma once
16
17#include "DiagramList.h"
18#include "QArrow.h"
19#include "QGraphicsGrid.h"
21#include <QGraphicsScene>
22
23class QDateTime;
24
28class DiagramScene : public QGraphicsScene
29{
30public:
31 explicit DiagramScene(QObject* parent = nullptr);
32 explicit DiagramScene(DiagramList* list, QObject* parent = nullptr);
33 ~DiagramScene() override;
34
35 QArrow* addArrow(qreal length, qreal angle, QPen& pen);
36 void addGraph(DiagramList* list);
37 QGraphicsGrid* addGrid(const QRectF &rect, int xTicks, int yTicks, const QPen &pen);
38
39 static const int MARGIN = 30;
40
41private:
42 void addCaption(const QString &name, QPen &pen);
44 const QFont &font = QFont());
45 void adjustAxis(qreal& min, qreal& max, int& numberOfTicks);
46 void adjustScaling();
47 void clearGrid();
48 void constructGrid();
49 void drawGraph(DiagramList* list);
50 int getXAxisOffset();
51 int getYAxisOffset();
52 void initialize();
54
56 void setXAxis(QArrow* arrow) { _xAxis = arrow; }
57
59 void setYAxis(QArrow* arrow) { _yAxis = arrow; }
60
61 void update();
62
63 QRectF _bounds;
65 QVector<DiagramList*> _lists;
66 QVector<QGraphicsItemGroup*> _graphCaptions;
67 QVector<QGraphicsPathItem*> _graphs;
69 QDateTime _startDate;
70 float _scaleX;
71 float _scaleY;
78 QVector<QNonScalableGraphicsTextItem*> _xTicksText;
79 QVector<QNonScalableGraphicsTextItem*> _yTicksText;
80};
Definition of the DiagramList class.
Definition of the QArrow class.
Definition of the QGraphicsGrid class.
Definition of the QNonScalableGraphicsTextItem class.
A List of data points and all the necessary meta-information to draw a graph.
Definition DiagramList.h:29
A scene graph for a 2D Diagram including coordinate axes with labels and ticks for one or more plotte...
DiagramScene(QObject *parent=nullptr)
QDateTime _startDate
void drawGraph(DiagramList *list)
Plots the graph.
QVector< QNonScalableGraphicsTextItem * > _xTicksText
~DiagramScene() override
void adjustAxis(qreal &min, qreal &max, int &numberOfTicks)
QNonScalableGraphicsTextItem * _xUnit
QArrow * _xAxis
QVector< QGraphicsPathItem * > _graphs
QVector< QGraphicsItemGroup * > _graphCaptions
QVector< QNonScalableGraphicsTextItem * > _yTicksText
void addGraph(DiagramList *list)
Adds a graph to the scene, including all data points and meta-information.
QArrow * addArrow(qreal length, qreal angle, QPen &pen)
void addCaption(const QString &name, QPen &pen)
The margin between the boundary of the scene and the bounding box of all items within the scene.
QNonScalableGraphicsTextItem * _yUnit
QGraphicsGrid * addGrid(const QRectF &rect, int xTicks, int yTicks, const QPen &pen)
Adds a grid-object to the scene.
void setDiagramBoundaries(DiagramList *list)
QNonScalableGraphicsTextItem * _yLabel
QNonScalableGraphicsTextItem * _xLabel
QNonScalableGraphicsTextItem * addNonScalableText(const QString &text, const QFont &font=QFont())
Adds a non-scalable text object to the scene.
static const int MARGIN
void setYAxis(QArrow *arrow)
Sets an arrow as y-axis.
QVector< DiagramList * > _lists
QGraphicsGrid * _grid
void clearGrid()
Destroys the grid object (coordinate system) when a new graph is added.
QArrow * _yAxis
QRectF _unscaledBounds
void setXAxis(QArrow *arrow)
Sets an arrow as x-axis.
An arrow as a QGraphicsObject.
Definition QArrow.h:26
A 2D cartesian grid as a QGraphicsItem.
A QGraphicsTextItem that will ignore all geometric transformations.