-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnewcustomerdialog.cpp
More file actions
128 lines (119 loc) · 4.26 KB
/
newcustomerdialog.cpp
File metadata and controls
128 lines (119 loc) · 4.26 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
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
#include "newcustomerdialog.h"
#include "ui_newcustomerdialog.h"
#include <QRegExp>
#include <QRegExpValidator>
#include <QDebug>
#include <QDate>
NewCustomerDialog::NewCustomerDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewCustomerDialog)
{
ui->setupUi(this);
//Sets Birthday date to current Date
this->ui->birthday_dateEdit->setDate(QDate::currentDate());
//Removes "What's it?" button
this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
///Sets Email Validator Connection
QObject::connect(this->ui->email_lineEdit_4,SIGNAL(textEdited(QString)),this,SLOT(validateEmail(QString)));
//Sets Name Validator Connection
QObject::connect(this->ui->name_lineEdit,SIGNAL(textEdited(QString)),this,SLOT(validateName(QString)));
//Sets Phone Validator
QObject::connect(this->ui->phone1_lineEdit_2,SIGNAL(textEdited(QString)),this,SLOT(validatePhone(QString)));
QObject::connect(this->ui->phone2_lineEdit_3,SIGNAL(textEdited(QString)),this,SLOT(validatePhone2(QString)));
//Sets City Validator
QObject::connect(this->ui->city_lineEdit_7,SIGNAL(textChanged(QString)),this,SLOT(validateCity(QString)));
//Sets Address Validator
QObject::connect(this->ui->address_lineEdit_5,SIGNAL(textChanged(QString)),this,SLOT(validateAddress(QString)));
//Disables Ok flags for default
nameOK=false;
emailOK=false;
cityOK=false;
phoneOK=false;
phone2OK=true;
addressOK = false;
validationFinished();
}
NewCustomerDialog::~NewCustomerDialog()
{
delete ui;
}
void NewCustomerDialog::validateEmail(QString text){
QRegExp mailREX("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b");
mailREX.setCaseSensitivity(Qt::CaseInsensitive);
mailREX.setPatternSyntax(QRegExp::RegExp);
QRegExpValidator *validator = new QRegExpValidator(mailREX,0);
int pos=0;
if(validator->validate(text,pos)==QValidator::Invalid){
this->ui->email_lineEdit_4->setStyleSheet("color: red");
emailOK = false;
}
if(validator->validate(text,pos)==QValidator::Intermediate){
this->ui->email_lineEdit_4->setStyleSheet("color: orange");
emailOK = false;
}
if(validator->validate(text,pos)==QValidator::Acceptable){
this->ui->email_lineEdit_4->setStyleSheet("color: green");
emailOK = true;
}
validationFinished();
}
void NewCustomerDialog::validateName(QString text){
if(text.length()<5 || text.length()>100){
this->ui->name_lineEdit->setStyleSheet("color: red");
nameOK=false;
}else{
this->ui->name_lineEdit->setStyleSheet("color: green");
nameOK=true;
}
validationFinished();
}
void NewCustomerDialog::validatePhone(QString text){
//qDebug()<<text;
if(text.length()<12){
this->ui->phone1_lineEdit_2->setStyleSheet("color: red");
phoneOK=false;
}else{
this->ui->phone1_lineEdit_2->setStyleSheet("color: green");
phoneOK=true;
}
validationFinished();
}
void NewCustomerDialog::validatePhone2(QString text){
//qDebug()<<text;
if(text.length()==12 || text.length()==2){
this->ui->phone2_lineEdit_3->setStyleSheet("color: green");
phone2OK=false;
}else{
this->ui->phone2_lineEdit_3->setStyleSheet("color: color");
phone2OK=true;
}
validationFinished();
}
void NewCustomerDialog::validateCity(QString text){
if(text.length()<5 || text.length()>50){
this->ui->city_lineEdit_7->setStyleSheet("color: red");
cityOK=false;
}else{
this->ui->city_lineEdit_7->setStyleSheet("color: green");
cityOK=true;
}
validationFinished();
}
void NewCustomerDialog::validateAddress(QString text){
if(text.length()<15 || text.length()>150){
this->ui->address_lineEdit_5->setStyleSheet("color: red");
addressOK=false;
}else{
this->ui->address_lineEdit_5->setStyleSheet("color: green");
addressOK=true;
}
validationFinished();
}
void NewCustomerDialog::validationFinished(){
if(emailOK && nameOK && phoneOK && cityOK && phone2OK && addressOK){
this->ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
else{
this->ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
}