-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileio.cpp
65 lines (49 loc) · 1.3 KB
/
fileio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2020 Nicolas Stuhlfauth
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "fileio.h"
#include <QFile>
#include <QTextStream>
#include <QMessageLogger>
FileIO::FileIO(QObject *parent) :
QObject(parent)
{}
FileIO::~FileIO()
{}
/*
* This function is used to add a new line to the CSV file for every time the button is clicked.
*/
void FileIO::writeToFile(const QString &inputText)
{
QString filename = "Results.csv";
QFile file( filename );
if ( file.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text ) )
{
QTextStream stream( &file );
if (file.pos() == 0) {
stream << "Testperson, Testcounter, Distance, RealWidth, Time, DifficultyIndex" << endl;
}
stream << inputText << endl;
}
return;
}
/*
* This function returns the last Testperson-ID, which has been written to the CSV file
*/
int FileIO::getPersonID()
{
QString filename = "Results.csv";
QFile file(filename);
QString line;
if ( file.open(QIODevice::ReadOnly) )
{
QTextStream stream(&file);
while (!stream.atEnd()) {
line = stream.readLine();
}
line = line.split(",")[0];
}
m_personID = line.toInt();
return m_personID;
}