Add fully-functional administration panel for administrators and dispatchers
This commit is contained in:
parent
bf599549ea
commit
ff6901e3a9
22 changed files with 1257 additions and 42 deletions
64
iFacility/viewmodels/administrationviewmodel.cpp
Normal file
64
iFacility/viewmodels/administrationviewmodel.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include "administrationviewmodel.h"
|
||||
|
||||
AdministrationViewModel::AdministrationViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
|
||||
int AdministrationViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||
return mUserData.length();
|
||||
}
|
||||
|
||||
int AdministrationViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant AdministrationViewModel::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("Full name");
|
||||
case 3:
|
||||
return QString("Status");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant AdministrationViewModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
auto usr = mUserData[index.row()];
|
||||
|
||||
int col = index.column();
|
||||
switch (col) {
|
||||
case 0:
|
||||
return usr.uID();
|
||||
case 1:
|
||||
return usr.getLogin();
|
||||
case 2:
|
||||
return usr.getFullName();
|
||||
case 3:
|
||||
return usr.getUserType() == UserType::ADMINISTRATOR? "Administrator" : "Dispatcher";
|
||||
}
|
||||
|
||||
return "UNKNOWN FIELD";
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void AdministrationViewModel::invalidateData() {
|
||||
beginResetModel();
|
||||
mUserData.clear();
|
||||
foreach (auto u, Database::instance()->getUsersByType(UserType::ADMINISTRATOR)) {
|
||||
mUserData += *u;
|
||||
}
|
||||
foreach (auto u, Database::instance()->getUsersByType(UserType::DISPATCHER)) {
|
||||
mUserData += *u;
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
27
iFacility/viewmodels/administrationviewmodel.h
Normal file
27
iFacility/viewmodels/administrationviewmodel.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef ADMINISTRATIONVIEWMODEL_H
|
||||
#define ADMINISTRATIONVIEWMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QVector>
|
||||
|
||||
#include "../objects/user.h"
|
||||
#include "../db/database.h"
|
||||
|
||||
class AdministrationViewModel : public QAbstractTableModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
QVector<User> mUserData;
|
||||
|
||||
public:
|
||||
AdministrationViewModel(QObject *parent);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
void invalidateData();
|
||||
};
|
||||
|
||||
#endif // ADMINISTRATIONVIEWMODEL_H
|
||||
46
iFacility/viewmodels/professionsviewmodel.cpp
Normal file
46
iFacility/viewmodels/professionsviewmodel.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "professionsviewmodel.h"
|
||||
|
||||
ProfessionsViewModel::ProfessionsViewModel(QObject *parent) : QStandardItemModel(parent) {
|
||||
|
||||
}
|
||||
|
||||
void ProfessionsViewModel::invalidateData() {
|
||||
beginResetModel();
|
||||
|
||||
clear();
|
||||
QStandardItemModel::setHeaderData(0, Qt::Orientation::Horizontal, "Professions");
|
||||
QStandardItem *rootNode = invisibleRootItem();
|
||||
foreach (auto prof, Database::instance()->professions()) {
|
||||
QStandardItem *profNode = new QStandardItem("Profession: " + prof.title());
|
||||
QStandardItem *profUID = new QStandardItem("PID: " + prof.pID().toString());
|
||||
QStandardItem *currentWorkers = new QStandardItem("Current workers");
|
||||
QStandardItem *availableWorkers = new QStandardItem("Available workers");
|
||||
foreach(auto worker, Database::instance()->getUsersByProfession(prof.pID())) {
|
||||
QStandardItem *workerNode = new QStandardItem(worker->getFullNameShortForm());
|
||||
UserProfession up;
|
||||
foreach (auto uProf, worker->getProfessions()) {
|
||||
if (uProf.getProfession() == prof.pID()) {
|
||||
up = uProf;
|
||||
}
|
||||
}
|
||||
QStandardItem *workerRank = new QStandardItem(tr("%1 rank").arg(up.getRank()));
|
||||
QStandardItem *acqDateNode = new QStandardItem(
|
||||
up.getAcquiredDate().toString(Qt::DateFormat::SystemLocaleShortDate));
|
||||
workerNode->appendRow(workerRank);
|
||||
workerNode->appendRow(acqDateNode);
|
||||
if (worker->getCurrentProfession() == prof.pID()) {
|
||||
currentWorkers->appendRow(workerNode);
|
||||
}
|
||||
else {
|
||||
availableWorkers->appendRow(workerNode);
|
||||
}
|
||||
}
|
||||
|
||||
profNode->appendRow(profUID);
|
||||
profNode->appendRow(currentWorkers);
|
||||
profNode->appendRow(availableWorkers);
|
||||
rootNode->appendRow(profNode);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
18
iFacility/viewmodels/professionsviewmodel.h
Normal file
18
iFacility/viewmodels/professionsviewmodel.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PROFESSIONSVIEMODEL_H
|
||||
#define PROFESSIONSVIEMODEL_H
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#include "../db/database.h"
|
||||
|
||||
class ProfessionsViewModel : public QStandardItemModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProfessionsViewModel(QObject *parent);
|
||||
|
||||
void invalidateData();
|
||||
};
|
||||
|
||||
#endif // PROFESSIONSVIEMODEL_H
|
||||
|
|
@ -5,7 +5,7 @@ UserProfessionViewModel::UserProfessionViewModel(QObject *parent) : QAbstractTab
|
|||
}
|
||||
|
||||
int UserProfessionViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||
return mProfList.length();
|
||||
return mUser != nullptr? mUser->getProfessions().length() : 0;
|
||||
}
|
||||
|
||||
int UserProfessionViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||
|
|
@ -16,41 +16,53 @@ QVariant UserProfessionViewModel::headerData(int section,
|
|||
Qt::Orientation orientation, int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return QString("Profession");
|
||||
case 1:
|
||||
return QString("Date of acquirement");
|
||||
case 2:
|
||||
return QString("Rank");
|
||||
case 0:
|
||||
return QString("Profession");
|
||||
case 1:
|
||||
return QString("Date of acquirement");
|
||||
case 2:
|
||||
return QString("Rank");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant UserProfessionViewModel::data(const QModelIndex &index, int role) const {
|
||||
auto profs = mUser->getProfessions();
|
||||
auto uProf = profs[index.row()];
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
auto item = mProfList[index.row()];
|
||||
auto prof = Database::instance()->getProfession(item.getProfession());
|
||||
auto prof = Database::instance()->getProfession(uProf.getProfession());
|
||||
|
||||
int col = index.column();
|
||||
switch (col) {
|
||||
case 0:
|
||||
return prof == nullptr? "ERROR:UNKNOWN" : prof->title();
|
||||
case 1:
|
||||
return item.getAcquiredDate();
|
||||
case 2:
|
||||
return item.getRank();
|
||||
case 0:
|
||||
return prof == nullptr? "#ERROR!" : prof->title();
|
||||
case 1:
|
||||
return uProf.getAcquiredDate().toString(Qt::DateFormat::SystemLocaleShortDate);
|
||||
case 2:
|
||||
return uProf.getRank();
|
||||
}
|
||||
|
||||
return "UNKNOWN FIELD";
|
||||
}
|
||||
else if (role == Qt::FontRole) {
|
||||
if (uProf.getProfession() == mUser->getCurrentProfession()) {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UserProfessionViewModel::setProfessionsList(const ProfessionsList &profList) {
|
||||
void UserProfessionViewModel::setUser(User *user) {
|
||||
mUser = user;
|
||||
invalidateData();
|
||||
}
|
||||
|
||||
void UserProfessionViewModel::invalidateData() {
|
||||
beginResetModel();
|
||||
mProfList.clear();
|
||||
mProfList += profList;
|
||||
endResetModel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define USERPROFESSIONVIEWMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QFont>
|
||||
|
||||
#include "../objects/user.h"
|
||||
#include "../db/database.h"
|
||||
|
|
@ -10,16 +11,18 @@ class UserProfessionViewModel : public QAbstractTableModel {
|
|||
private:
|
||||
Q_OBJECT
|
||||
|
||||
ProfessionsList mProfList;
|
||||
User *mUser = nullptr;
|
||||
|
||||
public:
|
||||
UserProfessionViewModel(QObject *parent);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
void setProfessionsList(const ProfessionsList &profList);
|
||||
void setUser(User *user);
|
||||
void invalidateData();
|
||||
};
|
||||
|
||||
#endif // USERPROFESSIONVIEWMODEL_H
|
||||
|
|
|
|||
103
iFacility/viewmodels/workersviewmodel.cpp
Normal file
103
iFacility/viewmodels/workersviewmodel.cpp
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include "workersviewmodel.h"
|
||||
|
||||
WorkersViewModel::WorkersViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
|
||||
int WorkersViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||
return mUserData.length();
|
||||
}
|
||||
|
||||
int WorkersViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||
return 7;
|
||||
}
|
||||
|
||||
QVariant WorkersViewModel::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("Full name");
|
||||
case 3:
|
||||
return QString("First profession");
|
||||
case 4:
|
||||
return QString("Second profession");
|
||||
case 5:
|
||||
return QString("Third profession");
|
||||
case 6:
|
||||
return QString("Fourth profession");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QString WorkersViewModel::getProfessionAt(const User &user, int pIdx) const {
|
||||
auto profs = user.getProfessions();
|
||||
QString out = "";
|
||||
if (profs.size() >= pIdx + 1) {
|
||||
auto p = Database::instance()->getProfession(profs[pIdx].getProfession());
|
||||
out = tr("%1 (%2 rank)").arg(p->title()).arg(profs[pIdx].getRank());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool WorkersViewModel::shouldBeBold(const QModelIndex &index) const {
|
||||
int col = index.column();
|
||||
if (col < 3) {
|
||||
return false;
|
||||
}
|
||||
auto usr = mUserData[index.row()];
|
||||
if (!getProfessionAt(usr, col-3).isEmpty()) {
|
||||
if (usr.getProfessions()[col-3].getProfession() == usr.getCurrentProfession()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant WorkersViewModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
auto usr = mUserData[index.row()];
|
||||
auto profs = usr.getProfessions();
|
||||
|
||||
int col = index.column();
|
||||
switch (col) {
|
||||
case 0:
|
||||
return usr.uID();
|
||||
case 1:
|
||||
return usr.getLogin();
|
||||
case 2:
|
||||
return usr.getFullName();
|
||||
case 3:
|
||||
return getProfessionAt(usr, 0);
|
||||
case 4:
|
||||
return getProfessionAt(usr, 1);
|
||||
case 5:
|
||||
return getProfessionAt(usr, 2);
|
||||
case 6:
|
||||
return getProfessionAt(usr, 3);
|
||||
}
|
||||
|
||||
return "UNKNOWN FIELD";
|
||||
}
|
||||
else if (role == Qt::FontRole) {
|
||||
if (shouldBeBold(index)) {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void WorkersViewModel::invalidateData() {
|
||||
beginResetModel();
|
||||
mUserData.clear();
|
||||
foreach (auto u, Database::instance()->getUsersByType(UserType::WORKER)) {
|
||||
mUserData += *u;
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
33
iFacility/viewmodels/workersviewmodel.h
Normal file
33
iFacility/viewmodels/workersviewmodel.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef WORKERSVIEWMODEL_H
|
||||
#define WORKERSVIEWMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QVector>
|
||||
|
||||
#include "../objects/user.h"
|
||||
#include "../db/database.h"
|
||||
|
||||
class WorkersViewModel : public QAbstractTableModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
QVector<User> mUserData;
|
||||
|
||||
QString getProfessionAt(const User &user, int pIdx) const;
|
||||
bool shouldBeBold(const QModelIndex &index) const;
|
||||
|
||||
public:
|
||||
WorkersViewModel(QObject *parent);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
void invalidateData();
|
||||
};
|
||||
|
||||
#endif // WORKERSVIEWMODEL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue