diff --git a/core/autoform.h b/core/autoform.h index 0936ac1..0ad1603 100644 --- a/core/autoform.h +++ b/core/autoform.h @@ -25,8 +25,8 @@ public: virtual ~AutoForm() { foreach (IValidator *val, m_validators) { delete val; - m_validators.clear(); } + m_validators.clear(); } void setEntity(QSharedPointer entity) { diff --git a/core/core.pro b/core/core.pro index 9fe8998..fafd34f 100644 --- a/core/core.pro +++ b/core/core.pro @@ -38,7 +38,8 @@ SOURCES += \ roles/rolesform.cpp \ permissionservice.cpp \ filterui.cpp \ - exprevaluator.cpp + exprevaluator.cpp \ + samestringvalidator.cpp HEADERS += core.h\ core_global.h \ @@ -73,7 +74,8 @@ HEADERS += core.h\ roles/rolesform.h \ permissionservice.h \ filterui.h \ - exprevaluator.h + exprevaluator.h \ + samestringvalidator.h unix { target.path = /usr/lib diff --git a/core/formdialog.cpp b/core/formdialog.cpp index 50a0eb4..731e506 100644 --- a/core/formdialog.cpp +++ b/core/formdialog.cpp @@ -1,5 +1,6 @@ #include "formdialog.h" #include "ui_formdialog.h" +#include FormDialog::FormDialog(QWidget *parent) : QDialog(parent), @@ -21,11 +22,20 @@ void FormDialog::setForm(IForm *formWidget) { ui->verticalLayout->addWidget(formWidget); m_form = formWidget; + connect(m_form, SIGNAL(validationError(QString)), this, SLOT(onValidationError(QString))); setGeometry(formWidget->geometry()); } } -void FormDialog::on_buttonBox_accepted() +void FormDialog::onValidationError(const QString &message) { - m_form->saveRecord(); + QMessageBox::critical(this, tr("Validation error"), tr(message.toStdString().c_str())); +} + +void FormDialog::accept() +{ + if (m_form->saveRecord()) + { + QDialog::accept(); + } } diff --git a/core/formdialog.h b/core/formdialog.h index ac45614..2cdf9b4 100644 --- a/core/formdialog.h +++ b/core/formdialog.h @@ -20,13 +20,17 @@ public: void setForm(IForm *formWidget); -private slots: - void on_buttonBox_accepted(); - private: bool m_formSet; IForm *m_form; Ui::FormDialog *ui; + +private slots: + void onValidationError(const QString &message); + + // QDialog interface +public slots: + void accept(); }; #endif // FORMDIALOG_H diff --git a/core/iform.h b/core/iform.h index 67e5a0c..5bee31f 100644 --- a/core/iform.h +++ b/core/iform.h @@ -16,7 +16,7 @@ public: signals: void recordAdded(); void recordUpdated(); - void validationError(QString errMessage); + void validationError(const QString &errMessage); public slots: virtual bool saveRecord() = 0; diff --git a/core/samestringvalidator.cpp b/core/samestringvalidator.cpp new file mode 100644 index 0000000..718f3fe --- /dev/null +++ b/core/samestringvalidator.cpp @@ -0,0 +1,21 @@ +#include "samestringvalidator.h" +#include + +SameStringValidator::SameStringValidator(QWidget *widget_1, QWidget * widget_2, const QString & errorMessage) + :IValidator(widget_1,errorMessage) +{ + m_widget_2 = widget_2; +} + +bool SameStringValidator::validate() +{ + QString data = m_widget->property(m_widget->metaObject()->userProperty().name()).toString(); + QString data_2 = m_widget_2->property(m_widget_2->metaObject()->userProperty().name()).toString(); + if (data != data_2) + { + m_widget->setFocus(); + return false; + } + + return true; +} diff --git a/core/samestringvalidator.h b/core/samestringvalidator.h new file mode 100644 index 0000000..699b828 --- /dev/null +++ b/core/samestringvalidator.h @@ -0,0 +1,15 @@ +#ifndef SAMESTRINGVALIDATOR_H +#define SAMESTRINGVALIDATOR_H +#include "ivalidator.h" +#include "core_global.h" + +class CORESHARED_EXPORT SameStringValidator : public IValidator +{ +public: + SameStringValidator(QWidget * widget_1, QWidget *widget_2, const QString &errorMessage); + bool validate(); +private: +QWidget * m_widget_2; +}; + +#endif // SAMESTRINGVALIDATOR_H diff --git a/core/users/userform.cpp b/core/users/userform.cpp index 199afff..9394593 100644 --- a/core/users/userform.cpp +++ b/core/users/userform.cpp @@ -5,6 +5,8 @@ #include #include "../data/core-data.h" #include "../service.h" +#include "../emptystringvalidator.h" +#include "../samestringvalidator.h" UserForm::UserForm(QWidget *parent) : AutoForm(parent), @@ -16,6 +18,15 @@ UserForm::UserForm(QWidget *parent) : registerBinding(ui->name); registerBinding(ui->isAdmin); registerBinding(ui->active); + EmptyStringValidator * esv_login = new EmptyStringValidator(ui->login,"Enter Login Name"); + registerValidator(esv_login); + EmptyStringValidator * esv_password = new EmptyStringValidator(ui->password,"Enter Password"); + registerValidator(esv_password); + EmptyStringValidator * esv_name = new EmptyStringValidator(ui->name,"Enter Name"); + registerValidator(esv_name); + SameStringValidator * ssv_password = new SameStringValidator(ui->password,ui->retypePassword,"Passwords doesen't match"); + registerValidator(ssv_password); + } UserForm::~UserForm() @@ -25,6 +36,8 @@ UserForm::~UserForm() void UserForm::bindOtherToUi() { + ui->retypePassword->setText(this->entity()->password()); + Service srv; QList > roles = this->entity()->listRoles(); ui->tableWidget->setRowCount(srv.all().count()); diff --git a/core/users/userform.ui b/core/users/userform.ui index 8e74725..f5b635d 100644 --- a/core/users/userform.ui +++ b/core/users/userform.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 458 + 301 @@ -32,19 +32,23 @@ - + + + QLineEdit::Password + + - + Name - + - + Qt::RightToLeft @@ -54,7 +58,7 @@ - + Qt::RightToLeft @@ -64,18 +68,41 @@ - + - + Roles + + + + QLineEdit::Password + + + + + + + Retype Password + + + + + login + password + retypePassword + name + tableWidget + isAdmin + active +