base viewmodel and interactions
This commit is contained in:
parent
50aa95e659
commit
d69b18f083
14 changed files with 228 additions and 77 deletions
65
sea_transport/viewmodels/usersviewmodel.cpp
Normal file
65
sea_transport/viewmodels/usersviewmodel.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include "usersviewmodel.h"
|
||||
|
||||
UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
|
||||
int UsersViewModel::rowCount(const QModelIndex & /*parent*/) const {
|
||||
return apparatus::instance()->get_object_subsystem().vessels().size();
|
||||
}
|
||||
|
||||
int UsersViewModel::columnCount(const QModelIndex & /*parent*/) const {
|
||||
return 3;
|
||||
}
|
||||
|
||||
QVariant UsersViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return QString("UID");
|
||||
case 1:
|
||||
return QString("Login");
|
||||
case 2:
|
||||
return QString("Role");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant UsersViewModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
auto item = apparatus::instance()->get_auth_subsystem().users()[index.row()];
|
||||
int col = index.column();
|
||||
|
||||
switch (col) {
|
||||
case 0:
|
||||
return QString::number(item.id());
|
||||
case 1:
|
||||
return item.login();
|
||||
case 2:
|
||||
QString role = "unknown";
|
||||
|
||||
switch(item.role()) {
|
||||
case UserRole::ADMINISTRATOR:
|
||||
role = "Administrator";
|
||||
break;
|
||||
case UserRole::DISPATCHER:
|
||||
role = "Dispatcher";
|
||||
break;
|
||||
case UserRole::SKIPPER:
|
||||
role = "Skipper";
|
||||
break;
|
||||
}
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
return "UNKNOWN FIELD";
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UsersViewModel::update() {
|
||||
this->resetInternalData();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue