24 void PlottingWidget::getEcgFileList()
26 ecgFilesWidget->clear();
28 QStringList nameFilter;
29 nameFilter <<
"*.txt";
30 nameFilter <<
"*.edf";
31 nameFilter <<
"*.bdf";
32 QDir directory(qApp->applicationDirPath());
33 QStringList ecgFiles = directory.entryList(nameFilter);
35 ecgFilesWidget->addItems(ecgFiles);
41 void PlottingWidget::fileSelected(QListWidgetItem *item)
43 tlbl->setText(
"Loading "+item->text());
44 progBar->setVisible(
true);
45 progBar->setRange(0,0);
50 connect(loadFile, SIGNAL(sendFileData(QVector<QVector<QPointF> >)),
this, SLOT(initEcg(QVector<QVector<QPointF> >)));
55 QFileInfo fInfo(item->text());
56 QFile headerFile(fInfo.baseName()+
"_header.txt");
57 if (headerFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
58 QTextStream headerTextStream(&headerFile);
61 while (!headerTextStream.atEnd()) {
62 headerText += headerTextStream.readLine() +
"\n";
65 headerTextArea->setText(headerText);
66 headerTextStream.flush();
74 void PlottingWidget::clearPlot()
76 for (
int ii = 0; ii<4; ii++) {
77 d_plots[ii]->ClearPlot();
87 void PlottingWidget::updatePlot(
int index)
89 int windowSize = timeframeComboBox->itemData(timeframeComboBox->currentIndex()).toInt();
90 int startingPosition = index*windowSize;
93 for (
int ii = 0; ii<4; ii++) {
94 d_plots[ii]->setInterval(startingPosition, startingPosition+windowSize);
102 void PlottingWidget::windowSizeChanged(
int index)
106 int windowSize = timeframeComboBox->itemData(index).toInt();
107 nFrames =
static_cast<int>(recordingTime/timeframeComboBox->itemData(index).toInt());
109 for (
int ii = 0; ii<4; ii++) {
110 d_plots[ii]->setInterval(0, windowSize);
114 }
else if (index == 0) {
115 for (
int ii = 0; ii<4; ii++) {
116 d_plots[ii]->setInterval(0, recordingTime);
130 void PlottingWidget::initEcg(QVector<QVector<QPointF> > fileData)
134 tlbl->setText(
"Done!");
135 progBar->setMaximum(10);
136 progBar->setValue(10);
138 recordingTime =
static_cast<int>(ecgVals.last().at(0).x());
139 nFrames =
static_cast<int>(recordingTime/timeframeComboBox->itemData(timeframeComboBox->currentIndex()).toInt());
145 for (
int ii = 0; ii<4; ii++) {
146 d_plots[ii]->setInterval(0, timeframeComboBox->itemData(timeframeComboBox->currentIndex()).toInt());
149 if (recordingTime>5) {
150 QVector<double> maxVector;
151 QVector<double> minVector;
153 for (
int ii = 0; ii<4; ii++) {
154 maxVector.append(ecgVals[500].at(ii).y());
155 minVector.append(ecgVals[500].at(ii).y());
158 for (
int ii = 500; ii<ecgVals.length(); ii++) {
159 for (
int jj = 0; jj<4; jj++) {
160 if(ecgVals[ii].at(jj).y()<maxVector[jj]) {
161 if (ecgVals[ii].at(jj).y()<minVector[jj])
163 minVector[jj] = ecgVals[ii].at(jj).y();
166 maxVector[jj] = ecgVals[ii].at(jj).y();
171 for (
int ii = 0; ii<4; ii++) {
172 d_plots[ii]->setYAxis(minVector[ii], maxVector[ii]);
183 void PlottingWidget::plotVector()
185 const int sampleSize = ecgVals.length();
186 d_plots[0]->setInterval(0, ecgVals.last().at(0).x());
188 for (
int ii = 0; ii<4; ii++) {
189 d_plots[ii]->ClearPlot();
193 for (
int ii = 0; ii < sampleSize; ii++) {
194 for (
int jj = 0; jj<4; jj++) {
195 d_plots[jj]->AppendPoint(ecgVals.at(ii).at(jj));
200 for (
int ii = 0; ii<4; ii++) {
201 d_plots[ii]->DrawCurveSegment(sampleSize);
210 void PlottingWidget::prev()
212 if (currentFrame > 0) {
213 int windowSize = timeframeComboBox->itemData(timeframeComboBox->currentIndex()).toInt();
214 currentFrame = startingPointSlider->
value() - 1;
215 startingPointSlider->
setValue(currentFrame);
217 for (
int ii = 0; ii<4; ii++) {
218 d_plots[ii]->setInterval(currentFrame*windowSize, (currentFrame+1)*windowSize);
227 void PlottingWidget::play()
229 int windowSize = timeframeComboBox->itemData(timeframeComboBox->currentIndex()).toInt();
230 playTimer->start(windowSize*1000);
236 void PlottingWidget::pause()
244 void PlottingWidget::next()
246 if (currentFrame<nFrames) {
247 int windowSize = timeframeComboBox->itemData(timeframeComboBox->currentIndex()).toInt();
248 currentFrame = startingPointSlider->
value() + 1;
249 startingPointSlider->
setValue(currentFrame);
251 for (
int ii = 0; ii<4; ii++) {
252 d_plots[ii]->setInterval(currentFrame*windowSize, (currentFrame+1)*windowSize);
265 int delta =
event->delta();
269 }
else if (delta < 0) {
277 void PlottingWidget::setupComponents()
280 playTimer =
new QTimer();
283 getFilesButton =
new QPushButton(
"Get ECG files");
284 resetPlotButton =
new QPushButton(
"Reset plot");
287 headerTextArea =
new QTextEdit(
"");
290 tlbl =
new QLabel(
"no file selected");
293 ecgFilesWidget =
new QListWidget;
294 ecgFilesWidget->setFixedSize(QSize(QWIDGETSIZE_MAX,100));
298 d_plots.append(
new Plot(
"Lead I",
this));
299 d_plots.append(
new Plot(
"Lead II",
this));
300 d_plots.append(
new Plot(
"Lead III",
this));
301 d_plots.append(
new Plot(
"Respiration",
this));
303 d_plots[0]->setCurveColor(Qt::red);
304 d_plots[1]->setCurveColor(Qt::blue);
305 d_plots[2]->setCurveColor(Qt::green);
306 d_plots[3]->setCurveColor(Qt::black);
308 d_plots[3]->setCurveMargin(0.0001);
311 progBar =
new QProgressBar();
312 progBar->setRange(0,0);
313 progBar->setVisible(
false);
314 progBar->setTextVisible(
false);
317 timeframeComboBox =
new QComboBox();
318 timeframeComboBox->addItem(
"Whole recording", 0);
319 timeframeComboBox->insertSeparator(1);
320 timeframeComboBox->addItem(
"5 s", 5);
321 timeframeComboBox->addItem(
"10 s", 10);
322 timeframeComboBox->addItem(
"1 min", 60);
323 timeframeComboBox->setCurrentIndex(2);
332 void PlottingWidget::setupActions()
335 prevAction =
new QAction(QIcon(
":/images/images/media-skip-backward-6.png"),
"Prev.",
this);
336 playAction =
new QAction(QIcon(
":/images/images/media-playback-start-6.png"),
"Play",
this);
337 pauseAction =
new QAction(QIcon(
":/images/images/media-playback-pause-6.png"),
"Pause",
this);
338 nextAction =
new QAction(QIcon(
":/images/images/media-skip-forward-6.png"),
"Next",
this);
341 connect(prevAction, SIGNAL(triggered()),
this, SLOT(prev()));
342 connect(nextAction, SIGNAL(triggered()),
this, SLOT(next()));
343 connect(playAction, SIGNAL(triggered()),
this, SLOT(play()));
344 connect(pauseAction, SIGNAL(triggered()),
this, SLOT(pause()));
345 connect(timeframeComboBox,SIGNAL(currentIndexChanged(
int)),
this,SLOT(windowSizeChanged(
int)));
346 connect(getFilesButton, SIGNAL(clicked()),
this, SLOT(getEcgFileList()));
347 connect(resetPlotButton, SIGNAL(clicked()),
this, SLOT(clearPlot()));
348 connect(startingPointSlider, SIGNAL(valueChanged(
int)),
this, SLOT(updatePlot(
int)));
349 connect(ecgFilesWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this, SLOT(fileSelected(QListWidgetItem*)));
350 connect(playTimer, SIGNAL(timeout()),
this, SLOT(next()));
356 void PlottingWidget::setupLayout()
359 QLabel *wsLabel =
new QLabel(
"Window size");
362 QToolBar *playbackButtons =
new QToolBar;
363 playbackButtons->addAction(prevAction);
364 playbackButtons->addAction(playAction);
365 playbackButtons->addAction(pauseAction);
366 playbackButtons->addAction(nextAction);
369 QHBoxLayout *progressBarLayout =
new QHBoxLayout;
370 progressBarLayout->addWidget(tlbl, 2);
371 progressBarLayout->addWidget(progBar, 8);
374 QHBoxLayout *wsLayout =
new QHBoxLayout;
375 wsLayout->addStretch();
376 wsLayout->addWidget(wsLabel);
377 wsLayout->addWidget(timeframeComboBox);
378 wsLayout->addStretch();
381 QHBoxLayout *playbackLayout =
new QHBoxLayout;
382 playbackLayout->addWidget(playbackButtons);
383 playbackLayout->addWidget(startingPointSlider);
386 QVBoxLayout *sidebarLayout =
new QVBoxLayout;
387 sidebarLayout->addWidget(getFilesButton);
388 sidebarLayout->addWidget(ecgFilesWidget);
389 sidebarLayout->addLayout(progressBarLayout);
390 sidebarLayout->addLayout(wsLayout);
391 sidebarLayout->addWidget(headerTextArea);
392 sidebarLayout->addStretch();
393 sidebarLayout->addWidget(resetPlotButton);
396 QVBoxLayout *plotLayout =
new QVBoxLayout;
399 for (
int ii = 0; ii < 4; ii++) {
400 plotLayout->addWidget(d_plots[ii]);
403 plotLayout->addLayout(playbackLayout);
406 QHBoxLayout *mainLayout =
new QHBoxLayout;
407 mainLayout->addLayout(sidebarLayout, 1);
408 mainLayout->addLayout(plotLayout, 9);
410 setLayout(mainLayout);
Extension of QwtPlot used for plotting data.
Class used to load a big .txt file in a new thread.