-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpeopledialog.cpp
More file actions
72 lines (49 loc) · 1.72 KB
/
peopledialog.cpp
File metadata and controls
72 lines (49 loc) · 1.72 KB
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
#include "peopledialog.h"
#include "ui_peopledialog.h"
#include <QPushButton>
#include <QVBoxLayout>
PeopleDialog::PeopleDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PeopleDialog)
{
ui->setupUi(this);
}
PeopleDialog::~PeopleDialog()
{
delete ui;
}
void PeopleDialog::setActions() {
QObject::connect( ui -> addAsFriendBtn, SIGNAL( clicked() ), this, SLOT( addFriends()) );
}
void PeopleDialog::recievedData(int user_id) {
this->user_id = user_id;
}
bool PeopleDialog::addFriends() {
QList<QListWidgetItem *> selectedPeople = ui -> findedPeopleList -> selectedItems();
int i = 0;
QSqlQuery query;
QStringList stringlist;
if ( MainWindow::getInstance() -> isConnectedToDB() ) {
for (; i < selectedPeople.count(); ++i) {
stringlist = selectedPeople.at(i) -> text().split(" ");
query.prepare("INSERT INTO user_friends(user_id, f_fname, f_lname) VALUES(:user_id, :f_fname, :f_lname)");
query.bindValue(":user_id", this -> user_id );
query.bindValue(":f_fname", stringlist.at(0));
query.bindValue(":f_lname", stringlist.at(1));
if ( !query.exec() ) {
qDebug() << query.lastError().text();
}
}
//MainWindow::getInstance() -> closeDBConnection();
return true;
}
return false;
}
void PeopleDialog::loadPeopleList(QHash<QString, QString> & peopleList) {
int j = 0;
QHash<QString, QString>::iterator i;
for (i = peopleList.begin(); i != peopleList.end(); ++i, j++) {
ui -> findedPeopleList -> addItem( peopleList.value("FullFriendName"+j) );
}
ui -> findedPeopleList -> setSelectionMode(QAbstractItemView::ExtendedSelection);
}