OGS
DiagramView.cpp
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#include "DiagramView.h"
5
6#include <math.h>
7
8#include <QGraphicsTextItem>
9
10DiagramView::DiagramView(QWidget* parent) : QGraphicsView(parent)
11{
12 _scene = new DiagramScene();
13 setScene(_scene);
14 initialize();
15}
16
18 : QGraphicsView(parent)
19{
20 _scene = new DiagramScene(list);
21 setScene(_scene);
22 initialize();
23}
24
26{
27 delete _scene;
28}
29
31{
32 _scene->addGraph(list);
33 update();
34}
35
37{
38 return static_cast<int>((_scene->itemsBoundingRect()).height());
39}
40
42{
43 return static_cast<int>((_scene->itemsBoundingRect()).width());
44}
45
50{
51 // QMatrix currentMatrix = matrix();
52 // setMatrix(currentMatrix * scene->getTransformationMatrix());
53
54 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
55 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
56
57 update();
58}
59
60/*
61 * Keeps the aspect ration of the labels when the view is resized.
62 * It is only necessary to call this if
63 * Qt::AspectRatioMode == Qt::IgnoreAspectRatio.
64 * Also, this method is kind of annoying because you have to set the
65 * appropriate transform for every single QGraphicsTextItem separately.
66 */
67/*
68 void DiagramView::keepItemAspectRatio()
69 {
70 double xFactor = transform().mapRect(QRectF(0, 0, 1, 1)).width();
71 double yFactor = transform().mapRect(QRectF(0, 0, 1, 1)).height();
72 QMatrix invertedScaling;
73 invertedScaling.scale(1.0 , xFactor / yFactor);
74
75 scene->xLabel->setTransform(QTransform(invertedScaling));
76 scene->yLabel->setTransform(QTransform(invertedScaling));
77 scene->yLabel->rotate(-90);
78 }
79 */
80
82{
83 return QSize(3 * DiagramScene::MARGIN, 2 * DiagramScene::MARGIN);
84}
85
87{
88 return QSize(6 * DiagramScene::MARGIN, 4 * DiagramScene::MARGIN);
89}
90
91void DiagramView::resizeEvent(QResizeEvent* event)
92{
93 Q_UNUSED(event)
94 update();
95 // keepItemAspectRatio();
96}
97
105{
106 // setResizeAnchor(QGraphicsView::AnchorViewCenter);
107 QRectF viewRect = _scene->itemsBoundingRect();
108 _scene->setSceneRect(viewRect);
109 QRectF sceneInView(0 /*_scene->MARGIN*/, DiagramScene::MARGIN / 2,
110 viewRect.width() /*+_scene->MARGIN*/,
111 viewRect.height() + DiagramScene::MARGIN);
112 fitInView(sceneInView, Qt::IgnoreAspectRatio);
113}
A List of data points and all the necessary meta-information to draw a graph.
Definition DiagramList.h:18
A scene graph for a 2D Diagram including coordinate axes with labels and ticks for one or more plotte...
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:50
DiagramView(QWidget *parent=nullptr)
int getHeight()
Returns the height of the bounding rectangle of all objects within the scene.