BioSignalPi  v2
plotandcapturewidget.cpp
Go to the documentation of this file.
1 /*
2  * plotandcapturewidget.cpp
3  *
4  * Created on: Oct 29, 2015
5  * Author: martin
6  */
7 
8 #include "plotandcapturewidget.h"
9 #include "plot.h"
10 #include "datalogger.h"
11 
12 
14 QWidget(parent), plottedPoints(0)
15 {
16  d_plots.append(new Plot("Lead I", this));
17  d_plots.append(new Plot("Lead II", this));
18  d_plots.append(new Plot("Lead III", this));
19  d_plots.append(new Plot("Respiration", this));
20 
21  d_plots[0]->setCurveColor(Qt::red);
22  d_plots[1]->setCurveColor(Qt::blue);
23  d_plots[2]->setCurveColor(Qt::green);
24  d_plots[3]->setCurveColor(Qt::black);
25 
26 
27  counter = 0;
28  loopCounter = 0;
29  currentTime = 0.0;
30  timeInterval = 10.0;
31  d_clock.start();
32 
33 
34  device=new DeviceManager();
35  stream=new DataStream();
36  logger=new DataLogger();
37 
38  // QThread *sampleT = new QThread;
39  // device->moveToThread(sampleT);
40  setupComponents();
41  setupActions();
42  setupLayout();
43 
44 
45 
46 
47 }
48 
49 
51  //QPixmap pixmap = d_plot->grab();
52  QPixmap pixmap = this->grab();
53  pixmap.save("screen.png");
54 }
55 
59 void PlotAndCaptureWidget::updateStatus(QString status) {
60  currentStatusLabel->setText(status);
61 }
62 
63 
64 
65 
67  // TODO Auto-generated destructor stub
68  delete device;
69  delete stream;
70  delete logger;
71 }
72 
74 {
75 
76  device->init(1, *stream);
77  connect(device, SIGNAL(sendSampleVector(QVector<QVector<QPointF> >)), this, SLOT(plotSampleVector(QVector<QVector<QPointF> >)),Qt::QueuedConnection);
78  connect(device, SIGNAL(updateStatus(QString)), this, SLOT(updateStatus(QString)),Qt::QueuedConnection);
79  stopButton->setEnabled(true);
80  startButton->setDisabled(true);
81  currentStatusLabel->setText("Recording...");
82 
83 
84  device->startCapture();
85 
86 }
87 
94 {
95 
96 
97  device->stop();
98  stream->size();
99  stopButton->setEnabled(false);
100  currentStatusLabel->setText("Stopped!");
101 
102  logger->save(*stream);
103  startButton->setEnabled(true);
104 }
105 
106 void PlotAndCaptureWidget::plotSampleVector(QVector<QVector<QPointF> > sampleVector)
107 {
108 
109  // qDebug()<<sampleVector;
110  const int sampleSize = sampleVector.length();
111  QPointF last = sampleVector.at(sampleSize-1).at(0);
112  const double elapsedTime = last.x();
113 
114  if (elapsedTime > currentTime+timeInterval)
115  {
116  for (int ii = 0; ii<4; ii++) {
117  d_plots[ii]->IncrementInterval();
118  d_plots[ii]->ClearPlot();
119  }
120 // d_plot->IncrementInterval();
121 // d_plot->ClearPlot();
122 
123 // currentTime += timeInterval;
124  }
125 
126  for (int ii = 0; ii < sampleSize; ii++) {
127  for (int jj = 0; jj<4; jj++) {
128  d_plots[jj]->AppendPoint(sampleVector.at(ii).at(jj));
129  }
130 // d_plot->AppendPoint(sampleVector.at(ii).at(0));
131  }
132 
133  for (int ii = 0; ii<4; ii++) {
134  d_plots[ii]->DrawCurveSegment(sampleSize);
135  }
136 // d_plot->DrawCurveSegment(sampleSize);
137 
138 }
139 
140 void PlotAndCaptureWidget::setupComponents()
141 {
142  //Status label
143  currentStatusLabel = new QLabel("Off");
144 
145 
146  //=====START CHANNEL CONTROL COMPONENTS=====
147  channelControlGroup = new QGroupBox("Channel control");
148  channelControlButtonGroup = new QButtonGroup;
149  leadIButton = new QRadioButton("Lead I");
150  leadIIButton = new QRadioButton("Lead II");
151  leadIIIButton = new QRadioButton("Lead III");
152  respButton = new QRadioButton("Respiration");
153  channelControlButtonGroup->addButton(leadIButton, 1);
154  channelControlButtonGroup->addButton(leadIIButton, 2);
155  channelControlButtonGroup->addButton(leadIIIButton, 3);
156  channelControlButtonGroup->addButton(respButton, 4);
157  leadIButton->setChecked(true);
158  //=====END CHANNEL CONTROL COMPONENTS=====
159 
160  //Buttons
161  startButton = new QPushButton(tr("Start ECG capture"));
162  startButton->show();
163  stopButton = new QPushButton(tr("Stop ECG capture"));
164  stopButton->setDisabled(true);
165  takeScreenshot = new QPushButton("Take screenshot");
166 }
167 
168 void PlotAndCaptureWidget::setupActions()
169 {
170  //Signals-slots
171  connect(takeScreenshot, SIGNAL(clicked()), this, SLOT(takeScreen()));
172  connect(startButton, SIGNAL(clicked()), this, SLOT(startCapture()));
173  connect(stopButton, SIGNAL(clicked()), this, SLOT(stopCapture()));
174  connect(logger, SIGNAL(updateStatus(QString)), this, SLOT(updateStatus(QString)));
175 
176 }
177 
178 void PlotAndCaptureWidget::setupLayout()
179 {
180  QLabel *statusLabel = new QLabel("Status: ");
181  QLabel *xAxisLabel = new QLabel("Time [s]");
182  xAxisLabel->setAlignment(Qt::AlignCenter);
183 
184  //Channel control layout
185  QHBoxLayout *channelControlLayout = new QHBoxLayout;
186  channelControlLayout->addWidget(leadIButton);
187  channelControlLayout->addWidget(leadIIButton);
188  channelControlLayout->addWidget(leadIIIButton);
189  channelControlLayout->addWidget(respButton);
190 
191  channelControlGroup->setLayout(channelControlLayout);
192 
193  //Status bar layout
194  QHBoxLayout *statusBarLayout = new QHBoxLayout;
195  statusBarLayout->addWidget(statusLabel);
196  statusBarLayout->addWidget(currentStatusLabel);
197  statusBarLayout->addStretch();
198 
199  //Buttons on the top of the widget
200  QHBoxLayout *buttonLayout = new QHBoxLayout;
201  buttonLayout->addWidget(startButton);
202  buttonLayout->addWidget(stopButton);
203  buttonLayout->addWidget(takeScreenshot);
204 
205  //Main layout
206  QVBoxLayout *mainLayout = new QVBoxLayout;
207  mainLayout->addLayout(buttonLayout);
208  mainLayout->addLayout(statusBarLayout);
209 
210  for (int ii = 0; ii<4; ii++) {
211  mainLayout->addWidget(d_plots[ii]);
212  }
213  mainLayout->addWidget(xAxisLabel);
214  mainLayout->addWidget(channelControlGroup);
215 
216  setLayout(mainLayout);
217 }
void stopCapture()
Stop the ECG capture, this will stop the sampling thread so no more samples will be collected...
PlotAndCaptureWidget(QWidget *=NULL)
Extension of QwtPlot used for plotting data.
Definition: plot.h:14
The DataLogger class.
Definition: datalogger.h:16
void plotSampleVector(QVector< QVector< QPointF > >)
void stop()
Stops the running device.
void takeScreen()
Take a snapshot of the PLOT.
void save(DataStream &input)
Saves the input to a txt-file, header-file and edf-file(if bool saveAsEdf in SettingsSingleton) ...
Definition: datalogger.cpp:21
Abstract Interface that should be used for storing data in the memory.
Definition: datastream.h:16
void init(int, DataStream &)
Prepares a new data-collection,.
Handles which device to connect through the DeviceInterface.
Definition: devicemanager.h:23
void startCapture()
Starts the initiated device through a call to start()