Repository navigation
Expand file tree
/
Copy patheditform.cpp
More file actions
61 lines (49 loc) · 2.33 KB
/
Copy patheditform.cpp
File metadata and controls
61 lines (49 loc) · 2.33 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
#include "editform.h"
#include <QMessageBox>
#include <QProgressBar>
EditForm::EditForm(QVector<UserProfile> &profiles, int index, QWidget *parent)
: QWidget(parent), profilesEdit(profiles), profileIndex(index) {
QVBoxLayout *layout = new QVBoxLayout(this);
editForm = new ProfileForm(this);
editForm->setProfile(profiles[index]);
QPushButton *saveButton = new QPushButton("Save Changes", this);
QPushButton *backButton = new QPushButton("Back", this);
QPushButton *deleteButton = new QPushButton("Delete Profile", this);
deleteButton->setStyleSheet("background-color: #ff4444; color: white;");
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(backButton);
buttonLayout->addWidget(deleteButton);
buttonLayout->addWidget(saveButton);
layout->addWidget(editForm);
layout->addLayout(buttonLayout);
connect(saveButton, &QPushButton::clicked, [this]() {
int temp_cuser = profilesEdit[profileIndex].cuser;
profilesEdit[profileIndex] = editForm->getProfile();
profilesEdit[profileIndex].cuser = temp_cuser;
emit profileEdited();
});
connect(deleteButton, &QPushButton::clicked, [this]() {
if(profilesEdit.size() == 1 && profilesEdit[profileIndex].cuser == 1){
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Confirm Delete",
"This is the last profile in the list, are you sure you want to delete this profile?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
profilesEdit.remove(profileIndex);
emit lastprofileDeleted();
}
} else if(profilesEdit[profileIndex].cuser == 1){
QMessageBox::warning(this, "Error", "This is the current user profile, switch to other profiles to delete");
} else {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Confirm Delete",
"Are you sure you want to delete this profile?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
profilesEdit.remove(profileIndex);
emit profileDeleted();
}
}
});
connect(backButton, &QPushButton::clicked, this, &EditForm::profileEdited);
}