OGS
DiagramView Class Reference

Detailed Description

A view in which to display a DiagramScene.

A view in which to display a DiagramScene. It supports resizing of the window and loading of data into the diagram.

Definition at line 16 of file DiagramView.h.

#include <DiagramView.h>

Inheritance diagram for DiagramView:
[legend]
Collaboration diagram for DiagramView:
[legend]

Public Member Functions

 DiagramView (QWidget *parent=nullptr)
 DiagramView (DiagramList *list, QWidget *parent=nullptr)
 ~DiagramView () override
void addGraph (DiagramList *list)
 Adds a new graph to the scene.
int getHeight ()
 Returns the height of the bounding rectangle of all objects within the scene.
int getWidth ()
 Returns the width of the bounding rectangle of all objects within the scene.

Protected Member Functions

void resizeEvent (QResizeEvent *event) override
 Resizes the scene.

Private Member Functions

void initialize ()
void keepItemAspectRatio ()
QSize minimumSizeHint () const override
QSize sizeHint () const override
void update ()

Private Attributes

DiagramScene_scene

Constructor & Destructor Documentation

◆ DiagramView() [1/2]

DiagramView::DiagramView ( QWidget * parent = nullptr)
explicit

Creates an empty view.

Definition at line 10 of file DiagramView.cpp.

10 : QGraphicsView(parent)
11{
12 _scene = new DiagramScene();
13 setScene(_scene);
14 initialize();
15}
void initialize()
DiagramScene * _scene
Definition DiagramView.h:50

References _scene, and initialize().

◆ DiagramView() [2/2]

DiagramView::DiagramView ( DiagramList * list,
QWidget * parent = nullptr )
explicit

Creates a view already containing a graph

Parameters
listContains a list of data points and metainformation to be displayed by the scene.
parentThe parent QWidget.

Definition at line 17 of file DiagramView.cpp.

18 : QGraphicsView(parent)
19{
20 _scene = new DiagramScene(list);
21 setScene(_scene);
22 initialize();
23}

References _scene, and initialize().

◆ ~DiagramView()

DiagramView::~DiagramView ( )
override

Definition at line 25 of file DiagramView.cpp.

26{
27 delete _scene;
28}

References _scene.

Member Function Documentation

◆ addGraph()

void DiagramView::addGraph ( DiagramList * list)

Adds a new graph to the scene.

Definition at line 30 of file DiagramView.cpp.

31{
32 _scene->addGraph(list);
33 update();
34}

References _scene, and update().

◆ getHeight()

int DiagramView::getHeight ( )

Returns the height of the bounding rectangle of all objects within the scene.

Definition at line 36 of file DiagramView.cpp.

37{
38 return static_cast<int>((_scene->itemsBoundingRect()).height());
39}

References _scene.

◆ getWidth()

int DiagramView::getWidth ( )

Returns the width of the bounding rectangle of all objects within the scene.

Definition at line 41 of file DiagramView.cpp.

42{
43 return static_cast<int>((_scene->itemsBoundingRect()).width());
44}

References _scene.

◆ initialize()

void DiagramView::initialize ( )
private

Initialises the view.

Definition at line 49 of file DiagramView.cpp.

50{
51 // QMatrix currentMatrix = matrix();
52 // setMatrix(currentMatrix * scene->getTransformationMatrix());
53
54 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
55 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
56
57 update();
58}

References update().

Referenced by DiagramView(), and DiagramView().

◆ keepItemAspectRatio()

void DiagramView::keepItemAspectRatio ( )
private

◆ minimumSizeHint()

QSize DiagramView::minimumSizeHint ( ) const
overrideprivate

Definition at line 81 of file DiagramView.cpp.

82{
83 return QSize(3 * DiagramScene::MARGIN, 2 * DiagramScene::MARGIN);
84}
static const int MARGIN

References DiagramScene::MARGIN.

◆ resizeEvent()

void DiagramView::resizeEvent ( QResizeEvent * event)
overrideprotected

Resizes the scene.

Definition at line 91 of file DiagramView.cpp.

92{
93 Q_UNUSED(event)
94 update();
95 // keepItemAspectRatio();
96}

References update().

◆ sizeHint()

QSize DiagramView::sizeHint ( ) const
overrideprivate

Definition at line 86 of file DiagramView.cpp.

87{
88 return QSize(6 * DiagramScene::MARGIN, 4 * DiagramScene::MARGIN);
89}

References DiagramScene::MARGIN.

◆ update()

void DiagramView::update ( )
private

Updates the view automatically when a new list is added or when the window containing the view is resized or changes its state. Basically, the methods makes sure that everything keeps looking as it is supposed to.

Definition at line 104 of file DiagramView.cpp.

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}

References _scene, and DiagramScene::MARGIN.

Referenced by addGraph(), initialize(), and resizeEvent().

Member Data Documentation

◆ _scene

DiagramScene* DiagramView::_scene
private

Definition at line 50 of file DiagramView.h.

Referenced by DiagramView(), DiagramView(), ~DiagramView(), addGraph(), getHeight(), getWidth(), and update().


The documentation for this class was generated from the following files: