|
|
|
@ -1,6 +1,11 @@
|
|
|
|
|
#include "userform.h"
|
|
|
|
|
#include "ui_userform.h"
|
|
|
|
|
|
|
|
|
|
#include <QTableWidgetItem>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include "../data/core-data.h"
|
|
|
|
|
#include "../service.h"
|
|
|
|
|
|
|
|
|
|
UserForm::UserForm(QWidget *parent) :
|
|
|
|
|
AutoForm<User>(parent),
|
|
|
|
|
ui(new Ui::UserForm)
|
|
|
|
@ -17,3 +22,37 @@ UserForm::~UserForm()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UserForm::bindOtherToUi()
|
|
|
|
|
{
|
|
|
|
|
Service<Role> srv;
|
|
|
|
|
QList<QSharedPointer<Role> > roles = this->entity()->listRoles();
|
|
|
|
|
ui->tableWidget->setRowCount(srv.all().count());
|
|
|
|
|
ui->tableWidget->setColumnCount(1);
|
|
|
|
|
int i = 0;
|
|
|
|
|
foreach(QSharedPointer<Role> r,srv.all())
|
|
|
|
|
{
|
|
|
|
|
auto it = std::find_if(ALL(roles),[r](QSharedPointer<Role> role){return r->id() == role->id();});
|
|
|
|
|
QTableWidgetItem * ti;
|
|
|
|
|
ti = new QTableWidgetItem;
|
|
|
|
|
ti->setText(r->name());
|
|
|
|
|
ti->setCheckState(it == roles.end() ? Qt::Unchecked : Qt::Checked);
|
|
|
|
|
ti->setData(Qt::UserRole,r->id());
|
|
|
|
|
ui->tableWidget->setItem(i,0,ti);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UserForm::bindOtherToData()
|
|
|
|
|
{
|
|
|
|
|
Service<Role> srv;
|
|
|
|
|
this->entity()->clearRoles();
|
|
|
|
|
for(int i = 0;i < ui->tableWidget->rowCount() ;i++){
|
|
|
|
|
if(ui->tableWidget->item(i,0)->checkState()== Qt::Checked)
|
|
|
|
|
{
|
|
|
|
|
this->entity()->addRole(srv.loadById(ui->tableWidget->item(i,0)->data(Qt::UserRole).toInt()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|