MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
lineplot.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "lineplot.h"
41
42//=============================================================================================================
43// QT INCLUDES
44//=============================================================================================================
45
46//=============================================================================================================
47// EIGEN INCLUDES
48//=============================================================================================================
49
50//=============================================================================================================
51// USED NAMESPACES
52//=============================================================================================================
53
54using namespace DISPLIB;
55using namespace Eigen;
56#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
57using namespace QtCharts;
58#endif
59
60//=============================================================================================================
61// DEFINE MEMBER METHODS
62//=============================================================================================================
63
64LinePlot::LinePlot(QWidget *parent)
65: QChartView(parent)
66, m_pLineSeries(Q_NULLPTR)
67, m_pChart(Q_NULLPTR)
68{
69 update();
70}
71
72//=============================================================================================================
73
74LinePlot::LinePlot(const QVector<double> &y,
75 const QString& title,
76 QWidget *parent)
77: QChartView(parent)
78, m_sTitle(title)
79, m_pLineSeries(Q_NULLPTR)
80, m_pChart(Q_NULLPTR)
81{
82 updateData(y);
83}
84
85//=============================================================================================================
86
87LinePlot::LinePlot(const QVector<double> &x,
88 const QVector<double> &y,
89 const QString& title,
90 QWidget *parent)
91: QChartView(parent)
92, m_sTitle(title)
93, m_pLineSeries(Q_NULLPTR)
94, m_pChart(Q_NULLPTR)
95{
96 updateData(x, y);
97}
98
99//=============================================================================================================
100
104
105//=============================================================================================================
106
107void LinePlot::setTitle(const QString &p_sTitle)
108{
109 m_sTitle = p_sTitle;
110 update();
111}
112
113//=============================================================================================================
114
115void LinePlot::setXLabel(const QString &p_sXLabel)
116{
117 m_sXLabel = p_sXLabel;
118 update();
119}
120
121//=============================================================================================================
122
123void LinePlot::setYLabel(const QString &p_sYLabel)
124{
125 m_sYLabel = p_sYLabel;
126 update();
127}
128
129//=============================================================================================================
130
131void LinePlot::updateData(const QVector<double> &y)
132{
133 QVector<double> x(y.size());
134
135 for(int i = 0; i < x.size(); ++i) {
136 x[i] = i;
137 }
138
139 return updateData(x, y);
140}
141
142//=============================================================================================================
143
144void LinePlot::updateData(const QVector<double> &x,
145 const QVector<double> &y)
146{
147 if(!m_pLineSeries) {
148 m_pLineSeries = new QLineSeries;
149 }
150 else {
151 m_pLineSeries->clear();
152 }
153
154 for(int i = 0; i < x.size(); ++i) {
155 m_pLineSeries->append(x[i], y[i]);
156 }
157
158 if(!m_pChart) {
159 m_pChart = new QChart;
160 }
161 else {
162 m_pChart->removeAllSeries();
163 }
164
165 m_pChart->legend()->hide();
166 m_pChart->addSeries(m_pLineSeries);
167 m_pChart->createDefaultAxes();
168
169 update();
170}
171
172//=============================================================================================================
173
174void LinePlot::update()
175{
176 if(!m_pChart)
177 return;
178
179 m_pChart->setTitle(m_sTitle);
180
181 this->setChart(m_pChart);
182 this->setRenderHint(QPainter::Antialiasing);
183 this->setWindowTitle(m_sTitle);
184}
LinePlot class declaration.
void updateData(const QVector< double > &y)
Definition lineplot.cpp:131
void setTitle(const QString &p_sTitle)
Definition lineplot.cpp:107
void setXLabel(const QString &p_sXLabel)
Definition lineplot.cpp:115
void setYLabel(const QString &p_sYLabel)
Definition lineplot.cpp:123
LinePlot(QWidget *parent=Q_NULLPTR)
Definition lineplot.cpp:64
virtual ~LinePlot()
Definition lineplot.cpp:101