-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexposeclass.cpp
190 lines (164 loc) · 6.01 KB
/
exposeclass.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "exposeclass.h"
#include <QDebug>
ExposeClass::ExposeClass(Users *userinfo, QObject *parent) : QObject(parent)
{
this->userinfo=userinfo;
// We assign our model to the model that we created in exposemodel.h
m_model = new ExposeModel(this);
//query.exec ("select * from users");
//qDebug()<<(userinfo.Username);
for (int i = 0;i<(userinfo->numberOfUsers);i++)
{
// Here we create the item we want to have the data
QStandardItem *item = new QStandardItem;
// Here we give the data to the item
item->setData("0", Score1Role);
item->setData(userinfo->users[i].name, NameRole);
item->setData(userinfo->users[i].score,ScoreRole);
item->setData(userinfo->users[i].pass, PassRole);
item->setData(userinfo->users[i].admin, AdminRole);
item->setData(userinfo->users[i].date, DateRole);
//here we add the item to the model
m_model->appendRow(item);
}
}
QStandardItemModel *ExposeClass::model() const
{
return m_model;
}
void ExposeClass::clearModel()
{
m_model->clear();
}
void ExposeClass::updateModel()
{
m_model->clear();
for (int i = 0;i<(userinfo->numberOfUsers);i++)
{
// Here we create the item we want to have the data
QStandardItem *item = new QStandardItem;
// Here we give the data to the item
item->setData("0", Score1Role);
item->setData(userinfo->users[i].name, NameRole);
item->setData(userinfo->users[i].score,ScoreRole);
item->setData(userinfo->users[i].pass, PassRole);
item->setData(userinfo->users[i].admin, AdminRole);
item->setData(userinfo->users[i].date, DateRole);
//here we add the item to the model
m_model->appendRow(item);
}
}
void ExposeClass::updateSort()
{
qDebug()<<(QString("5") > QString("4"));
User * temp=new User();
if(Fild== QString("Score") && IDFild == QString("Descending"))
for(int i=0;i<userinfo->numberOfUsers;i++)
{
for(int j=0;j<userinfo->numberOfUsers -1;j++)
{
if(userinfo->users[j].score<userinfo->users[i+1].score)
{
temp->name=userinfo->users[j].name;
temp->score=userinfo->users[j].score;
temp->pass=userinfo->users[j].pass;
temp->admin=userinfo->users[j].admin;
temp->date=userinfo->users[j].date;
userinfo->users[j].name=userinfo->users[j +1].name;
userinfo->users[j].score=userinfo->users[j +1].score;
userinfo->users[j].pass=userinfo->users[j +1].pass;
userinfo->users[j].admin=userinfo->users[j +1].admin;
userinfo->users[j].date=userinfo->users[j +1].date;
userinfo->users[j +1].name=temp->name;
userinfo->users[j +1].score=temp->score;
userinfo->users[j +1].pass=temp->pass;
userinfo->users[j +1].admin=temp->admin;
userinfo->users[j +1].date=temp->date;
}
//delete temp;
qDebug()<<" S A ";
}
updateModel ();
}
else
if(Fild == QString("Score") && IDFild == QString("Ascending"))
{
for(int i=0;i<userinfo->numberOfUsers;i++)
for(int j=0;j<userinfo->numberOfUsers -1;j++)
{
if(userinfo->users[j].score>userinfo->users[i+1].score)
{
temp->name=userinfo->users[j].name;
temp->score=userinfo->users[j].score;
temp->pass=userinfo->users[j].pass;
temp->admin=userinfo->users[j].admin;
temp->date=userinfo->users[j].date;
userinfo->users[j].name=userinfo->users[j +1].name;
userinfo->users[j].score=userinfo->users[j +1].score;
userinfo->users[j].pass=userinfo->users[j +1].pass;
userinfo->users[j].admin=userinfo->users[j +1].admin;
userinfo->users[j].date=userinfo->users[j +1].date;
userinfo->users[j +1].name=temp->name;
userinfo->users[j +1].score=temp->score;
userinfo->users[j +1].pass=temp->pass;
userinfo->users[j +1].admin=temp->admin;
userinfo->users[j +1].date=temp->date;
}
updateModel ();
qDebug()<<" S D ";
}
updateModel ();
}else
if(Fild == "Date" && IDFild == "Descending")
m_model->sort (5,Qt::DescendingOrder);
else
if(Fild == "Date" && IDFild == "Ascending")
m_model->sort (5,Qt::AscendingOrder);
}
void ExposeClass::deleteUser(QString name)
{
for (int i = 0;i<(userinfo->numberOfUsers);i++)
{
if(userinfo->users[i].name==name)
{
qDebug()<<i;
userinfo->deluser (i);
}
}
updateModel ();
}
void ExposeClass::adddata(QString name , QString score, QString pass, QString admin, QString date)
{
QStandardItem *item = new QStandardItem;
// Here we give the data to the item
item->setData ("0",Score1Role);
item->setData (score,ScoreRole);
item->setData(pass, PassRole);
item->setData(date, DateRole);
item->setData(admin, AdminRole);
item->setData(name, NameRole);
userinfo->AddUser (name,score,pass,admin,date);
userinfo->update ();
//here we add the item to the model
m_model->appendRow(item);
}
QString ExposeClass::fild()
{
return Fild;
}
void ExposeClass::setFild(QString value)
{
Fild=value;
emit fildChanged();
updateSort();
}
QString ExposeClass::idFild()
{
return IDFild;
}
void ExposeClass::setIdFild(QString value)
{
IDFild=value;
updateSort();
emit idFildChanged ();
}