![]() |
OGS
|
|
A scene graph for a 2D Diagram including coordinate axes with labels and ticks for one or more plotted graphs.
Definition at line 17 of file DiagramScene.h.
#include <DiagramScene.h>
Public Member Functions | |
| DiagramScene (QObject *parent=nullptr) | |
| DiagramScene (DiagramList *list, QObject *parent=nullptr) | |
| ~DiagramScene () override | |
| QArrow * | addArrow (qreal length, qreal angle, QPen &pen) |
| void | addGraph (DiagramList *list) |
| Adds a graph to the scene, including all data points and meta-information. | |
| QGraphicsGrid * | addGrid (const QRectF &rect, int xTicks, int yTicks, const QPen &pen) |
| Adds a grid-object to the scene. | |
Static Public Attributes | |
| static const int | MARGIN = 30 |
Private Member Functions | |
| 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 * | addNonScalableText (const QString &text, const QFont &font=QFont()) |
| Adds a non-scalable text object to the scene. | |
| void | adjustAxis (qreal &min, qreal &max, int &numberOfTicks) |
| void | adjustScaling () |
| void | clearGrid () |
| Destroys the grid object (coordinate system) when a new graph is added. | |
| void | constructGrid () |
| void | drawGraph (DiagramList *list) |
| Plots the graph. | |
| int | getXAxisOffset () |
| int | getYAxisOffset () |
| void | initialize () |
| void | setDiagramBoundaries (DiagramList *list) |
| void | setXAxis (QArrow *arrow) |
| Sets an arrow as x-axis. | |
| void | setYAxis (QArrow *arrow) |
| Sets an arrow as y-axis. | |
| void | update () |
Private Attributes | |
| QRectF | _bounds |
| QRectF | _unscaledBounds |
| QVector< DiagramList * > | _lists |
| QVector< QGraphicsItemGroup * > | _graphCaptions |
| QVector< QGraphicsPathItem * > | _graphs |
| QGraphicsGrid * | _grid |
| QDateTime | _startDate |
| float | _scaleX |
| float | _scaleY |
| QArrow * | _xAxis |
| QArrow * | _yAxis |
| QNonScalableGraphicsTextItem * | _xLabel |
| QNonScalableGraphicsTextItem * | _yLabel |
| QNonScalableGraphicsTextItem * | _xUnit |
| QNonScalableGraphicsTextItem * | _yUnit |
| QVector< QNonScalableGraphicsTextItem * > | _xTicksText |
| QVector< QNonScalableGraphicsTextItem * > | _yTicksText |
|
explicit |
Creates a new scene. Since no data points are given some default values are used for constructing all the necessary objects.
Definition at line 17 of file DiagramScene.cpp.
References _bounds, and initialize().
|
explicit |
Creates a new scene.
| list | includes all necessary information of the graph to display. |
| parent | The parent QObject. |
Definition at line 28 of file DiagramScene.cpp.
References initialize(), and setDiagramBoundaries().
|
override |
Definition at line 35 of file DiagramScene.cpp.
References _graphCaptions, _graphs, _grid, _lists, _xAxis, _xLabel, _xTicksText, _xUnit, _yAxis, _yLabel, _yTicksText, and _yUnit.
| QArrow * DiagramScene::addArrow | ( | qreal | length, |
| qreal | angle, | ||
| QPen & | pen ) |
Adds an arrow object to the diagram which might be used as a coordinate axis, etc.
Definition at line 73 of file DiagramScene.cpp.
Referenced by initialize().
|
private |
The margin between the boundary of the scene and the bounding box of all items within the scene.
Adds a caption for a graph beneath the actual diagram.
Definition at line 81 of file DiagramScene.cpp.
References _graphCaptions.
Referenced by drawGraph().
| void DiagramScene::addGraph | ( | DiagramList * | list | ) |
Adds a graph to the scene, including all data points and meta-information.
Definition at line 97 of file DiagramScene.cpp.
References _lists, _xLabel, _xUnit, _yLabel, _yUnit, adjustScaling(), clearGrid(), constructGrid(), drawGraph(), DiagramList::getXLabel(), DiagramList::getXUnit(), DiagramList::getYLabel(), DiagramList::getYUnit(), setDiagramBoundaries(), and update().
| QGraphicsGrid * DiagramScene::addGrid | ( | const QRectF & | rect, |
| int | xTicks, | ||
| int | yTicks, | ||
| const QPen & | pen ) |
Adds a grid-object to the scene.
Definition at line 119 of file DiagramScene.cpp.
Referenced by constructGrid().
|
private |
Adds a non-scalable text object to the scene.
Definition at line 128 of file DiagramScene.cpp.
Referenced by constructGrid(), and initialize().
|
private |
Resizes a given axis to "nice" dimensions and calculates an adequate number of ticks to be placed on it
Definition at line 139 of file DiagramScene.cpp.
Referenced by constructGrid().
|
private |
Calculates scaling factors to set coordinate system and graphs to default window size
Definition at line 163 of file DiagramScene.cpp.
References _scaleX, _scaleY, _unscaledBounds, kDefaultX, and kDefaultY.
Referenced by addGraph().
|
private |
Destroys the grid object (coordinate system) when a new graph is added.
Definition at line 173 of file DiagramScene.cpp.
References _graphCaptions, _graphs, _grid, _lists, _xTicksText, and _yTicksText.
Referenced by addGraph().
|
private |
Adjusts the underlying grid based on the graphs that are displayed in the diagram
Definition at line 205 of file DiagramScene.cpp.
References _bounds, _grid, _scaleX, _scaleY, _startDate, _unscaledBounds, _xTicksText, _yTicksText, addGrid(), addNonScalableText(), adjustAxis(), and MARGIN.
Referenced by addGraph().
|
private |
Plots the graph.
For correct display the graph needs to be flipped vertically and then translated back to its original position
Definition at line 264 of file DiagramScene.cpp.
References _graphs, _scaleX, _scaleY, addCaption(), DiagramList::getColor(), DiagramList::getName(), DiagramList::getPath(), and DiagramList::minYValue().
Referenced by addGraph().
|
private |
Returns the y-value at which the x-axis should cross the y-axis. This value is zero if minYValue<0<maxYValue and minYValue otherwise.
Definition at line 292 of file DiagramScene.cpp.
References _bounds.
Referenced by update().
|
private |
Returns the x-value at which the y-axis should cross the x-axis. This value is zero if minXValue<0<maxXValue and minXValue otherwise.
Definition at line 301 of file DiagramScene.cpp.
References _bounds.
Referenced by update().
|
private |
Initialises the coordinate axes, adds labels and/or units to the axes, calculates axes-lengths, offsets, etc.
Definition at line 310 of file DiagramScene.cpp.
References _bounds, _xLabel, _xUnit, _yLabel, _yUnit, addArrow(), addNonScalableText(), setXAxis(), setYAxis(), and update().
Referenced by DiagramScene(), and DiagramScene().
|
private |
Updates the (unscaled) boundaries of the visible coordinate system when a new list is added (boundaries are rescaled in the constructGrid-method
Definition at line 329 of file DiagramScene.cpp.
References _lists, _startDate, _unscaledBounds, DiagramList::getStartDate(), DiagramList::maxXValue(), DiagramList::maxYValue(), DiagramList::minXValue(), and DiagramList::minYValue().
Referenced by DiagramScene(), and addGraph().
|
inlineprivate |
Sets an arrow as x-axis.
Definition at line 45 of file DiagramScene.h.
References _xAxis.
Referenced by initialize().
|
inlineprivate |
Sets an arrow as y-axis.
Definition at line 48 of file DiagramScene.h.
References _yAxis.
Referenced by initialize().
|
private |
Updates the scene at the start and every time new data points are added. Specifically, objects on the scene are assigned their position in the new coordinate system and are resized if necessary.
Definition at line 369 of file DiagramScene.cpp.
References _bounds, _graphCaptions, _graphs, _xAxis, _xLabel, _xUnit, _yAxis, _yLabel, _yUnit, getXAxisOffset(), getYAxisOffset(), and MARGIN.
Referenced by addGraph(), and initialize().
|
private |
Definition at line 52 of file DiagramScene.h.
Referenced by DiagramScene(), constructGrid(), getXAxisOffset(), getYAxisOffset(), initialize(), and update().
|
private |
Definition at line 55 of file DiagramScene.h.
Referenced by ~DiagramScene(), addCaption(), clearGrid(), and update().
|
private |
Definition at line 56 of file DiagramScene.h.
Referenced by ~DiagramScene(), clearGrid(), drawGraph(), and update().
|
private |
Definition at line 57 of file DiagramScene.h.
Referenced by ~DiagramScene(), clearGrid(), and constructGrid().
|
private |
Definition at line 54 of file DiagramScene.h.
Referenced by ~DiagramScene(), addGraph(), clearGrid(), and setDiagramBoundaries().
|
private |
Definition at line 59 of file DiagramScene.h.
Referenced by adjustScaling(), constructGrid(), and drawGraph().
|
private |
Definition at line 60 of file DiagramScene.h.
Referenced by adjustScaling(), constructGrid(), and drawGraph().
|
private |
Definition at line 58 of file DiagramScene.h.
Referenced by constructGrid(), and setDiagramBoundaries().
|
private |
Definition at line 53 of file DiagramScene.h.
Referenced by adjustScaling(), constructGrid(), and setDiagramBoundaries().
|
private |
Definition at line 61 of file DiagramScene.h.
Referenced by ~DiagramScene(), setXAxis(), and update().
|
private |
Definition at line 63 of file DiagramScene.h.
Referenced by ~DiagramScene(), addGraph(), initialize(), and update().
|
private |
Definition at line 67 of file DiagramScene.h.
Referenced by ~DiagramScene(), clearGrid(), and constructGrid().
|
private |
Definition at line 65 of file DiagramScene.h.
Referenced by ~DiagramScene(), addGraph(), initialize(), and update().
|
private |
Definition at line 62 of file DiagramScene.h.
Referenced by ~DiagramScene(), setYAxis(), and update().
|
private |
Definition at line 64 of file DiagramScene.h.
Referenced by ~DiagramScene(), addGraph(), initialize(), and update().
|
private |
Definition at line 68 of file DiagramScene.h.
Referenced by ~DiagramScene(), clearGrid(), and constructGrid().
|
private |
Definition at line 66 of file DiagramScene.h.
Referenced by ~DiagramScene(), addGraph(), initialize(), and update().
|
static |
Definition at line 28 of file DiagramScene.h.
Referenced by constructGrid(), DiagramView::minimumSizeHint(), DiagramView::sizeHint(), update(), and DiagramView::update().