OGS
DiagramView.cpp
Go to the documentation of this file.
1
15#include "DiagramView.h"
16
17#include <math.h>
18
19#include <QGraphicsTextItem>
20
21DiagramView::DiagramView(QWidget* parent) : QGraphicsView(parent)
22{
23 _scene = new DiagramScene();
24 setScene(_scene);
25 initialize();
26}
27
29 : QGraphicsView(parent)
30{
31 _scene = new DiagramScene(list);
32 setScene(_scene);
33 initialize();
34}
35
37{
38 delete _scene;
39}
40
42{
43 _scene->addGraph(list);
44 update();
45}
46
48{
49 return static_cast<int>((_scene->itemsBoundingRect()).height());
50}
51
53{
54 return static_cast<int>((_scene->itemsBoundingRect()).width());
55}
56
61{
62 // QMatrix currentMatrix = matrix();
63 // setMatrix(currentMatrix * scene->getTransformationMatrix());
64
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67
68 update();
69}
70
71/*
72 * Keeps the aspect ration of the labels when the view is resized.
73 * It is only necessary to call this if
74 * Qt::AspectRatioMode == Qt::IgnoreAspectRatio.
75 * Also, this method is kind of annoying because you have to set the
76 * appropriate transform for every single QGraphicsTextItem separately.
77 */
78/*
79 void DiagramView::keepItemAspectRatio()
80 {
81 double xFactor = transform().mapRect(QRectF(0, 0, 1, 1)).width();
82 double yFactor = transform().mapRect(QRectF(0, 0, 1, 1)).height();
83 QMatrix invertedScaling;
84 invertedScaling.scale(1.0 , xFactor / yFactor);
85
86 scene->xLabel->setTransform(QTransform(invertedScaling));
87 scene->yLabel->setTransform(QTransform(invertedScaling));
88 scene->yLabel->rotate(-90);
89 }
90 */
91
93{
94 return QSize(3 * DiagramScene::MARGIN, 2 * DiagramScene::MARGIN);
95}
96
98{
99 return QSize(6 * DiagramScene::MARGIN, 4 * DiagramScene::MARGIN);
100}
101
102void DiagramView::resizeEvent(QResizeEvent* event)
103{
104 Q_UNUSED(event)
105 update();
106 // keepItemAspectRatio();
107}
108
116{
117 // setResizeAnchor(QGraphicsView::AnchorViewCenter);
118 QRectF viewRect = _scene->itemsBoundingRect();
119 _scene->setSceneRect(viewRect);
120 QRectF sceneInView(0 /*_scene->MARGIN*/, DiagramScene::MARGIN / 2,
121 viewRect.width() /*+_scene->MARGIN*/,
122 viewRect.height() + DiagramScene::MARGIN);
123 fitInView(sceneInView, Qt::IgnoreAspectRatio);
124}
Definition of the DiagramView 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...
void addGraph(DiagramList *list)
Adds a graph to the scene, including all data points and meta-information.
static const int MARGIN
~DiagramView() override
QSize minimumSizeHint() const override
void resizeEvent(QResizeEvent *event) override
Resizes the scene.
int getWidth()
Returns the width of the bounding rectangle of all objects within the scene.
void addGraph(DiagramList *list)
Adds a new graph to the scene.
QSize sizeHint() const override
void initialize()
DiagramScene * _scene
Definition DiagramView.h:61
DiagramView(QWidget *parent=nullptr)
int getHeight()
Returns the height of the bounding rectangle of all objects within the scene.