-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilework.cpp
121 lines (106 loc) · 2.09 KB
/
filework.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "filework.h"
#include <QWidget>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
#include <iostream>
#include <cstdlib>
#include <QString>
#include <string>
#include <fstream>
#include <istream>
#include <QApplication>
FileWork::FileWork()
{
}
void FileWork::Open(QWidget *q)
{
try{
fileName = QFileDialog::getOpenFileName(q, QObject::tr("Open File"), ".", QObject::tr("Text Files (*.txt)"));
}
catch(std::exception &e)
{
QMessageBox::about(q, "title", e.what());
}
if (!fileName.isEmpty() && fileName.contains(".txt"))
{
QFileInfo file(fileName);
QString f = file.fileName();
}
else
{
QMessageBox::information(0, "Error", "File is empty. Exiting application.");
QApplication::quit();
}
}
void FileWork::Read()
{
count = 0;
int num = 0;
QString line = "";
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::information(0, "error", file.errorString());
}
QTextStream in(&file);
while(num < 4)
{
if (num == 0)
{
line = in.readLine();
seats = line.toInt();
num++;
}
else if (num == 1)
{
line = in.readLine();
names = line;
num++;
}
else if (num == 2)
{
line = in.readLine();
parties = line;
num++;
}
else
{
while(!in.atEnd())
{
line = in.readLine();
votes.append(line);
count++;
}
num++;
}
}
file.close();
}
int FileWork::get_Count()
{
return count;
}
int FileWork::get_Seats()
{
return seats;
}
QStringList FileWork::get_Votes()
{
return votes;
}
QStringList FileWork::get_Candidate_Names()
{
QStringList n = names.split(",");
return n;
}
QStringList FileWork::get_Candidate_Parties()
{
QStringList p = parties.split(",");
return p;
}
QString FileWork::get_FileName()
{
return fileName;
}