Added new validator, userform validation
This commit is contained in:
+1
-1
@@ -25,8 +25,8 @@ public:
|
||||
virtual ~AutoForm() {
|
||||
foreach (IValidator *val, m_validators) {
|
||||
delete val;
|
||||
m_validators.clear();
|
||||
}
|
||||
m_validators.clear();
|
||||
}
|
||||
|
||||
void setEntity(QSharedPointer<T> entity) {
|
||||
|
||||
+4
-2
@@ -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
|
||||
|
||||
+12
-2
@@ -1,5 +1,6 @@
|
||||
#include "formdialog.h"
|
||||
#include "ui_formdialog.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -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
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "samestringvalidator.h"
|
||||
#include <QMetaProperty>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <QHeaderView>
|
||||
#include "../data/core-data.h"
|
||||
#include "../service.h"
|
||||
#include "../emptystringvalidator.h"
|
||||
#include "../samestringvalidator.h"
|
||||
|
||||
UserForm::UserForm(QWidget *parent) :
|
||||
AutoForm<User>(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<Role> srv;
|
||||
QList<QSharedPointer<Role> > roles = this->entity()->listRoles();
|
||||
ui->tableWidget->setRowCount(srv.all().count());
|
||||
|
||||
+36
-9
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>458</width>
|
||||
<height>301</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -32,19 +32,23 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="password"/>
|
||||
<widget class="QLineEdit" name="password">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="name"/>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="isAdmin">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
@@ -54,7 +58,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="active">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
@@ -64,18 +68,41 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QTableWidget" name="tableWidget"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Roles</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="retypePassword">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Retype Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>login</tabstop>
|
||||
<tabstop>password</tabstop>
|
||||
<tabstop>retypePassword</tabstop>
|
||||
<tabstop>name</tabstop>
|
||||
<tabstop>tableWidget</tabstop>
|
||||
<tabstop>isAdmin</tabstop>
|
||||
<tabstop>active</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user