-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNameDialog.cpp
More file actions
60 lines (48 loc) · 1.21 KB
/
Copy pathAddNameDialog.cpp
File metadata and controls
60 lines (48 loc) · 1.21 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
#include "AddNameDialog.h"
#include "Common.h"
AddNameDialog::AddNameDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
AddNameDialog::~AddNameDialog()
{
}
void AddNameDialog::on_firstNameEdit_textEdited(const QString& text)
{
first = text;
if ((first != "") && (last != "")) {
ui.okAddName->setEnabled(true);
}
else {
ui.okAddName->setEnabled(false);
}
}
void AddNameDialog::on_lastNameEdit_textEdited(const QString& text)
{
last = text;
if ((first != "") && (last != "")) {
ui.okAddName->setEnabled(true);
}
else {
ui.okAddName->setEnabled(false);
}
}
void AddNameDialog::on_okAddName_clicked() {
if ((first.contains(',')) ||
(last.contains(','))) {
QMessageBox::warning(this, "", "The names can not contain spaces or commas.");
return;
}
QFile file(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + "Volunteers.csv");
if(!openFile(&file, this, QFile::ReadWrite | QFile::Text | QFile::ExistingOnly)) return;
QTextStream out(&file);
QString all = out.readAll();
if (all.contains(last + ',' + first)) {
QMessageBox::information(this, "", "This name already exists.");
return;
}
out << last << ',' << first << "\n";
out.flush();
this->accept();
}