BioSignalPi  v2
loadbigfile.cpp
Go to the documentation of this file.
1 #include "loadbigfile.h"
2 #include <QThread>
3 #include <QString>
4 #include <QVector>
5 #include <QPointF>
6 #include <QFile>
7 #include <QTextStream>
8 #include <QRegularExpression>
9 #include <QDebug>
10 
11 /*
12  * Class used to load a big .txt file in a new thread
13  */
14 LoadBigFile::LoadBigFile(QString fileName, QObject *parent):
15 QThread( parent )
16 {
17  fname = fileName;
18  decimateFlag = true;
19 }
20 
25 {
26  QFile myFile(fname);
27  if (myFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
28  QTextStream ecgInfo(&myFile);
29  QVector<QVector<QPointF> > ecgVals;
30  int iterations;
31  if (!ecgInfo.atEnd()) {
32  QString strVals = ecgInfo.readLine();
33  while (!ecgInfo.atEnd()) {
34  strVals = ecgInfo.readLine();
35  QStringList strPieces = strVals.split(QRegularExpression("\\s+"));
36 
37  if (strPieces.length()==5) {
38  // double x = 0.0, y = 0.0;
39  // x = strPieces[0].toDouble();
40  // y = strPieces[1].toDouble();
41 
42  double elapsed = strPieces[0].toDouble();
43  // elapsed = elapsed/5;
44 
45  QVector<QPointF> tmp;
46  tmp << QPointF(elapsed, strPieces[1].toDouble())
47  << QPointF(elapsed, strPieces[2].toDouble())
48  << QPointF(elapsed, strPieces[3].toDouble())
49  << QPointF(elapsed, strPieces[4].toDouble());
50 
51  // ecgVals.append(QPointF(x/1000,y));
52  ecgVals.append(tmp);
53  tmp.clear();
54  }
55  else if (strPieces.length()==4){
56  QVector<QPointF> tmp;
57  tmp << QPointF(iterations/1000, strPieces[0].toDouble())
58  << QPointF(iterations/1000, strPieces[1].toDouble())
59  << QPointF(iterations/1000, strPieces[2].toDouble())
60  << QPointF(iterations/1000, strPieces[3].toDouble());
61 
62  // ecgVals.append(QPointF(x/1000,y));
63  iterations++;
64  ecgVals.append(tmp);
65  tmp.clear();
66  }
67 
68  // for (int ii=0; ii<=8; ii++) {
69  // ecgInfo.readLine();
70  // }
71  }
72  }
73  ecgInfo.flush();
74  myFile.close();
75 
76  if (decimateFlag) {
77  decimate();
78  }
79 
80  emit sendFileData(ecgVals);
81  }
82 }
83 
84 void LoadBigFile::decimate()
85 {
86  //TODO
87 }
void sendFileData(QVector< QVector< QPointF > >)
signal used to send the loaded txt file as a QVector<QVector <QPointF> > that can be used for plottin...
LoadBigFile(QString fileName, QObject *parent=NULL)
Definition: loadbigfile.cpp:14
virtual void run()
Load the file with chosen filename and emit the signal sendFileData() when the file is read...
Definition: loadbigfile.cpp:24