-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentinformation.cpp
executable file
·91 lines (65 loc) · 1.61 KB
/
studentinformation.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
#include "studentinformation.h"
#include "ui_studentinformation.h"
#include <QMessageBox>
#include <QDebug>
#include <QTableWidget>
#include <QTableWidgetItem>
StudentInformation::StudentInformation(QWidget *parent) :
QDialog(parent),
ui(new Ui::StudentInformation)
{
ui->setupUi(this);
initData();
reloadData();
}
void StudentInformation::initData()
{
file = new QFile("/home/reza/Documents/Data.txt", this);
in = new QTextStream(file);
in->setCodec("UTF-8");
}
StudentInformation::~StudentInformation()
{
delete ui;
}
void StudentInformation::reloadData()
{
if( file->open(QFile::ReadOnly | QFile::Text)) {
QTableWidget *table = ui->tableWidget;
unsigned int row = 1, col = 1;
while(!in->atEnd()) {
QString data = in->readLine();
if (data == "#") {
row++;
col = 1;
continue;
}
if (table->rowCount() != row) {
table->setRowCount(row);
}
if (table->columnCount() < col) {
table->setColumnCount(col);
}
QTableWidgetItem *cell = new QTableWidgetItem(data);
table->setItem(row-1, col-1, cell);
col++;
if (col == 13 && data != "مهمان") {
col++;
}
}
}
else {
QMessageBox *message = new QMessageBox(this);
message->setWindowTitle("ERROR");
message->setText("متاسفانه فایل باز نشد");
message->setIcon(QMessageBox::Critical);
message->exec();
}
}
QString StudentInformation::readAllData()
{
QString data = in->readAll();
stuCounter = data.split("\n").size() - 1; //find student count
data.remove("\n");
return data;
}