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 27 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 21 of file DiagramView.cpp.

21 : QGraphicsView(parent)
22{
23 _scene = new DiagramScene();
24 setScene(_scene);
25 initialize();
26}
A scene graph for a 2D Diagram including coordinate axes with labels and ticks for one or more plotte...
void initialize()
DiagramScene * _scene
Definition DiagramView.h:61

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 28 of file DiagramView.cpp.

29 : QGraphicsView(parent)
30{
31 _scene = new DiagramScene(list);
32 setScene(_scene);
33 initialize();
34}

References _scene, and initialize().

◆ ~DiagramView()

DiagramView::~DiagramView ( )
override

Definition at line 36 of file DiagramView.cpp.

37{
38 delete _scene;
39}

References _scene.

Member Function Documentation

◆ addGraph()

void DiagramView::addGraph ( DiagramList * list)

Adds a new graph to the scene.

Definition at line 41 of file DiagramView.cpp.

42{
43 _scene->addGraph(list);
44 update();
45}
void addGraph(DiagramList *list)
Adds a graph to the scene, including all data points and meta-information.

References _scene, DiagramScene::addGraph(), and update().

◆ getHeight()

int DiagramView::getHeight ( )

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

Definition at line 47 of file DiagramView.cpp.

48{
49 return static_cast<int>((_scene->itemsBoundingRect()).height());
50}

References _scene.

◆ getWidth()

int DiagramView::getWidth ( )

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

Definition at line 52 of file DiagramView.cpp.

53{
54 return static_cast<int>((_scene->itemsBoundingRect()).width());
55}

References _scene.

◆ initialize()

void DiagramView::initialize ( )
private

Initialises the view.

Definition at line 60 of file DiagramView.cpp.

61{
62 // QMatrix currentMatrix = matrix();
63 // setMatrix(currentMatrix * scene->getTransformationMatrix());
64
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67
68 update();
69}

References update().

Referenced by DiagramView(), and DiagramView().

◆ keepItemAspectRatio()

void DiagramView::keepItemAspectRatio ( )
private

◆ minimumSizeHint()

QSize DiagramView::minimumSizeHint ( ) const
overrideprivate

Definition at line 92 of file DiagramView.cpp.

93{
94 return QSize(3 * DiagramScene::MARGIN, 2 * DiagramScene::MARGIN);
95}
static const int MARGIN

References DiagramScene::MARGIN.

◆ resizeEvent()

void DiagramView::resizeEvent ( QResizeEvent * event)
overrideprotected

Resizes the scene.

Definition at line 102 of file DiagramView.cpp.

103{
104 Q_UNUSED(event)
105 update();
106 // keepItemAspectRatio();
107}

References update().

◆ sizeHint()

QSize DiagramView::sizeHint ( ) const
overrideprivate

Definition at line 97 of file DiagramView.cpp.

98{
99 return QSize(6 * DiagramScene::MARGIN, 4 * DiagramScene::MARGIN);
100}

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 115 of file DiagramView.cpp.

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}

References _scene, and DiagramScene::MARGIN.

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

Member Data Documentation

◆ _scene

DiagramScene* DiagramView::_scene
private

Definition at line 61 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: