v2.0.0
Loading...
Searching...
No Matches
graph.cpp
Go to the documentation of this file.
1//=============================================================================================================
14
15//=============================================================================================================
16// INCLUDES
17//=============================================================================================================
18
19#include "graph.h"
20
21//=============================================================================================================
22// QT INCLUDES
23//=============================================================================================================
24
25#include <QResizeEvent>
26#include <QPainter>
27
28//=============================================================================================================
29// EIGEN INCLUDES
30//=============================================================================================================
31
32//=============================================================================================================
33// USED NAMESPACES
34//=============================================================================================================
35
36using namespace DISPLIB;
37using namespace Eigen;
38
39//=============================================================================================================
40// DEFINE MEMBER METHODS
41//=============================================================================================================
42
43Graph::Graph(QWidget *parent)
44: QWidget(parent)
45{
46 init();
47}
48
49//=============================================================================================================
50
52{
53 m_sTitle = QString("");
54 m_sXLabel = QString("");
55 m_sYLabel = QString("");
56
57 //Set Borders
60
61 this->setMinimumWidth(m_iBorderLeftRight*2.5);
62 this->setMinimumHeight(m_iBorderTopBottom*2.5);
63
64 //Set Fonts
65 m_qFontAxes.setPixelSize(12);
66 m_qPenAxes = QPen(Qt::black);
67
68 m_qFontTitle.setPixelSize(20);
69 m_qFontTitle.setBold(true);
70 m_qPenTitle = QPen(Qt::black);
71}
72
73//=============================================================================================================
74
75void Graph::setTitle(const QString &p_sTitle)
76{
77 m_sTitle = p_sTitle;
78 update();
79}
80
81//=============================================================================================================
82
83void Graph::setXLabel(const QString &p_sXLabel)
84{
85 m_sXLabel = p_sXLabel;
86 update();
87}
88
89//=============================================================================================================
90
91void Graph::setYLabel(const QString &p_sYLabel)
92{
93 m_sYLabel = p_sYLabel;
94 update();
95}
96
97//=============================================================================================================
98
99void Graph::drawLabels(qint32 p_iContentWidth, qint32 p_iContentHeight)
100{
101 QPainter painter(this);
102
103 qint32 t_iLabelWidth = m_qSizeWidget.width()-2*m_iBorderLeftRight;
104 qint32 t_iLabelHeight = 100;
105
106 // -- Title --
107 if(!m_sTitle.isEmpty())
108 {
109 painter.save();
110 painter.setPen(m_qPenTitle);
111 painter.setFont(m_qFontTitle);
112
113 painter.translate((m_qSizeWidget.width()-t_iLabelWidth)/2, (m_qSizeWidget.height()-p_iContentHeight)/2 - m_iBorderTopBottom*1.5);
114 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sTitle);
115
116 painter.restore();
117 }
118
119 // -- Axes --
120 painter.setPen(m_qPenAxes);
121 painter.setFont(m_qFontAxes);
122
123 // X FsLabel
124 if(!m_sXLabel.isEmpty())
125 {
126 painter.save();
127 painter.translate((m_qSizeWidget.width()-t_iLabelWidth)/2, p_iContentHeight+((m_qSizeWidget.height()-p_iContentHeight-m_iBorderTopBottom)/2));
128 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sXLabel);
129 painter.restore();
130 }
131
132 //Y FsLabel
133 if(!m_sYLabel.isEmpty())
134 {
135 painter.save();
136 painter.rotate(270);
137 painter.translate(-(m_qSizeWidget.height()+t_iLabelWidth)/2,(m_qSizeWidget.width()-p_iContentWidth)/2-t_iLabelHeight*0.75);
138 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sYLabel);
139 painter.restore();
140 }
141}
142
143//=============================================================================================================
144
145void Graph::resizeEvent(QResizeEvent* event)
146{
147 m_qSizeWidget = event->size();
148 // Call base class impl
149 QWidget::resizeEvent(event);
150}
151
Abstract base widget providing title, axis labels and resize handling for the in-house 2-D plots.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
QFont m_qFontTitle
Definition graph.h:139
QPen m_qPenAxes
Definition graph.h:148
Graph(QWidget *parent=0)
Definition graph.cpp:43
QString m_sXLabel
Definition graph.h:145
void init()
Definition graph.cpp:51
QSize m_qSizeWidget
Definition graph.h:136
QFont m_qFontAxes
Definition graph.h:147
void setYLabel(const QString &p_sYLabel)
Definition graph.cpp:91
QString m_sTitle
Definition graph.h:138
QString m_sYLabel
Definition graph.h:146
QPen m_qPenTitle
Definition graph.h:140
qint32 m_iBorderLeftRight
Definition graph.h:143
void setTitle(const QString &p_sTitle)
Definition graph.cpp:75
void resizeEvent(QResizeEvent *event)
Definition graph.cpp:145
qint32 m_iBorderTopBottom
Definition graph.h:142
void drawLabels(qint32 p_iContentWidth, qint32 p_iContentHeight)
Definition graph.cpp:99
void setXLabel(const QString &p_sXLabel)
Definition graph.cpp:83