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 painter.save();
109 painter.setPen(m_qPenTitle);
110 painter.setFont(m_qFontTitle);
111
112 painter.translate((m_qSizeWidget.width() - t_iLabelWidth) / 2, (m_qSizeWidget.height() - p_iContentHeight) / 2 - m_iBorderTopBottom * 1.5);
113 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sTitle);
114
115 painter.restore();
116 }
117
118 // -- Axes --
119 painter.setPen(m_qPenAxes);
120 painter.setFont(m_qFontAxes);
121
122 // X FsLabel
123 if (!m_sXLabel.isEmpty()) {
124 painter.save();
125 painter.translate((m_qSizeWidget.width() - t_iLabelWidth) / 2, p_iContentHeight + ((m_qSizeWidget.height() - p_iContentHeight - m_iBorderTopBottom) / 2));
126 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sXLabel);
127 painter.restore();
128 }
129
130 //Y FsLabel
131 if (!m_sYLabel.isEmpty()) {
132 painter.save();
133 painter.rotate(270);
134 painter.translate(-(m_qSizeWidget.height() + t_iLabelWidth) / 2, (m_qSizeWidget.width() - p_iContentWidth) / 2 - t_iLabelHeight * 0.75);
135 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sYLabel);
136 painter.restore();
137 }
138}
139
140//=============================================================================================================
141
142void Graph::resizeEvent(QResizeEvent* event)
143{
144 m_qSizeWidget = event->size();
145 // Call base class impl
146 QWidget::resizeEvent(event);
147}
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:141
QPen m_qPenAxes
Definition graph.h:150
Graph(QWidget *parent=0)
Definition graph.cpp:43
QString m_sXLabel
Definition graph.h:147
void init()
Definition graph.cpp:51
QSize m_qSizeWidget
Definition graph.h:138
QFont m_qFontAxes
Definition graph.h:149
void setYLabel(const QString &p_sYLabel)
Definition graph.cpp:91
QString m_sTitle
Definition graph.h:140
QString m_sYLabel
Definition graph.h:148
QPen m_qPenTitle
Definition graph.h:142
qint32 m_iBorderLeftRight
Definition graph.h:145
void setTitle(const QString &p_sTitle)
Definition graph.cpp:75
void resizeEvent(QResizeEvent *event)
Definition graph.cpp:142
qint32 m_iBorderTopBottom
Definition graph.h:144
void drawLabels(qint32 p_iContentWidth, qint32 p_iContentHeight)
Definition graph.cpp:99
void setXLabel(const QString &p_sXLabel)
Definition graph.cpp:83