-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadduser.cpp
102 lines (82 loc) · 2.73 KB
/
adduser.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
#include <QtGui>
#include "adduser.h"
AddUser::AddUser(QWidget *parent)
: QWidget(parent)
{
setupModel();
nameLabel = new QLabel(tr("&Name:"));
nameEdit = new QLineEdit();
roomLabel = new QLabel(tr("&Room:"));
roomEdit = new QLineEdit();
codeLabel = new QLabel(tr("&Acces code:"));
codeEdit = new QLineEdit();
saveButton = new QPushButton(tr("&Save"));
cancelButton = new QPushButton(tr("&Cancel"));
nameLabel->setBuddy(nameEdit);
roomLabel->setBuddy(roomEdit);
codeLabel->setBuddy(codeEdit);
//! [Set up widgets]
//! [Set up the mapper]
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(nameEdit, 0);
mapper->addMapping(roomEdit, 1);
mapper->addMapping(codeEdit, 2);
// connect(nextButton, SIGNAL(clicked()),
// mapper, SLOT(toNext()));
// connect(mapper, SIGNAL(currentIndexChanged(int)),
// this, SLOT(updateButtons(int)));
connect(saveButton, SIGNAL(clicked()),
this, SLOT(saveEntry()));
connect(cancelButton, SIGNAL(clicked()),
this, SLOT(close()));
//! [Set up the mapper]
//! [Set up the layout]
QGridLayout *layout = new QGridLayout();
layout->addWidget(nameLabel, 0, 0, 1, 1);
layout->addWidget(nameEdit, 0, 1, 1, 1);
layout->addWidget(roomLabel, 1, 0, 1, 1);
layout->addWidget(roomEdit, 1, 1, 1, 1);
layout->addWidget(codeLabel, 2, 0, 1, 1);
layout->addWidget(codeEdit, 2, 1, 2, 1);
layout->addWidget(saveButton, 0, 2, 1, 1);
layout->addWidget(cancelButton, 0, 2, 0, 1);
setLayout(layout);
setWindowTitle(tr("Adding user"));
mapper->toFirst();
}
//! [Set up the layout]
//! [Set up the model]
void AddUser::saveEntry(){
addUserToUsers(nameEdit->text(), roomEdit->text(), codeEdit->text());
cout << "-- Added new user: \n";
cout << "name: " << nameEdit->text().toStdString() << "\n";
cout << "room: " << roomEdit->text().toStdString() << "\n";
cout << "code: " << codeEdit->text().toStdString() << "\n";
cout << "-----------------------------\n";
close();
}
void AddUser::setupModel()
{
model = new QStandardItemModel(1, 4, this);
QStringList names;
names << "";
QStringList rooms;
rooms << "";
QStringList codes;
codes<< "";
QStandardItem *item = new QStandardItem(names[0]);
model->setItem(0, 0, item);
item = new QStandardItem(rooms[0]);
model->setItem(0, 1, item);
item = new QStandardItem(codes[0]);
model->setItem(0, 2, item);
}
//! [Set up the model]
//! [Slot for updating the buttons]
//void AddUser::updateButtons(int row)
//{
// previousButton->setEnabled(row > 0);
// nextButton->setEnabled(row < model->rowCount() - 1);
//}
//! [Slot for updating the buttons]