Mercurial > hg > syntilista
comparison src/main.cpp @ 121:404d567edaab
Validate the length of extra info field in the add/edit person dialog.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 06 Jul 2017 10:53:07 +0300 |
parents | 2ff2ad720474 |
children | f0db8267911b |
comparison
equal
deleted
inserted
replaced
120:2ff2ad720474 | 121:404d567edaab |
---|---|
1093 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | 1093 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
1094 | 1094 |
1095 ui->edit_FirstName->setMaxLength(SQL_MAX_FIRST_NAME); | 1095 ui->edit_FirstName->setMaxLength(SQL_MAX_FIRST_NAME); |
1096 ui->edit_LastName->setMaxLength(SQL_MAX_LAST_NAME); | 1096 ui->edit_LastName->setMaxLength(SQL_MAX_LAST_NAME); |
1097 | 1097 |
1098 connect( | |
1099 ui->textedit_ExtraInfo, | |
1100 SIGNAL(textChanged()), | |
1101 this, | |
1102 SLOT(on_textedit_ExtraInfo_textChanged())); | |
1103 | |
1098 validateForm(); | 1104 validateForm(); |
1099 } | 1105 } |
1100 | 1106 |
1101 | 1107 |
1102 EditPerson::~EditPerson() | 1108 EditPerson::~EditPerson() |
1115 bool EditPerson::validateForm() | 1121 bool EditPerson::validateForm() |
1116 { | 1122 { |
1117 selPerson.firstName = slCleanupStr(ui->edit_FirstName->text()); | 1123 selPerson.firstName = slCleanupStr(ui->edit_FirstName->text()); |
1118 selPerson.lastName = slCleanupStr(ui->edit_LastName->text()); | 1124 selPerson.lastName = slCleanupStr(ui->edit_LastName->text()); |
1119 selPerson.extraInfo = ui->textedit_ExtraInfo->document()->toPlainText(); | 1125 selPerson.extraInfo = ui->textedit_ExtraInfo->document()->toPlainText(); |
1120 | 1126 bool extraInfoValid = selPerson.extraInfo.length() < SQL_MAX_EXTRA_INFO; |
1127 | |
1128 ui->textedit_ExtraInfo->setStyleSheet(!extraInfoValid ? "background-color: red;" : NULL); | |
1121 ui->edit_FirstName->setStyleSheet(selPerson.firstName == "" ? "background-color: red;" : NULL); | 1129 ui->edit_FirstName->setStyleSheet(selPerson.firstName == "" ? "background-color: red;" : NULL); |
1122 ui->edit_LastName->setStyleSheet(selPerson.lastName == "" ? "background-color: red;" : NULL); | 1130 ui->edit_LastName->setStyleSheet(selPerson.lastName == "" ? "background-color: red;" : NULL); |
1123 | 1131 |
1124 return selPerson.firstName != "" && selPerson.lastName != ""; | 1132 return selPerson.firstName != "" && selPerson.lastName != "" && extraInfoValid; |
1125 } | 1133 } |
1126 | 1134 |
1127 | 1135 |
1128 void EditPerson::on_button_Cancel_clicked() | 1136 void EditPerson::on_button_Cancel_clicked() |
1129 { | 1137 { |
1135 { | 1143 { |
1136 if (!validateForm()) | 1144 if (!validateForm()) |
1137 { | 1145 { |
1138 slErrorMsg( | 1146 slErrorMsg( |
1139 tr("Virhe!"), | 1147 tr("Virhe!"), |
1140 tr("Vaaditut kentät (etunimi, sukunimi) eivät ole täytetty.")); | 1148 tr("Vaaditut kentät (etunimi, sukunimi) eivät ole täytetty tai lisätietojen pituus on liian suuri.")); |
1141 | 1149 |
1142 return; | 1150 return; |
1143 } | 1151 } |
1144 | 1152 |
1145 if (selPerson.id >= 0) | 1153 if (selPerson.id >= 0) |
1219 | 1227 |
1220 | 1228 |
1221 void EditPerson::on_edit_LastName_textChanged(const QString &arg1) | 1229 void EditPerson::on_edit_LastName_textChanged(const QString &arg1) |
1222 { | 1230 { |
1223 (void) arg1; | 1231 (void) arg1; |
1232 validateForm(); | |
1233 } | |
1234 | |
1235 | |
1236 void EditPerson::on_textedit_ExtraInfo_textChanged() | |
1237 { | |
1224 validateForm(); | 1238 validateForm(); |
1225 } | 1239 } |
1226 | 1240 |
1227 | 1241 |
1228 void EditPerson::clearForm() | 1242 void EditPerson::clearForm() |