OGS
DiagramScene.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include "DiagramList.h"
7#include "QArrow.h"
8#include "QGraphicsGrid.h"
10#include <QGraphicsScene>
11
12class QDateTime;
13
17class DiagramScene : public QGraphicsScene
18{
19public:
20 explicit DiagramScene(QObject* parent = nullptr);
21 explicit DiagramScene(DiagramList* list, QObject* parent = nullptr);
22 ~DiagramScene() override;
23
24 QArrow* addArrow(qreal length, qreal angle, QPen& pen);
25 void addGraph(DiagramList* list);
26 QGraphicsGrid* addGrid(const QRectF &rect, int xTicks, int yTicks, const QPen &pen);
27
28 static const int MARGIN = 30;
29
30private:
31 void addCaption(const QString &name, QPen &pen);
33 const QFont &font = QFont());
34 void adjustAxis(qreal& min, qreal& max, int& numberOfTicks);
35 void adjustScaling();
36 void clearGrid();
37 void constructGrid();
38 void drawGraph(DiagramList* list);
39 int getXAxisOffset();
40 int getYAxisOffset();
41 void initialize();
43
45 void setXAxis(QArrow* arrow) { _xAxis = arrow; }
46
48 void setYAxis(QArrow* arrow) { _yAxis = arrow; }
49
50 void update();
51
52 QRectF _bounds;
54 QVector<DiagramList*> _lists;
55 QVector<QGraphicsItemGroup*> _graphCaptions;
56 QVector<QGraphicsPathItem*> _graphs;
58 QDateTime _startDate;
59 float _scaleX;
60 float _scaleY;
67 QVector<QNonScalableGraphicsTextItem*> _xTicksText;
68 QVector<QNonScalableGraphicsTextItem*> _yTicksText;
69};
A List of data points and all the necessary meta-information to draw a graph.
Definition DiagramList.h:18
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:15
A 2D cartesian grid as a QGraphicsItem.
A QGraphicsTextItem that will ignore all geometric transformations.