commit
8c9cb25c6f
45 changed files with 1902 additions and 415 deletions
|
|
@ -6,78 +6,298 @@ AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminP
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
||||||
// connect(ui->pb_logout, &QPushButton::clicked, this, &AdminPanel::on_logout_requested);
|
connect(ui->pb_logout, &QPushButton::clicked, this, &AdminPanel::on_logout_requested);
|
||||||
|
|
||||||
// connect(ui->pb_vessels_add, &QPushButton::clicked, this, &AdminPanel::on_vessel_add);
|
connect(ui->pb_vessels_add, &QPushButton::clicked, this, [this](){
|
||||||
// connect(ui->pb_vessels_remove, &QPushButton::clicked, this, &AdminPanel::on_vessel_remove);
|
this->on_vessel_add_edit(false);
|
||||||
|
});
|
||||||
|
connect(ui->pb_vessels_edit, &QPushButton::clicked, this, [this](){
|
||||||
|
this->on_vessel_add_edit(true);
|
||||||
|
});
|
||||||
|
connect(ui->pb_vessels_remove, &QPushButton::clicked, this, &AdminPanel::on_vessel_remove);
|
||||||
|
|
||||||
// connect(ui->pb_users_add, &QPushButton::clicked, this, &AdminPanel::on_user_add);
|
connect(ui->pb_users_add, &QPushButton::clicked, this, [this](){
|
||||||
// connect(ui->pb_users_remove, &QPushButton::clicked, this, &AdminPanel::on_user_remove);
|
this->on_user_add_edit(false);
|
||||||
|
});
|
||||||
|
connect(ui->pb_users_edit, &QPushButton::clicked, this, [this](){
|
||||||
|
this->on_user_add_edit(true);
|
||||||
|
});
|
||||||
|
connect(ui->pb_users_remove, &QPushButton::clicked, this, &AdminPanel::on_user_remove);
|
||||||
|
|
||||||
// connect(ui->pb_users_add, &QPushButton::clicked, this, &AdminPanel::on_storage_add);
|
connect(ui->pb_dp_add, &QPushButton::clicked, this, [this](){
|
||||||
// connect(ui->pb_users_remove, &QPushButton::clicked, this, &AdminPanel::on_storage_remove);
|
this->on_delivery_point_add_edit(false);
|
||||||
|
});
|
||||||
|
connect(ui->pb_dp_edit, &QPushButton::clicked, this, [this](){
|
||||||
|
this->on_delivery_point_add_edit(true);
|
||||||
|
});
|
||||||
|
connect(ui->pb_dp_remove, &QPushButton::clicked, this, &AdminPanel::on_delivery_point_remove);
|
||||||
|
|
||||||
// connect(ui->pb_dp_add, &QPushButton::clicked, this, &AdminPanel::on_delivery_point_add);
|
|
||||||
// connect(ui->pb_dp_remove, &QPushButton::clicked, this, &AdminPanel::on_delivery_point_remove);
|
|
||||||
|
|
||||||
|
|
||||||
// ui->tv_vessels->setModel();
|
|
||||||
|
|
||||||
uvm = new UsersViewModel(this);
|
uvm = new UsersViewModel(this);
|
||||||
ui->tv_users->setModel(uvm);
|
ui->tv_users->setModel(this->uvm);
|
||||||
|
|
||||||
// ui->tv_dp->setModel();
|
vvm = new VesselsViewModel(this);
|
||||||
|
ui->tv_vessels->setModel(vvm);
|
||||||
|
|
||||||
// ui->tv_storages->setModel();
|
dpvm = new DeliveryPointsViewModel(this);
|
||||||
|
ui->tv_dp->setModel(dpvm);
|
||||||
|
|
||||||
|
connect(ui->tv_users->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) {
|
||||||
|
ui->pb_users_remove->setEnabled(selected.length() > 0);
|
||||||
|
ui->pb_users_edit->setEnabled(selected.length() == 1);
|
||||||
|
});
|
||||||
|
|
||||||
uvm->update();
|
connect(ui->tv_vessels->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) {
|
||||||
|
ui->pb_vessels_remove->setEnabled(selected.length() > 0);
|
||||||
|
ui->pb_vessels_edit->setEnabled(selected.length() == 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->tv_dp->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) {
|
||||||
|
ui->pb_dp_remove->setEnabled(selected.length() > 0);
|
||||||
|
ui->pb_dp_edit->setEnabled(selected.length() == 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
ui->tw_tabs->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdminPanel::~AdminPanel() {
|
AdminPanel::~AdminPanel() {
|
||||||
delete ui;
|
delete ui;
|
||||||
|
|
||||||
delete uvm;
|
delete uvm;
|
||||||
|
delete vvm;
|
||||||
|
delete dpvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdminPanel& AdminPanel::set_user(const user_entity &user) {
|
AdminPanel& AdminPanel::set_user(const user_entity &user) {
|
||||||
this->user = user;
|
this->user = user;
|
||||||
ui->lab_user->setText(tr("Hello user %1").arg(user.login()));
|
ui->lab_user->setText(tr("Hello, **%1**").arg(user.login()));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_logout_requested() {
|
void AdminPanel::on_logout_requested() {
|
||||||
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_vessel_add() {
|
void AdminPanel::on_vessel_add_edit(bool edit) {
|
||||||
|
auto selected = ui->tv_vessels->selectionModel()->selectedRows();
|
||||||
|
if (edit && selected.length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apparatus::instance()->get_object_subsystem()->dpoints().isEmpty()) {
|
||||||
|
QMessageBox::critical(this, "Error", "No harbors to assign. At least one required.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int skippers = 0;
|
||||||
|
foreach (auto user, apparatus::instance()->get_auth_subsystem()->users()) {
|
||||||
|
skippers += user.role() == UserRole::SKIPPER;
|
||||||
|
}
|
||||||
|
if (skippers == 0) {
|
||||||
|
QMessageBox::critical(this, "Error", "No skippers to assign. At least one required.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vessel_entity ves;
|
||||||
|
if (edit) {
|
||||||
|
int idx = selected[0].row();
|
||||||
|
ves = apparatus::instance()->get_object_subsystem()->vessels()[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
VesselEditDialog ved(this);
|
||||||
|
ved.setWindowTitle(edit? "Edit vessel" : "New vessel");
|
||||||
|
ved.set_vessel(&ves, edit);
|
||||||
|
if (ved.exec() != UserEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = ved.vessel();
|
||||||
|
if (edit) {
|
||||||
|
apparatus::instance()->get_object_subsystem()->remove_vessel(ves.id());
|
||||||
|
QMessageBox::information(this, "Info", "Vessel edited successfully");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::information(this, "Info", "Vessel created successfully");
|
||||||
|
}
|
||||||
|
apparatus::instance()->get_object_subsystem()->add_vessel(*data);
|
||||||
|
|
||||||
|
vvm->update();
|
||||||
|
dpvm->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_vessel_remove() {
|
void AdminPanel::on_vessel_remove() {
|
||||||
|
auto selected = ui->tv_vessels->selectionModel()->selectedRows();
|
||||||
|
if (selected.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox delConf(this);
|
||||||
|
delConf.setIcon(QMessageBox::Question);
|
||||||
|
delConf.setWindowTitle(tr("Deletion confirmation"));
|
||||||
|
delConf.setText(tr("Are you sure you want to delete these vessels?"));
|
||||||
|
delConf.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
delConf.setDefaultButton(QMessageBox::No);
|
||||||
|
if (delConf.exec() == QMessageBox::No) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto mIdx, selected) {
|
||||||
|
entity_id oid = mIdx.data().toULongLong();
|
||||||
|
apparatus::instance()->get_object_subsystem()->remove_vessel(oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
vvm->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_user_add() {
|
void AdminPanel::on_user_add_edit(bool edit) {
|
||||||
|
auto selected = ui->tv_users->selectionModel()->selectedRows();
|
||||||
|
if (edit && selected.length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user_entity usr;
|
||||||
|
if (edit) {
|
||||||
|
int idx = selected[0].row();
|
||||||
|
usr = apparatus::instance()->get_auth_subsystem()->users()[idx];
|
||||||
|
if (usr.id() == this->user.id()) {
|
||||||
|
QMessageBox::critical(this, "Error", "You cannot edit yourself");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UserEditDialog ued(this);
|
||||||
|
ued.setWindowTitle(edit? "Edit user" : "New user");
|
||||||
|
ued.set_user(&usr, edit);
|
||||||
|
if (ued.exec() != UserEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = ued.user_data();
|
||||||
|
if (edit) {
|
||||||
|
bool success;
|
||||||
|
auto user = apparatus::instance()->get_auth_subsystem()->get_user(usr.login(), success);
|
||||||
|
if (success) {
|
||||||
|
user->set_password(data->password);
|
||||||
|
user->set_role(data->role);
|
||||||
|
QMessageBox::information(this, "Info", "User edited successfully (note: you cannot change login)");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Error while editing user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bool success = apparatus::instance()->get_auth_subsystem()->register_user(data->login, data->password, data->role);
|
||||||
|
if (success) {
|
||||||
|
QMessageBox::information(this, "Info", "User created successfully");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Error while creating user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uvm->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_user_remove() {
|
void AdminPanel::on_user_remove() {
|
||||||
|
auto selected = ui->tv_users->selectionModel()->selectedRows();
|
||||||
|
if (selected.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox delConf(this);
|
||||||
|
delConf.setIcon(QMessageBox::Question);
|
||||||
|
delConf.setWindowTitle(tr("Deletion confirmation"));
|
||||||
|
delConf.setText(tr("Are you sure you want to delete these users?"));
|
||||||
|
delConf.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
delConf.setDefaultButton(QMessageBox::No);
|
||||||
|
if (delConf.exec() == QMessageBox::No) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto _u = apparatus::instance()->get_auth_subsystem()->users();
|
||||||
|
foreach (auto mIdx, selected) {
|
||||||
|
int idx = mIdx.row();
|
||||||
|
auto ent = _u[idx];
|
||||||
|
if (ent.id() == user.id()) {
|
||||||
|
QMessageBox::critical(this, "Error", "You cannot delete yourself!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
apparatus::instance()->get_auth_subsystem()->remove_user(ent.login());
|
||||||
|
}
|
||||||
|
|
||||||
|
uvm->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_storage_add() {
|
void AdminPanel::on_delivery_point_add_edit(bool edit) {
|
||||||
|
auto selected = ui->tv_dp->selectionModel()->selectedRows();
|
||||||
|
if (edit && selected.length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
dpoint_entity dpoint;
|
||||||
|
if (edit) {
|
||||||
|
int idx = selected[0].row();
|
||||||
|
dpoint = apparatus::instance()->get_object_subsystem()->dpoints()[idx];
|
||||||
|
}
|
||||||
|
|
||||||
void AdminPanel::on_storage_remove() {
|
DeliveryPointEditDialog dped(this);
|
||||||
|
dped.setWindowTitle(edit? "Edit delivery point" : "New delivery point");
|
||||||
|
dped.set_dpoint(&dpoint, edit);
|
||||||
|
if (dped.exec() != UserEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
auto data = dped.dpoint();
|
||||||
|
if (edit) {
|
||||||
|
bool success;
|
||||||
|
auto dp = apparatus::instance()->get_object_subsystem()->get_dpoint(dpoint.id(), success);
|
||||||
|
if (success) {
|
||||||
|
QMessageBox::information(this, "Info", "Successfully edited delivery point");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Error editing delivery point");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void AdminPanel::on_delivery_point_add() {
|
dp->set_title(data->title());
|
||||||
|
dp->set_storages(data->storages());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bool success = apparatus::instance()->get_object_subsystem()->add_dpoint(*data);
|
||||||
|
if (success) {
|
||||||
|
QMessageBox::information(this, "Info", "Successfully created delivery point");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Error creating delivery point");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dpvm->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_delivery_point_remove() {
|
void AdminPanel::on_delivery_point_remove() {
|
||||||
|
auto selected = ui->tv_dp->selectionModel()->selectedRows();
|
||||||
|
if (selected.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox delConf(this);
|
||||||
|
delConf.setIcon(QMessageBox::Question);
|
||||||
|
delConf.setWindowTitle(tr("Deletion confirmation"));
|
||||||
|
delConf.setText(tr("Are you sure you want to delete these delivery points?"));
|
||||||
|
delConf.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
delConf.setDefaultButton(QMessageBox::No);
|
||||||
|
if (delConf.exec() == QMessageBox::No) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto mIdx, selected) {
|
||||||
|
entity_id oid = mIdx.data().toULongLong();
|
||||||
|
apparatus::instance()->get_object_subsystem()->remove_dpoint(oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
dpvm->update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,19 @@
|
||||||
#define ADMINPANEL_H
|
#define ADMINPANEL_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "usereditdialog.h"
|
||||||
|
#include "vesseleditdialog.h"
|
||||||
|
#include "deliverypointeditdialog.h"
|
||||||
|
|
||||||
#include "viewmodels/usersviewmodel.h"
|
#include "viewmodels/usersviewmodel.h"
|
||||||
|
#include "viewmodels/vesselsviewmodel.h"
|
||||||
|
#include "viewmodels/deliverypointsviewmodel.h"
|
||||||
|
|
||||||
#include "entities/user_entity.h"
|
#include "entities/user_entity.h"
|
||||||
|
#include "entities/dpoint_entity.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class AdminPanel;
|
class AdminPanel;
|
||||||
|
|
@ -18,6 +27,8 @@ class AdminPanel : public QMainWindow
|
||||||
user_entity user;
|
user_entity user;
|
||||||
|
|
||||||
UsersViewModel *uvm;
|
UsersViewModel *uvm;
|
||||||
|
VesselsViewModel *vvm;
|
||||||
|
DeliveryPointsViewModel *dpvm;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AdminPanel(QWidget *parent = nullptr);
|
explicit AdminPanel(QWidget *parent = nullptr);
|
||||||
|
|
@ -32,16 +43,13 @@ private:
|
||||||
|
|
||||||
void on_logout_requested();
|
void on_logout_requested();
|
||||||
|
|
||||||
void on_vessel_add();
|
void on_vessel_add_edit(bool edit);
|
||||||
void on_vessel_remove();
|
void on_vessel_remove();
|
||||||
|
|
||||||
void on_user_add();
|
void on_user_add_edit(bool edit);
|
||||||
void on_user_remove();
|
void on_user_remove();
|
||||||
|
|
||||||
void on_storage_add();
|
void on_delivery_point_add_edit(bool edit);
|
||||||
void on_storage_remove();
|
|
||||||
|
|
||||||
void on_delivery_point_add();
|
|
||||||
void on_delivery_point_remove();
|
void on_delivery_point_remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,153 +6,21 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1200</width>
|
<width>1162</width>
|
||||||
<height>600</height>
|
<height>532</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<item row="2" column="0">
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Vessels</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QTableView" name="tv_vessels"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_vessels_add">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_vessels_remove">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remove</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Users</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QTableView" name="tv_users"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_users_add">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_users_remove">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remove</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_4">
|
|
||||||
<property name="text">
|
|
||||||
<string>Delivery points</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QTableView" name="tv_dp"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_dp_add">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_dp_remove">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remove</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Storages</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QTableView" name="tv_storages"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_storage_add">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_storage_remove">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remove</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLabel" name="lab_user">
|
|
||||||
<property name="text">
|
|
||||||
<string>Hello, user %1</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QPushButton" name="pb_logout">
|
<widget class="QPushButton" name="pb_logout">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
@ -166,19 +34,229 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
<item row="0" column="1">
|
||||||
</widget>
|
<widget class="QLabel" name="lab_user">
|
||||||
<widget class="QMenuBar" name="menubar">
|
<property name="text">
|
||||||
<property name="geometry">
|
<string>Hello, %1</string>
|
||||||
<rect>
|
</property>
|
||||||
<x>0</x>
|
<property name="textFormat">
|
||||||
<y>0</y>
|
<enum>Qt::MarkdownText</enum>
|
||||||
<width>1200</width>
|
</property>
|
||||||
<height>21</height>
|
<property name="alignment">
|
||||||
</rect>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QTabWidget" name="tw_tabs">
|
||||||
|
<property name="tabShape">
|
||||||
|
<enum>QTabWidget::Rounded</enum>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="documentMode">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="tabBarAutoHide">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tab_users">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Users</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QTableView" name="tv_users">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>953</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_users_add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_users_edit">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_users_remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_vessels">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Vessels</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="1" column="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_vessels_add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_vessels_edit">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_vessels_remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>953</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="2">
|
||||||
|
<widget class="QTableView" name="tv_vessels">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_dps">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Delivery points</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="1" column="1">
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>953</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_dp_add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_dp_edit">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_dp_remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="2">
|
||||||
|
<widget class="QTableView" name="tv_dp">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ void AuthWindow::on_auth_requested() {
|
||||||
QMessageBox::information(this, "Info", "You are the first user of system. "
|
QMessageBox::information(this, "Info", "You are the first user of system. "
|
||||||
"Your account type is administrator");
|
"Your account type is administrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apparatus::instance()->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto user = a->get_user(login, success);
|
auto user = a->get_user(login, success);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,29 @@
|
||||||
#include "cargoeditdialog.h"
|
#include "cargoeditdialog.h"
|
||||||
#include "ui_cargoeditdialog.h"
|
#include "ui_cargoeditdialog.h"
|
||||||
|
|
||||||
CargoEditDialog::CargoEditDialog(QWidget *parent) :
|
CargoEditDialog::CargoEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CargoEditDialog) {
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::CargoEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &CargoEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &CargoEditDialog::reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
CargoEditDialog::~CargoEditDialog()
|
CargoEditDialog::~CargoEditDialog() {
|
||||||
{
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cargo_entity* CargoEditDialog::cargo() {
|
||||||
|
return this->_cargo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CargoEditDialog::accept() {
|
||||||
|
bool emptyTitle = ui->et_title->text().trimmed().isEmpty();
|
||||||
|
if (emptyTitle) {
|
||||||
|
QMessageBox::critical(this, "Error", "Title cannot be empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_cargo = new cargo_entity(ui->et_title->text().trimmed(), ui->sb_volume->value());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,28 @@
|
||||||
#define CARGOEDITDIALOG_H
|
#define CARGOEDITDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "entities/cargo_entity.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class CargoEditDialog;
|
class CargoEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CargoEditDialog : public QDialog
|
class CargoEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::CargoEditDialog *ui;
|
||||||
|
|
||||||
|
cargo_entity *_cargo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CargoEditDialog(QWidget *parent = nullptr);
|
explicit CargoEditDialog(QWidget *parent = nullptr);
|
||||||
~CargoEditDialog();
|
~CargoEditDialog();
|
||||||
|
|
||||||
private:
|
cargo_entity* cargo();
|
||||||
Ui::CargoEditDialog *ui;
|
|
||||||
|
public slots:
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARGOEDITDIALOG_H
|
#endif // CARGOEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,21 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>318</width>
|
<width>318</width>
|
||||||
<height>279</height>
|
<height>127</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>318</width>
|
||||||
|
<height>127</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>318</width>
|
||||||
|
<height>127</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -19,12 +31,12 @@
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Cargo ID:</string>
|
<string>Title</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="et_cargo_id">
|
<widget class="QLineEdit" name="et_title">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -33,28 +45,17 @@
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Quantity:</string>
|
<string>Volume:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="et_quantity">
|
<widget class="QSpinBox" name="sb_volume">
|
||||||
<property name="text">
|
<property name="minimum">
|
||||||
<string/>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="maximum">
|
||||||
</item>
|
<number>500000</number>
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="text">
|
|
||||||
<string>Destination:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QPushButton" name="btn_choose_destination">
|
|
||||||
<property name="text">
|
|
||||||
<string>Choose...</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -76,14 +77,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,106 @@
|
||||||
#include "deliverypointeditdialog.h"
|
#include "deliverypointeditdialog.h"
|
||||||
#include "ui_deliverypointeditdialog.h"
|
#include "ui_deliverypointeditdialog.h"
|
||||||
|
|
||||||
DeliveryPointEditDialog::DeliveryPointEditDialog(QWidget *parent) :
|
|
||||||
QDialog(parent),
|
DeliveryPointEditDialog::DeliveryPointEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DeliveryPointEditDialog) {
|
||||||
ui(new Ui::DeliveryPointEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
this->svm = new QStringListModel(this);
|
||||||
|
ui->lv_storages->setModel(this->svm);
|
||||||
|
|
||||||
|
connect(ui->lv_storages->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) {
|
||||||
|
ui->pb_storage_remove->setEnabled(selected.length() > 0);
|
||||||
|
ui->pb_storage_edit->setEnabled(selected.length() == 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_storage_remove, &QPushButton::clicked, [this]() {
|
||||||
|
auto sel = ui->lv_storages->selectionModel()->selectedRows();
|
||||||
|
if (sel.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto mIdx, sel) {
|
||||||
|
auto cuid = mIdx.data().toString().toULongLong();
|
||||||
|
this->_dp->remove_storage(cuid);
|
||||||
|
}
|
||||||
|
this->update_list();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_storage_edit, &QPushButton::clicked, [this]() {
|
||||||
|
this->on_storage_edit_add(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_storage_add, &QPushButton::clicked, [this]() {
|
||||||
|
this->on_storage_edit_add(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &DeliveryPointEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &DeliveryPointEditDialog::reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeliveryPointEditDialog::~DeliveryPointEditDialog()
|
DeliveryPointEditDialog::~DeliveryPointEditDialog() {
|
||||||
{
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::update_list() {
|
||||||
|
QStringList slist;
|
||||||
|
foreach (auto storage, this->_dp->storages()) {
|
||||||
|
slist << QString::number(storage.id());
|
||||||
|
}
|
||||||
|
this->svm->setStringList(slist);
|
||||||
|
}
|
||||||
|
|
||||||
|
dpoint_entity* DeliveryPointEditDialog::dpoint() const {
|
||||||
|
return this->_dp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::on_storage_edit_add(bool edit) {
|
||||||
|
auto selected = ui->lv_storages->selectionModel()->selectedRows();
|
||||||
|
if (edit && selected.length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_entity stor;
|
||||||
|
if (edit) {
|
||||||
|
int idx = selected[0].row();
|
||||||
|
stor = this->_dp->storages()[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
StorageEditDialog sed(this);
|
||||||
|
sed.setWindowTitle(edit? "Edit storage" : "New storage");
|
||||||
|
sed.set_storage(&stor, edit);
|
||||||
|
if (sed.exec() != StorageEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto n_storage = sed.storage();
|
||||||
|
if (edit) {
|
||||||
|
this->_dp->remove_storage(stor.id());
|
||||||
|
}
|
||||||
|
this->_dp->add_storage(*n_storage);
|
||||||
|
|
||||||
|
this->update_list();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::set_dpoint(dpoint_entity* dpoint, bool edit) {
|
||||||
|
this->_dp = new dpoint_entity(*dpoint);
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
ui->et_title->setText(dpoint->title());
|
||||||
|
this->update_list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::accept() {
|
||||||
|
bool emptyTitle = ui->et_title->text().trimmed().isEmpty();
|
||||||
|
if (emptyTitle) {;
|
||||||
|
QString message = "Some errors happend, while saving:"
|
||||||
|
"<br>- Title cannot be empty (all spaces - empty too)";
|
||||||
|
QMessageBox::critical(this, "Error", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_dp->set_title(ui->et_title->text().trimmed());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,42 @@
|
||||||
#ifndef DELIVERYPOINTEDITDIALOG_H
|
#ifndef DELIVERYPOINTEDITDIALOG_H
|
||||||
#define DELIVERYPOINTEDITDIALOG_H
|
#define DELIVERYPOINTEDITDIALOG_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
#include "entities/dpoint_entity.h"
|
||||||
|
#include "system/apparatus.h"
|
||||||
|
#include "storageeditdialog.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DeliveryPointEditDialog;
|
class DeliveryPointEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeliveryPointEditDialog : public QDialog
|
class DeliveryPointEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::DeliveryPointEditDialog *ui;
|
||||||
|
|
||||||
|
QStringListModel *svm;
|
||||||
|
dpoint_entity *_dp;
|
||||||
|
|
||||||
|
void update_list();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeliveryPointEditDialog(QWidget *parent = nullptr);
|
explicit DeliveryPointEditDialog(QWidget *parent = nullptr);
|
||||||
~DeliveryPointEditDialog();
|
~DeliveryPointEditDialog();
|
||||||
|
|
||||||
private:
|
dpoint_entity* dpoint() const;
|
||||||
Ui::DeliveryPointEditDialog *ui;
|
void set_dpoint(dpoint_entity* dpoint, bool edit);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_storage_edit_add(bool edit);
|
||||||
|
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DELIVERYPOINTEDITDIALOG_H
|
#endif // DELIVERYPOINTEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,22 @@
|
||||||
<height>386</height>
|
<height>386</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>394</width>
|
||||||
|
<height>386</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>394</width>
|
||||||
|
<height>386</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<property name="horizontalSpacing">
|
<property name="horizontalSpacing">
|
||||||
|
|
@ -44,19 +56,39 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="lv_storages"/>
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Storages IDs</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListView" name="lv_storages">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_storage_add">
|
<widget class="QPushButton" name="pb_storage_add">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add storage</string>
|
<string>Add storage</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_storage_remove">
|
<widget class="QPushButton" name="pb_storage_edit">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Edit storage</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_storage_remove">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -67,6 +99,9 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
@ -83,14 +118,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,19 @@
|
||||||
#include "cargo_entity.h"
|
#include "cargo_entity.h"
|
||||||
|
|
||||||
|
|
||||||
|
entity_id cargo_entity::__global_id = 0;
|
||||||
|
|
||||||
|
cargo_entity::cargo_entity() {
|
||||||
|
this->_id = ++cargo_entity::__global_id + QRandomGenerator().generate64();
|
||||||
|
}
|
||||||
|
|
||||||
cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(title), _volume(volume) {
|
cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(title), _volume(volume) {
|
||||||
this->_id = volume;
|
this->_id = volume;
|
||||||
auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5);
|
auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5);
|
||||||
for (auto bit : hash) {
|
for (auto bit : hash) {
|
||||||
this->_id += bit;
|
this->_id += bit;
|
||||||
}
|
}
|
||||||
|
this->_id += QRandomGenerator().generate64();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_id cargo_entity::id() const {
|
entity_id cargo_entity::id() const {
|
||||||
|
|
@ -27,3 +35,11 @@ void cargo_entity::serialize(QDataStream &output) {
|
||||||
void cargo_entity::deserialize(QDataStream &input) {
|
void cargo_entity::deserialize(QDataStream &input) {
|
||||||
input >> this->_id >> this->_title >> this->_volume;
|
input >> this->_id >> this->_title >> this->_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cargo_entity::preloadGlobalId(entity_id gid) {
|
||||||
|
cargo_entity::__global_id = gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id cargo_entity::GID() {
|
||||||
|
return cargo_entity::__global_id;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,20 @@
|
||||||
#include "IEntity.h"
|
#include "IEntity.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
class cargo_entity : public IEntity {
|
class cargo_entity : public IEntity {
|
||||||
private:
|
private:
|
||||||
entity_id _id;
|
static entity_id __global_id;
|
||||||
|
|
||||||
|
entity_id _id = 0;
|
||||||
QString _title;
|
QString _title;
|
||||||
unsigned int _volume;
|
unsigned int _volume = 50000;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cargo_entity() = default;
|
cargo_entity();
|
||||||
cargo_entity(const QString &title, unsigned int volume);
|
cargo_entity(const QString &title, unsigned int volume);
|
||||||
|
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
|
|
@ -23,6 +26,8 @@ public:
|
||||||
|
|
||||||
void serialize(QDataStream &output);
|
void serialize(QDataStream &output);
|
||||||
void deserialize(QDataStream &input);
|
void deserialize(QDataStream &input);
|
||||||
|
static void preloadGlobalId(entity_id gid);
|
||||||
|
static entity_id GID();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARGO_ENTITY_H
|
#endif // CARGO_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,75 @@
|
||||||
#include "dpoint_entity.h"
|
#include "dpoint_entity.h"
|
||||||
|
|
||||||
dpoint_entity::dpoint_entity(const QString &title) : _title(title) {
|
|
||||||
this->_id = 0;
|
entity_id dpoint_entity::__global_id = 0;
|
||||||
|
|
||||||
|
dpoint_entity::dpoint_entity() {
|
||||||
|
this->_id = ++dpoint_entity::__global_id + QRandomGenerator().generate64();
|
||||||
|
}
|
||||||
|
|
||||||
|
dpoint_entity::dpoint_entity(entity_id dispatcher_id, const QString &title) : _dispatcher_id(dispatcher_id), _title(title) {
|
||||||
|
this->_id = dispatcher_id;
|
||||||
auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5);
|
auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5);
|
||||||
for (auto bit : hash) {
|
for (auto bit : hash) {
|
||||||
this->_id += bit;
|
this->_id += bit;
|
||||||
}
|
}
|
||||||
|
this->_id += QRandomGenerator().generate64();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_id dpoint_entity::id() const {
|
entity_id dpoint_entity::id() const {
|
||||||
return this->_id;
|
return this->_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entity_id dpoint_entity::dispatcher() const {
|
||||||
|
return this->_dispatcher_id;
|
||||||
|
}
|
||||||
|
|
||||||
QString dpoint_entity::title() const {
|
QString dpoint_entity::title() const {
|
||||||
return this->_title;
|
return this->_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::set_title(const QString &new_title) {
|
||||||
|
this->_title = new_title;
|
||||||
|
}
|
||||||
|
|
||||||
const QVector<storage_entity> dpoint_entity::storages() {
|
const QVector<storage_entity> dpoint_entity::storages() {
|
||||||
return this->_storages;
|
return this->_storages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_entity* dpoint_entity::get_storage(entity_id sid, bool &success) {
|
||||||
|
success = false;
|
||||||
|
for (int i = 0; i < this->_storages.length(); i++) {
|
||||||
|
if (this->_storages[i].id() != sid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
success = true;
|
||||||
|
return &this->_storages[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::set_storages(QVector<storage_entity> storages) {
|
||||||
|
this->_storages = storages;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::remove_storage(entity_id sid) {
|
||||||
|
QVector<storage_entity> st(this->_storages);
|
||||||
|
|
||||||
|
for (int i = 0; i < st.length(); i++) {
|
||||||
|
if (st[i].id() == sid) {
|
||||||
|
st.removeAt(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->set_storages(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::add_storage(storage_entity ent) {
|
||||||
|
this->_storages.push_back(ent);
|
||||||
|
}
|
||||||
|
|
||||||
void dpoint_entity::serialize(QDataStream &output) {
|
void dpoint_entity::serialize(QDataStream &output) {
|
||||||
output << this->_id << this->_title << this->_storages.size();
|
output << this->_id << this->_title << this->_storages.size();
|
||||||
for (auto &item : this->_storages) {
|
for (auto &item : this->_storages) {
|
||||||
|
|
@ -35,3 +85,11 @@ void dpoint_entity::deserialize(QDataStream &input) {
|
||||||
this->_storages[i].deserialize(input);
|
this->_storages[i].deserialize(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::preloadGlobalId(entity_id gid) {
|
||||||
|
dpoint_entity::__global_id = gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id dpoint_entity::GID() {
|
||||||
|
return dpoint_entity::__global_id;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,37 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
class dpoint_entity : public IEntity {
|
class dpoint_entity : public IEntity {
|
||||||
private:
|
private:
|
||||||
entity_id _id;
|
static entity_id __global_id;
|
||||||
|
|
||||||
|
entity_id _id = 0;
|
||||||
|
entity_id _dispatcher_id;
|
||||||
QString _title;
|
QString _title;
|
||||||
QVector<storage_entity> _storages;
|
QVector<storage_entity> _storages;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
dpoint_entity() = default;
|
dpoint_entity();
|
||||||
dpoint_entity(const QString &title);
|
dpoint_entity(entity_id dispatcher_id, const QString &title);
|
||||||
|
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
|
entity_id dispatcher() const;
|
||||||
QString title() const;
|
QString title() const;
|
||||||
|
void set_title(const QString &new_title);
|
||||||
const QVector<storage_entity> storages();
|
const QVector<storage_entity> storages();
|
||||||
|
storage_entity* get_storage(entity_id sid, bool &success);
|
||||||
|
void set_storages(QVector<storage_entity> storages);
|
||||||
|
void remove_storage(entity_id sid);
|
||||||
|
void add_storage(storage_entity ent);
|
||||||
|
|
||||||
void serialize(QDataStream &output);
|
void serialize(QDataStream &output);
|
||||||
void deserialize(QDataStream &input);
|
void deserialize(QDataStream &input);
|
||||||
|
static void preloadGlobalId(entity_id gid);
|
||||||
|
static entity_id GID();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DPOINT_ENTITY_H
|
#endif // DPOINT_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,13 @@
|
||||||
|
|
||||||
entity_id storage_entity::__global_id = 0;
|
entity_id storage_entity::__global_id = 0;
|
||||||
|
|
||||||
storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
|
storage_entity::storage_entity() {
|
||||||
this->_id = ++storage_entity::__global_id;
|
this->_id = ++storage_entity::__global_id + QRandomGenerator().generate64();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
|
||||||
|
this->_id = ++storage_entity::__global_id + QRandomGenerator().generate64();
|
||||||
|
}
|
||||||
|
|
||||||
entity_id storage_entity::id() const {
|
entity_id storage_entity::id() const {
|
||||||
return this->_id;
|
return this->_id;
|
||||||
|
|
@ -16,12 +19,16 @@ unsigned int storage_entity::capacity() const {
|
||||||
return this->_capacity;
|
return this->_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void storage_entity::set_capacity(unsigned int new_capacity) {
|
||||||
|
this->_capacity = new_capacity;
|
||||||
|
}
|
||||||
|
|
||||||
const QVector<cargo_entity> storage_entity::cargo() {
|
const QVector<cargo_entity> storage_entity::cargo() {
|
||||||
return this->_cargo;
|
return this->_cargo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void storage_entity::add_cargo(cargo_entity object, bool &success) {
|
void storage_entity::add_cargo(cargo_entity object, bool &success) {
|
||||||
success = ((int)this->_capacity - (int)object.volume()) > 0;
|
success = ((int)this->_capacity - (int)object.volume()) >= 0;
|
||||||
if (success) {
|
if (success) {
|
||||||
this->_cargo.push_back(object);
|
this->_cargo.push_back(object);
|
||||||
this->_capacity -= object.volume();
|
this->_capacity -= object.volume();
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,24 @@
|
||||||
#include "cargo_entity.h"
|
#include "cargo_entity.h"
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QCryptographicHash>
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
|
|
||||||
class storage_entity : public IEntity {
|
class storage_entity : public IEntity {
|
||||||
private:
|
private:
|
||||||
static entity_id __global_id;
|
static entity_id __global_id;
|
||||||
|
|
||||||
entity_id _id;
|
entity_id _id = 0;
|
||||||
unsigned int _capacity;
|
unsigned int _capacity = 500000;
|
||||||
QVector<cargo_entity> _cargo;
|
QVector<cargo_entity> _cargo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
storage_entity() = default;
|
storage_entity();
|
||||||
storage_entity(unsigned int capacity);
|
storage_entity(unsigned int capacity);
|
||||||
|
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
unsigned int capacity() const;
|
unsigned int capacity() const;
|
||||||
|
void set_capacity(unsigned int new_capacity);
|
||||||
const QVector<cargo_entity> cargo();
|
const QVector<cargo_entity> cargo();
|
||||||
|
|
||||||
void add_cargo(cargo_entity object, bool &success);
|
void add_cargo(cargo_entity object, bool &success);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,21 @@
|
||||||
#include "user_entity.h"
|
#include "user_entity.h"
|
||||||
|
|
||||||
|
|
||||||
|
entity_id user_entity::__global_id = 0;
|
||||||
|
|
||||||
|
user_entity::user_entity() {
|
||||||
|
this->_id = ++user_entity::__global_id + QRandomGenerator().generate64();
|
||||||
|
}
|
||||||
|
|
||||||
user_entity::user_entity(const QString &login, const QString &password, UserRole role) : _login(login), _role(role) {
|
user_entity::user_entity(const QString &login, const QString &password, UserRole role) : _login(login), _role(role) {
|
||||||
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256);
|
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256);
|
||||||
|
foreach (auto bit, this->_pwd_hash) {
|
||||||
|
this->_id += bit;
|
||||||
|
}
|
||||||
|
foreach (auto bit, QCryptographicHash::hash(login.toLocal8Bit(), QCryptographicHash::Sha3_256)) {
|
||||||
|
this->_id += bit;
|
||||||
|
}
|
||||||
|
this->_id += QRandomGenerator().generate64();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_id user_entity::id() const {
|
entity_id user_entity::id() const {
|
||||||
|
|
@ -20,6 +34,14 @@ bool user_entity::verify_password(const QString &password) const {
|
||||||
return (this->_pwd_hash == QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256));
|
return (this->_pwd_hash == QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void user_entity::set_password(const QString &new_password) {
|
||||||
|
this->_pwd_hash = QCryptographicHash::hash(new_password.toLocal8Bit(), QCryptographicHash::Sha3_256);
|
||||||
|
}
|
||||||
|
|
||||||
|
void user_entity::set_role(UserRole new_role) {
|
||||||
|
this->_role = new_role;
|
||||||
|
}
|
||||||
|
|
||||||
void user_entity::serialize(QDataStream &output) {
|
void user_entity::serialize(QDataStream &output) {
|
||||||
output << this->_id << this->_login << this->_role << this->_pwd_hash;
|
output << this->_id << this->_login << this->_role << this->_pwd_hash;
|
||||||
}
|
}
|
||||||
|
|
@ -27,3 +49,11 @@ void user_entity::serialize(QDataStream &output) {
|
||||||
void user_entity::deserialize(QDataStream &input) {
|
void user_entity::deserialize(QDataStream &input) {
|
||||||
input >> this->_id >> this->_login >> this->_role >> this->_pwd_hash;
|
input >> this->_id >> this->_login >> this->_role >> this->_pwd_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void user_entity::preloadGlobalId(entity_id gid) {
|
||||||
|
user_entity::__global_id = gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id user_entity::GID() {
|
||||||
|
return user_entity::__global_id;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "IEntity.h"
|
#include "IEntity.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,22 +15,28 @@ enum class UserRole {
|
||||||
|
|
||||||
class user_entity : public IEntity {
|
class user_entity : public IEntity {
|
||||||
private:
|
private:
|
||||||
entity_id _id;
|
static entity_id __global_id;
|
||||||
|
|
||||||
|
entity_id _id = 0;
|
||||||
QString _login;
|
QString _login;
|
||||||
UserRole _role;
|
UserRole _role;
|
||||||
QByteArray _pwd_hash;
|
QByteArray _pwd_hash;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
user_entity() = default;
|
user_entity();
|
||||||
user_entity(const QString &login, const QString &password, UserRole role);
|
user_entity(const QString &login, const QString &password, UserRole role);
|
||||||
|
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
const QString login() const;
|
const QString login() const;
|
||||||
UserRole role() const;
|
UserRole role() const;
|
||||||
bool verify_password(const QString &password) const;
|
bool verify_password(const QString &password) const;
|
||||||
|
void set_password(const QString &new_password);
|
||||||
|
void set_role(UserRole new_role);
|
||||||
|
|
||||||
void serialize(QDataStream &output);
|
void serialize(QDataStream &output);
|
||||||
void deserialize(QDataStream &input);
|
void deserialize(QDataStream &input);
|
||||||
|
static void preloadGlobalId(entity_id gid);
|
||||||
|
static entity_id GID();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USER_ENTITY_H
|
#endif // USER_ENTITY_H
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,84 @@
|
||||||
|
|
||||||
entity_id vessel_entity::__global_id = 0;
|
entity_id vessel_entity::__global_id = 0;
|
||||||
|
|
||||||
vessel_entity::vessel_entity(const dpoint_entity &harbor, unsigned int capacity) : _harbor(harbor), _capacity(capacity) {
|
vessel_entity::vessel_entity() {
|
||||||
this->_id = ++vessel_entity::__global_id;
|
this->_id = ++vessel_entity::__global_id + QRandomGenerator().generate64();
|
||||||
|
}
|
||||||
|
|
||||||
|
vessel_entity::vessel_entity(QString skipper, entity_id harbor_id, unsigned int capacity) : _skipper(skipper), _harbor_id(harbor_id), _capacity(capacity) {
|
||||||
|
this->_id = ++vessel_entity::__global_id + harbor_id + capacity + QRandomGenerator().generate64();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_id vessel_entity::id() const {
|
entity_id vessel_entity::id() const {
|
||||||
return this->_id;
|
return this->_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dpoint_entity vessel_entity::harbor() const {
|
QString vessel_entity::skipper() const {
|
||||||
return this->_harbor;
|
return this->_skipper;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vessel_entity::set_skipper(const QString &new_skipper) {
|
||||||
|
this->_skipper = new_skipper;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id vessel_entity::harbor() const {
|
||||||
|
return this->_harbor_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vessel_entity::set_harbor(entity_id new_harbor) {
|
||||||
|
this->_harbor_id = new_harbor;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int vessel_entity::capacity() const {
|
unsigned int vessel_entity::capacity() const {
|
||||||
return this->_capacity;
|
return this->_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vessel_entity::set_capacity(unsigned int new_capacity) {
|
||||||
|
this->_capacity = new_capacity;
|
||||||
|
}
|
||||||
|
|
||||||
const QVector<cargo_entity> vessel_entity::cargo() {
|
const QVector<cargo_entity> vessel_entity::cargo() {
|
||||||
return this->_cargo;
|
return this->_cargo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vessel_entity::add_cargo(cargo_entity object, bool &success) {
|
||||||
|
success = ((int)this->_capacity - (int)object.volume()) >= 0;
|
||||||
|
if (success) {
|
||||||
|
this->_cargo.push_back(object);
|
||||||
|
this->_capacity -= object.volume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cargo_entity vessel_entity::get_cargo(entity_id oid, bool &found) {
|
||||||
|
cargo_entity ent;
|
||||||
|
found = false;
|
||||||
|
|
||||||
|
auto vit = this->_cargo.begin();
|
||||||
|
for (; vit != this->_cargo.end(); vit++) {
|
||||||
|
if ((*vit).id() == oid) {
|
||||||
|
ent = *vit;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vessel_entity::withdraw_cargo(entity_id oid, bool &success) {
|
||||||
|
success = false;
|
||||||
|
auto vit = this->_cargo.begin();
|
||||||
|
for (; vit != this->_cargo.end(); vit++) {
|
||||||
|
if ((*vit).id() == oid) {
|
||||||
|
this->_capacity += (*vit).volume();
|
||||||
|
this->_cargo.erase(vit);
|
||||||
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void vessel_entity::serialize(QDataStream &output) {
|
void vessel_entity::serialize(QDataStream &output) {
|
||||||
output << this->_id;
|
output << this->_id << this->_skipper << this->_harbor_id;
|
||||||
this->_harbor.serialize(output);
|
|
||||||
output << this->_capacity << this->_cargo.size();
|
output << this->_capacity << this->_cargo.size();
|
||||||
for (auto item : this->_cargo) {
|
for (auto item : this->_cargo) {
|
||||||
item.serialize(output);
|
item.serialize(output);
|
||||||
|
|
@ -33,8 +88,7 @@ void vessel_entity::serialize(QDataStream &output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vessel_entity::deserialize(QDataStream &input) {
|
void vessel_entity::deserialize(QDataStream &input) {
|
||||||
input >> this->_id;
|
input >> this->_id >> this->_skipper >> this->_harbor_id;
|
||||||
this->_harbor.deserialize(input);
|
|
||||||
int icnt;
|
int icnt;
|
||||||
input >> this->_capacity >> icnt;
|
input >> this->_capacity >> icnt;
|
||||||
this->_cargo.resize(icnt);
|
this->_cargo.resize(icnt);
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,36 @@
|
||||||
#include "cargo_entity.h"
|
#include "cargo_entity.h"
|
||||||
#include "dpoint_entity.h"
|
#include "dpoint_entity.h"
|
||||||
|
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
|
|
||||||
class vessel_entity : public IEntity {
|
class vessel_entity : public IEntity {
|
||||||
private:
|
private:
|
||||||
static entity_id __global_id;
|
static entity_id __global_id;
|
||||||
|
|
||||||
entity_id _id;
|
entity_id _id = 0;
|
||||||
dpoint_entity _harbor;
|
QString _skipper;
|
||||||
unsigned int _capacity;
|
entity_id _harbor_id;
|
||||||
|
unsigned int _capacity = 50000;
|
||||||
QVector<cargo_entity> _cargo;
|
QVector<cargo_entity> _cargo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vessel_entity() = default;
|
vessel_entity();
|
||||||
vessel_entity(const dpoint_entity &harbor, unsigned int capacity);
|
vessel_entity(QString skipper, entity_id harbor_id, unsigned int capacity);
|
||||||
|
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
const dpoint_entity harbor() const;
|
QString skipper() const;
|
||||||
|
void set_skipper(const QString &new_skipper);
|
||||||
|
entity_id harbor() const;
|
||||||
|
void set_harbor(entity_id new_harbor);
|
||||||
unsigned int capacity() const;
|
unsigned int capacity() const;
|
||||||
|
void set_capacity(unsigned int new_capacity);
|
||||||
const QVector<cargo_entity> cargo();
|
const QVector<cargo_entity> cargo();
|
||||||
|
|
||||||
|
void add_cargo(cargo_entity object, bool &success);
|
||||||
|
cargo_entity get_cargo(entity_id oid, bool &found);
|
||||||
|
void withdraw_cargo(entity_id oid, bool &success);
|
||||||
|
|
||||||
void serialize(QDataStream &output);
|
void serialize(QDataStream &output);
|
||||||
void deserialize(QDataStream &input);
|
void deserialize(QDataStream &input);
|
||||||
static void preloadGlobalId(entity_id gid);
|
static void preloadGlobalId(entity_id gid);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ SOURCES += \
|
||||||
system/object_system.cpp \
|
system/object_system.cpp \
|
||||||
usereditdialog.cpp \
|
usereditdialog.cpp \
|
||||||
vesseleditdialog.cpp \
|
vesseleditdialog.cpp \
|
||||||
viewmodels/usersviewmodel.cpp
|
viewmodels/cargoviewmodel.cpp \
|
||||||
|
viewmodels/deliverypointsviewmodel.cpp \
|
||||||
|
viewmodels/usersviewmodel.cpp \
|
||||||
|
viewmodels/vesselsviewmodel.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
adminpanel.h \
|
adminpanel.h \
|
||||||
|
|
@ -45,7 +48,10 @@ HEADERS += \
|
||||||
system/object_system.h \
|
system/object_system.h \
|
||||||
usereditdialog.h \
|
usereditdialog.h \
|
||||||
vesseleditdialog.h \
|
vesseleditdialog.h \
|
||||||
viewmodels/usersviewmodel.h
|
viewmodels/cargoviewmodel.h \
|
||||||
|
viewmodels/deliverypointsviewmodel.h \
|
||||||
|
viewmodels/usersviewmodel.h \
|
||||||
|
viewmodels/vesselsviewmodel.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
adminpanel.ui \
|
adminpanel.ui \
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,86 @@
|
||||||
#include "storageeditdialog.h"
|
#include "storageeditdialog.h"
|
||||||
#include "ui_storageeditdialog.h"
|
#include "ui_storageeditdialog.h"
|
||||||
|
|
||||||
StorageEditDialog::StorageEditDialog(QWidget *parent) :
|
StorageEditDialog::StorageEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StorageEditDialog) {
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::StorageEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
this->cvm = new CargoViewModel(this);
|
||||||
|
ui->tv_cargo->setModel(this->cvm);
|
||||||
|
|
||||||
|
connect(ui->tv_cargo->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) {
|
||||||
|
ui->pb_cargo_remove->setEnabled(selected.length() > 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_cargo_remove, &QPushButton::clicked, [this]() {
|
||||||
|
auto sel = ui->tv_cargo->selectionModel()->selectedRows();
|
||||||
|
if (sel.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto mIdx, sel) {
|
||||||
|
auto oid = mIdx.data().toULongLong();
|
||||||
|
bool success;
|
||||||
|
this->_storage->withdraw_cargo(oid, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot remove some of this cargo!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_cargo_add, &QPushButton::clicked, this, &StorageEditDialog::on_cargo_add);
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &StorageEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &StorageEditDialog::reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageEditDialog::~StorageEditDialog()
|
StorageEditDialog::~StorageEditDialog() {
|
||||||
{
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_entity* StorageEditDialog::storage() {
|
||||||
|
return this->_storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageEditDialog::set_storage(storage_entity *ent, bool edit) {
|
||||||
|
this->_storage = new storage_entity(*ent);
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
ui->sb_capacity->setValue(ent->capacity());
|
||||||
|
this->cvm->set_data(this->_storage->cargo());
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->lab_capacity_current->setText(QString::number(this->_storage->capacity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageEditDialog::on_cargo_add() {
|
||||||
|
CargoEditDialog ced(this);
|
||||||
|
ced.setWindowTitle("New cargo");
|
||||||
|
if (ced.exec() != CargoEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
this->_storage->add_cargo(*ced.cargo(), success);
|
||||||
|
if (success) {
|
||||||
|
this->cvm->set_data(this->_storage->cargo());
|
||||||
|
QMessageBox::information(this, "Success", "Cargo successfully put into storage");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Not enough space to put cargo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageEditDialog::accept() {
|
||||||
|
int cvs = 0;
|
||||||
|
foreach (auto c, this->_storage->cargo()) {
|
||||||
|
cvs += c.volume();
|
||||||
|
}
|
||||||
|
if (cvs > ui->sb_capacity->value()) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cargo volume bigger than capacity");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_storage->set_capacity(ui->sb_capacity->value());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,36 @@
|
||||||
#ifndef STORAGEEDITDIALOG_H
|
#ifndef STORAGEEDITDIALOG_H
|
||||||
#define STORAGEEDITDIALOG_H
|
#define STORAGEEDITDIALOG_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "entities/storage_entity.h"
|
||||||
|
#include "viewmodels/cargoviewmodel.h"
|
||||||
|
#include "cargoeditdialog.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class StorageEditDialog;
|
class StorageEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StorageEditDialog : public QDialog
|
class StorageEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::StorageEditDialog *ui;
|
||||||
|
|
||||||
|
CargoViewModel *cvm;
|
||||||
|
storage_entity *_storage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StorageEditDialog(QWidget *parent = nullptr);
|
explicit StorageEditDialog(QWidget *parent = nullptr);
|
||||||
~StorageEditDialog();
|
~StorageEditDialog();
|
||||||
|
|
||||||
private:
|
storage_entity* storage();
|
||||||
Ui::StorageEditDialog *ui;
|
void set_storage(storage_entity *ent, bool edit);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_cargo_add();
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STORAGEEDITDIALOG_H
|
#endif // STORAGEEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -7,37 +7,93 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>190</height>
|
<height>336</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>400</width>
|
||||||
|
<height>336</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>400</width>
|
||||||
|
<height>336</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Storage num.:</string>
|
<string>Capacity (new):</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="et_storage_num"/>
|
<widget class="QSpinBox" name="sb_capacity">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>500000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Capacity:</string>
|
<string>Capacity (current):</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="et_capacity"/>
|
<widget class="QLabel" name="lab_capacity_current">
|
||||||
|
<property name="text">
|
||||||
|
<string>0</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Storage cargo</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="tv_cargo"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_cargo_add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add cargo</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_cargo_remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove cargo</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
@ -54,14 +110,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,12 @@ void apparatus::save() {
|
||||||
QDataStream stream(&f);
|
QDataStream stream(&f);
|
||||||
|
|
||||||
// saving GIDs
|
// saving GIDs
|
||||||
entity_id vgid = vessel_entity::GID();
|
entity_id cgid = cargo_entity::GID();
|
||||||
|
entity_id dgid = dpoint_entity::GID();
|
||||||
entity_id sgid = storage_entity::GID();
|
entity_id sgid = storage_entity::GID();
|
||||||
stream << vgid << sgid;
|
entity_id ugid = user_entity::GID();
|
||||||
|
entity_id vgid = vessel_entity::GID();
|
||||||
|
stream << cgid << dgid << sgid << ugid << vgid;
|
||||||
|
|
||||||
// serializing data
|
// serializing data
|
||||||
this->_auth_system->serialize_data(&stream);
|
this->_auth_system->serialize_data(&stream);
|
||||||
|
|
@ -52,17 +55,20 @@ void apparatus::save() {
|
||||||
|
|
||||||
void apparatus::load() {
|
void apparatus::load() {
|
||||||
if (_instance == nullptr) {
|
if (_instance == nullptr) {
|
||||||
throw std::runtime_error("HOW DU FUCK INSTANCE IS NULL????");
|
throw std::runtime_error("NO WAY INSTANCE IS NULL!");
|
||||||
}
|
}
|
||||||
QFile f(apparatus::filename);
|
QFile f(apparatus::filename);
|
||||||
f.open(QIODevice::ReadOnly);
|
f.open(QIODevice::ReadOnly);
|
||||||
QDataStream stream(&f);
|
QDataStream stream(&f);
|
||||||
|
|
||||||
// loading GIDs
|
// loading GIDs
|
||||||
entity_id vgid, sgid;
|
entity_id cgid, dgid, sgid, ugid, vgid = ugid = sgid = dgid = cgid = 0;
|
||||||
stream >> vgid >> sgid;
|
stream >> cgid >> dgid >> sgid >> ugid >> vgid;
|
||||||
vessel_entity::preloadGlobalId(vgid);
|
cargo_entity::preloadGlobalId(cgid);
|
||||||
|
dpoint_entity::preloadGlobalId(dgid);
|
||||||
storage_entity::preloadGlobalId(sgid);
|
storage_entity::preloadGlobalId(sgid);
|
||||||
|
user_entity::preloadGlobalId(ugid);
|
||||||
|
vessel_entity::preloadGlobalId(vgid);
|
||||||
|
|
||||||
// deserializing data
|
// deserializing data
|
||||||
this->_auth_system->deserialize_data(&stream);
|
this->_auth_system->deserialize_data(&stream);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#include "apparatus.h"
|
#include "apparatus.h"
|
||||||
#include "auth_system.h"
|
#include "auth_system.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
const user_entity* auth_system::get_user(const QString &login, bool &success) {
|
user_entity* auth_system::get_user(const QString &login, bool &success) {
|
||||||
user_entity *out = nullptr;
|
user_entity *out = nullptr;
|
||||||
|
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -34,11 +33,7 @@ bool auth_system::register_user(const QString &login, const QString &password, U
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
this->get_user(login, exists);
|
this->get_user(login, exists);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
std::cout << apparatus::instance()->get_auth_subsystem()->users().length() << std::endl;
|
|
||||||
this->_users.push_back(user_entity(login, password, role));
|
this->_users.push_back(user_entity(login, password, role));
|
||||||
std::cout << apparatus::instance()->get_auth_subsystem()->users().length() << std::endl;
|
|
||||||
apparatus::instance()->save();
|
|
||||||
std::cout << apparatus::instance()->get_auth_subsystem()->users().length() << std::endl;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ private:
|
||||||
public:
|
public:
|
||||||
auth_system() = default;
|
auth_system() = default;
|
||||||
|
|
||||||
const user_entity* get_user(const QString &login, bool &success);
|
user_entity* get_user(const QString &login, bool &success);
|
||||||
bool remove_user(const QString &login);
|
bool remove_user(const QString &login);
|
||||||
bool register_user(const QString &login, const QString &password, UserRole role);
|
bool register_user(const QString &login, const QString &password, UserRole role);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "object_system.h"
|
#include "object_system.h"
|
||||||
|
|
||||||
|
|
||||||
const dpoint_entity* object_system::get_dpoint(entity_id oid, bool &success) {
|
dpoint_entity* object_system::get_dpoint(entity_id oid, bool &success) {
|
||||||
dpoint_entity *out = nullptr;
|
dpoint_entity *out = nullptr;
|
||||||
|
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -39,7 +39,7 @@ bool object_system::add_dpoint(dpoint_entity dpoint) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vessel_entity* object_system::get_vessel(entity_id oid, bool &success) {
|
vessel_entity* object_system::get_vessel(entity_id oid, bool &success) {
|
||||||
vessel_entity *out = nullptr;
|
vessel_entity *out = nullptr;
|
||||||
|
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -66,11 +66,11 @@ bool object_system::remove_vessel(entity_id oid) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool object_system::add_vessel(vessel_entity dpoint) {
|
bool object_system::add_vessel(vessel_entity vessel) {
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
this->get_dpoint(dpoint.id(), exists);
|
this->get_vessel(vessel.id(), exists);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
this->_vessels.push_back(dpoint);
|
this->_vessels.push_back(vessel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ private:
|
||||||
public:
|
public:
|
||||||
object_system() = default;
|
object_system() = default;
|
||||||
|
|
||||||
const dpoint_entity* get_dpoint(entity_id oid, bool &success);
|
dpoint_entity* get_dpoint(entity_id oid, bool &success);
|
||||||
bool remove_dpoint(entity_id oid);
|
bool remove_dpoint(entity_id oid);
|
||||||
bool add_dpoint(dpoint_entity dpoint);
|
bool add_dpoint(dpoint_entity dpoint);
|
||||||
|
|
||||||
const vessel_entity* get_vessel(entity_id oid, bool &success);
|
vessel_entity* get_vessel(entity_id oid, bool &success);
|
||||||
bool remove_vessel(entity_id oid);
|
bool remove_vessel(entity_id oid);
|
||||||
bool add_vessel(vessel_entity dpoint);
|
bool add_vessel(vessel_entity dpoint);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,72 @@
|
||||||
#include "usereditdialog.h"
|
#include "usereditdialog.h"
|
||||||
#include "ui_usereditdialog.h"
|
#include "ui_usereditdialog.h"
|
||||||
|
|
||||||
UserEditDialog::UserEditDialog(QWidget *parent) :
|
|
||||||
QDialog(parent),
|
UserEditDialog::UserEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::UserEditDialog) {
|
||||||
ui(new Ui::UserEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->btn_save, &QPushButton::clicked, this, &UserEditDialog::accept);
|
||||||
|
connect(ui->btn_discard, &QPushButton::clicked, this, &UserEditDialog::reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserEditDialog::~UserEditDialog()
|
UserEditDialog::~UserEditDialog() {
|
||||||
{
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user_data_struct* UserEditDialog::user_data() const {
|
||||||
|
return this->_user_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserEditDialog::set_user(user_entity* user, bool edit) {
|
||||||
|
if (edit) {
|
||||||
|
this->_user_data = new user_data_struct();
|
||||||
|
|
||||||
|
ui->et_login->setText(user->login());
|
||||||
|
ui->et_password->setText("##########UNEDITED##########");
|
||||||
|
ui->cb_role->setCurrentIndex((int)user->role());
|
||||||
|
ui->cb_role->setEnabled(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->_user_data = new user_data_struct{};
|
||||||
|
}
|
||||||
|
this->_user_data->edit = edit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserEditDialog::accept() {
|
||||||
|
UserRole role;
|
||||||
|
switch (ui->cb_role->currentIndex()) {
|
||||||
|
case 0:
|
||||||
|
role = UserRole::ADMINISTRATOR;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
role = UserRole::DISPATCHER;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
role = UserRole::SKIPPER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bool emptyTitle = ui->et_login->text().trimmed().isEmpty();
|
||||||
|
bool emptyPassword = ui->et_password->text().trimmed().isEmpty();
|
||||||
|
if (emptyTitle || emptyPassword) {
|
||||||
|
QMessageBox errDlg(this);
|
||||||
|
errDlg.setTextFormat(Qt::RichText);
|
||||||
|
errDlg.setWindowTitle(tr("Error"));
|
||||||
|
errDlg.setIcon(QMessageBox::Critical);
|
||||||
|
QString message = tr("Some errors happend, while saving:");
|
||||||
|
if (emptyTitle) {
|
||||||
|
message.append("<br>- Title cannot be empty (all spaces - empty too)");
|
||||||
|
}
|
||||||
|
if (emptyPassword) {
|
||||||
|
message.append("<br>- Password cannot be empty (all spaces - empty too)");
|
||||||
|
}
|
||||||
|
errDlg.setText(message);
|
||||||
|
errDlg.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_user_data->login = ui->et_login->text().trimmed();
|
||||||
|
this->_user_data->password = ui->et_password->text().trimmed();
|
||||||
|
this->_user_data->role = role;
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,37 @@
|
||||||
#define USEREDITDIALOG_H
|
#define USEREDITDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "entities/user_entity.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class UserEditDialog;
|
class UserEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserEditDialog : public QDialog
|
struct user_data_struct {
|
||||||
{
|
QString login;
|
||||||
|
QString password;
|
||||||
|
UserRole role;
|
||||||
|
bool edit;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UserEditDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::UserEditDialog *ui;
|
||||||
|
|
||||||
|
user_data_struct *_user_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UserEditDialog(QWidget *parent = nullptr);
|
explicit UserEditDialog(QWidget *parent = nullptr);
|
||||||
~UserEditDialog();
|
~UserEditDialog();
|
||||||
|
|
||||||
private:
|
user_data_struct* user_data() const;
|
||||||
Ui::UserEditDialog *ui;
|
void set_user(user_entity* user, bool edit);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USEREDITDIALOG_H
|
#endif // USEREDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,18 @@
|
||||||
<height>270</height>
|
<height>270</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>304</width>
|
||||||
|
<height>270</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>304</width>
|
||||||
|
<height>270</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -68,7 +80,7 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Captain</string>
|
<string>Skipper</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,269 @@
|
||||||
#include "vesseleditdialog.h"
|
#include "vesseleditdialog.h"
|
||||||
#include "ui_vesseleditdialog.h"
|
#include "ui_vesseleditdialog.h"
|
||||||
|
|
||||||
VesselEditDialog::VesselEditDialog(QWidget *parent) :
|
VesselEditDialog::VesselEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VesselEditDialog) {
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::VesselEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
this->cvm = new CargoViewModel(this);
|
||||||
|
ui->tv_cargo->setModel(this->cvm);
|
||||||
|
|
||||||
|
connect(ui->tv_cargo->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) {
|
||||||
|
ui->pb_cargo_remove->setEnabled(selected.length() > 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_cargo_remove, &QPushButton::clicked, [this]() {
|
||||||
|
auto sel = ui->tv_cargo->selectionModel()->selectedRows();
|
||||||
|
if (sel.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto mIdx, sel) {
|
||||||
|
auto oid = mIdx.data().toULongLong();
|
||||||
|
bool success;
|
||||||
|
this->_vessel->withdraw_cargo(oid, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot remove some of this cargo!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (auto port, apparatus::instance()->get_object_subsystem()->dpoints()) {
|
||||||
|
ui->cb_port->addItem(tr("%1 :%2").arg(port.title()).arg(port.id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto user, apparatus::instance()->get_auth_subsystem()->users()) {
|
||||||
|
if (user.role() != UserRole::SKIPPER) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ui->cb_skippers->addItem(tr("%1 :%2").arg(user.login()).arg(user.id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(ui->pb_cargo_add, &QPushButton::clicked, this, &VesselEditDialog::on_cargo_add);
|
||||||
|
|
||||||
|
connect(ui->pb_withdraw_from_harbor, &QPushButton::clicked, this, &VesselEditDialog::on_withdraw_from_harbor);
|
||||||
|
connect(ui->pb_withdraw_from_vessel, &QPushButton::clicked, this, &VesselEditDialog::on_withdraw_from_vessel);
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &VesselEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &VesselEditDialog::reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
VesselEditDialog::~VesselEditDialog()
|
VesselEditDialog::~VesselEditDialog() {
|
||||||
{
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::select_proper_skipper() {
|
||||||
|
int i = 0;
|
||||||
|
foreach (auto user, apparatus::instance()->get_auth_subsystem()->users()) {
|
||||||
|
if (user.role() != UserRole::SKIPPER || user.login() != this->_vessel->skipper()) {
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ui->cb_port->setCurrentIndex(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find this vessel's skipper.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::select_proper_port() {
|
||||||
|
int i = 0;
|
||||||
|
foreach (auto port, apparatus::instance()->get_object_subsystem()->dpoints()) {
|
||||||
|
if (port.id() != this->_vessel->harbor()) {
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ui->cb_port->setCurrentIndex(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find this vessel's harbor.");
|
||||||
|
}
|
||||||
|
|
||||||
|
vessel_entity* VesselEditDialog::vessel() {
|
||||||
|
return this->_vessel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::set_vessel(vessel_entity *ves, bool edit) {
|
||||||
|
this->_vessel = new vessel_entity(*ves);
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
this->select_proper_skipper();
|
||||||
|
this->select_proper_port();
|
||||||
|
ui->sb_capacity->setValue(this->_vessel->capacity());
|
||||||
|
this->cvm->set_data(this->_vessel->cargo());
|
||||||
|
ui->pb_withdraw_from_harbor->setEnabled(true);
|
||||||
|
ui->pb_withdraw_from_vessel->setEnabled(true);
|
||||||
|
}
|
||||||
|
ui->lab_capacity_current->setText(QString::number(this->_vessel->capacity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::on_cargo_add() {
|
||||||
|
CargoEditDialog ced(this);
|
||||||
|
ced.setWindowTitle("New cargo");
|
||||||
|
if (ced.exec() != CargoEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
this->_vessel->add_cargo(*ced.cargo(), success);
|
||||||
|
if (success) {
|
||||||
|
this->cvm->set_data(this->_vessel->cargo());
|
||||||
|
QMessageBox::information(this, "Success", "Cargo successfully put into storage");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Not enough space to put cargo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::on_withdraw_from_harbor() {
|
||||||
|
QMessageBox::information(this, "Note", "Please note, old storage will be used.\n"
|
||||||
|
"Also, movement cannot be undone by discarding vessel edit dialog");
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
auto dpoint = apparatus::instance()->get_object_subsystem()->get_dpoint(this->_vessel->harbor(), success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (dpoint->storages().isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Note", "Vessel has no storages");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList harbor_storage;
|
||||||
|
foreach (auto storage, dpoint->storages()) {
|
||||||
|
harbor_storage << QString::number(storage.id());
|
||||||
|
}
|
||||||
|
bool ok;
|
||||||
|
QString storage_id_str = QInputDialog::getItem(this, "Select storage", "Storages in harbor:", harbor_storage, 0, false, &ok);
|
||||||
|
if (!ok || storage_id_str.isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Aborted", "Operation aborted by user.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id sid = storage_id_str.toULongLong();
|
||||||
|
auto storage = dpoint->get_storage(sid, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find associated storage in harbor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (storage->cargo().isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Note", "Storage has no cargo");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList storage_cargo;
|
||||||
|
foreach (auto storage, storage->cargo()) {
|
||||||
|
storage_cargo << tr("%1 :%2").arg(storage.title()).arg(storage.id());
|
||||||
|
}
|
||||||
|
QString cargo_id_str = QInputDialog::getItem(this, "Select cargo", "Cargo in storage:", storage_cargo, 0, false, &ok);
|
||||||
|
if (!ok || cargo_id_str.isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Aborted", "Operation aborted by user.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id cid = cargo_id_str.split(":")[1].toULongLong();
|
||||||
|
auto cargo = storage->get_cargo(cid, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find cargo in storage");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_vessel->add_cargo(cargo, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot add cargo to vessel");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
storage->withdraw_cargo(cid, success);
|
||||||
|
if (!success) {
|
||||||
|
throw std::runtime_error("Cannot withdraw from storage");
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::information(this, "Info", "Successfully withdrawed cargo from harbor");
|
||||||
|
cvm->set_data(this->_vessel->cargo());
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::on_withdraw_from_vessel() {
|
||||||
|
if (this->_vessel->cargo().isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Note", "Vessel has no cargo");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::information(this, "Note", "Please note, old storage will be used.\n"
|
||||||
|
"Also, movement cannot be undone by discarding vessel edit dialog");
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
auto dpoint = apparatus::instance()->get_object_subsystem()->get_dpoint(this->_vessel->harbor(), success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList vessel_cargo;
|
||||||
|
foreach (auto storage, this->_vessel->cargo()) {
|
||||||
|
vessel_cargo << tr("%1 :%2").arg(storage.title()).arg(storage.id());
|
||||||
|
}
|
||||||
|
bool ok;
|
||||||
|
QString cargo_id_str = QInputDialog::getItem(this, "Select cargo", "Cargo in storage:", vessel_cargo, 0, false, &ok);
|
||||||
|
if (!ok || cargo_id_str.isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Aborted", "Operation aborted by user.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity_id cid = cargo_id_str.split(":")[1].toULongLong();
|
||||||
|
auto cargo = this->_vessel->get_cargo(cid, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find cargo in vessel");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList harbor_storage;
|
||||||
|
foreach (auto storage, dpoint->storages()) {
|
||||||
|
harbor_storage << QString::number(storage.id());
|
||||||
|
}
|
||||||
|
QString storage_id_str = QInputDialog::getItem(this, "Select storage", "Storages in harbor:", harbor_storage, 0, false, &ok);
|
||||||
|
if (!ok || storage_id_str.isEmpty()) {
|
||||||
|
QMessageBox::information(this, "Aborted", "Operation aborted by user.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
entity_id sid = storage_id_str.toULongLong();
|
||||||
|
auto storage = dpoint->get_storage(sid, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot find associated storage in harbor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
storage->add_cargo(cargo, success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot add cargo to storage");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->_vessel->withdraw_cargo(cid, success);
|
||||||
|
if (!success) {
|
||||||
|
throw std::runtime_error("Cannot withdraw from vessel");
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::information(this, "Info", "Successfully withdrawed cargo from vessel");
|
||||||
|
cvm->set_data(this->_vessel->cargo());
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselEditDialog::accept() {
|
||||||
|
int cvs = 0;
|
||||||
|
foreach (auto c, this->_vessel->cargo()) {
|
||||||
|
cvs += c.volume();
|
||||||
|
}
|
||||||
|
if (cvs > ui->sb_capacity->value()) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cargo volume bigger than capacity");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto slog = ui->cb_skippers->currentText().split(":")[0].trimmed();
|
||||||
|
auto hid = ui->cb_port->currentText().split(":")[1].trimmed().toULongLong();
|
||||||
|
auto cap = ui->sb_capacity->value();
|
||||||
|
|
||||||
|
this->_vessel->set_skipper(slog);
|
||||||
|
this->_vessel->set_harbor(hid);
|
||||||
|
this->_vessel->set_capacity(cap);
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,40 @@
|
||||||
#define VESSELEDITDIALOG_H
|
#define VESSELEDITDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "entities/vessel_entity.h"
|
||||||
|
#include "system/apparatus.h"
|
||||||
|
#include "viewmodels/cargoviewmodel.h"
|
||||||
|
#include "cargoeditdialog.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class VesselEditDialog;
|
class VesselEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VesselEditDialog : public QDialog
|
class VesselEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::VesselEditDialog *ui;
|
||||||
|
|
||||||
|
CargoViewModel *cvm;
|
||||||
|
vessel_entity *_vessel;
|
||||||
|
|
||||||
|
void select_proper_skipper();
|
||||||
|
void select_proper_port();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VesselEditDialog(QWidget *parent = nullptr);
|
explicit VesselEditDialog(QWidget *parent = nullptr);
|
||||||
~VesselEditDialog();
|
~VesselEditDialog();
|
||||||
|
|
||||||
private:
|
vessel_entity* vessel();
|
||||||
Ui::VesselEditDialog *ui;
|
void set_vessel(vessel_entity *ves, bool edit);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_cargo_add();
|
||||||
|
void on_withdraw_from_harbor();
|
||||||
|
void on_withdraw_from_vessel();
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VESSELEDITDIALOG_H
|
#endif // VESSELEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -10,100 +10,146 @@
|
||||||
<height>425</height>
|
<height>425</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>361</width>
|
||||||
|
<height>425</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>361</width>
|
||||||
|
<height>425</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<property name="fieldGrowthPolicy">
|
|
||||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
|
||||||
</property>
|
|
||||||
<property name="horizontalSpacing">
|
|
||||||
<number>24</number>
|
|
||||||
</property>
|
|
||||||
<property name="verticalSpacing">
|
|
||||||
<number>8</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Vessel num.:</string>
|
<string>Skipper:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLineEdit" name="et_vessel_num"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Home port:</string>
|
<string>Harbor:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QPushButton" name="btn_choose_home_port">
|
<widget class="QComboBox" name="cb_port"/>
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Choose...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Max. capacity:</string>
|
<string>Capacity (new):</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="cb_skippers"/>
|
||||||
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QLineEdit" name="et_max_capacity"/>
|
<widget class="QSpinBox" name="sb_capacity">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>50000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Capacity (current):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLabel" name="lab_capacity_current">
|
||||||
|
<property name="text">
|
||||||
|
<string>50000</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<widget class="QTableView" name="tv_cargo">
|
||||||
<item>
|
<property name="selectionBehavior">
|
||||||
<widget class="QListView" name="listView"/>
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_add_cargo">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="pb_cargo_remove">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove cargo</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="pb_cargo_add">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add cargo</string>
|
<string>Add cargo</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="pb_withdraw_from_harbor">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Get from harbor</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="pb_withdraw_from_vessel">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Move to harbor</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>64</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
54
sea_transport/viewmodels/cargoviewmodel.cpp
Normal file
54
sea_transport/viewmodels/cargoviewmodel.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "cargoviewmodel.h"
|
||||||
|
|
||||||
|
CargoViewModel::CargoViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int CargoViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return this->_data.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CargoViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CargoViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||||
|
switch (section) {
|
||||||
|
case 0:
|
||||||
|
return QString("SID");
|
||||||
|
case 1:
|
||||||
|
return QString("Title");
|
||||||
|
case 2:
|
||||||
|
return QString("Volume");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CargoViewModel::data(const QModelIndex &index, int role) const {
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
auto item = this->_data[index.row()];
|
||||||
|
|
||||||
|
int col = index.column();
|
||||||
|
switch (col) {
|
||||||
|
case 0:
|
||||||
|
return QString::number(item.id());
|
||||||
|
case 1:
|
||||||
|
return item.title();
|
||||||
|
case 2:
|
||||||
|
return item.volume();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "UNKNOWN FIELD";
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CargoViewModel::set_data(const QVector<cargo_entity> &new_data) {
|
||||||
|
this->beginResetModel();
|
||||||
|
this->_data.clear();
|
||||||
|
this->_data += new_data;
|
||||||
|
this->endResetModel();
|
||||||
|
}
|
||||||
24
sea_transport/viewmodels/cargoviewmodel.h
Normal file
24
sea_transport/viewmodels/cargoviewmodel.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef CARGOVIEWMODEL_H
|
||||||
|
#define CARGOVIEWMODEL_H
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
|
#include "entities/cargo_entity.h"
|
||||||
|
|
||||||
|
class CargoViewModel : public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QVector<cargo_entity> _data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CargoViewModel(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 set_data(const QVector<cargo_entity> &new_data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CARGOVIEWMODEL_H
|
||||||
60
sea_transport/viewmodels/deliverypointsviewmodel.cpp
Normal file
60
sea_transport/viewmodels/deliverypointsviewmodel.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
#include "deliverypointsviewmodel.h"
|
||||||
|
|
||||||
|
DeliveryPointsViewModel::DeliveryPointsViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeliveryPointsViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return apparatus::instance()->get_object_subsystem()->dpoints().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeliveryPointsViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DeliveryPointsViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||||
|
switch (section) {
|
||||||
|
case 0:
|
||||||
|
return QString("DPID");
|
||||||
|
case 1:
|
||||||
|
return QString("Title");
|
||||||
|
case 2:
|
||||||
|
return QString("Storages count");
|
||||||
|
case 3:
|
||||||
|
return QString("Storages total volume");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DeliveryPointsViewModel::data(const QModelIndex &index, int role) const {
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
auto item = apparatus::instance()->get_object_subsystem()->dpoints()[index.row()];
|
||||||
|
|
||||||
|
int col = index.column();
|
||||||
|
switch (col) {
|
||||||
|
case 0:
|
||||||
|
return QString::number(item.id());
|
||||||
|
case 1:
|
||||||
|
return item.title();
|
||||||
|
case 2:
|
||||||
|
return item.storages().length();
|
||||||
|
case 3:
|
||||||
|
int tvol = 0;
|
||||||
|
foreach (auto storage, item.storages()) {
|
||||||
|
tvol += storage.capacity();
|
||||||
|
}
|
||||||
|
return tvol;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "UNKNOWN FIELD";
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointsViewModel::update() {
|
||||||
|
this->beginResetModel();
|
||||||
|
this->endResetModel();
|
||||||
|
}
|
||||||
22
sea_transport/viewmodels/deliverypointsviewmodel.h
Normal file
22
sea_transport/viewmodels/deliverypointsviewmodel.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef DELIVERYPOINTSVIEWMODEL_H
|
||||||
|
#define DELIVERYPOINTSVIEWMODEL_H
|
||||||
|
|
||||||
|
#include "system/apparatus.h"
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
|
class DeliveryPointsViewModel : public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
DeliveryPointsViewModel(QObject *parent = nullptr);
|
||||||
|
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;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DELIVERYPOINTSVIEWMODEL_H
|
||||||
|
|
@ -4,11 +4,11 @@ UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int UsersViewModel::rowCount(const QModelIndex & /*parent*/) const {
|
int UsersViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||||
return apparatus::instance()->get_object_subsystem()->vessels().size();
|
return apparatus::instance()->get_auth_subsystem()->users().length();
|
||||||
}
|
}
|
||||||
|
|
||||||
int UsersViewModel::columnCount(const QModelIndex & /*parent*/) const {
|
int UsersViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,29 +29,29 @@ QVariant UsersViewModel::headerData(int section, Qt::Orientation orientation, in
|
||||||
QVariant UsersViewModel::data(const QModelIndex &index, int role) const {
|
QVariant UsersViewModel::data(const QModelIndex &index, int role) const {
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
auto item = apparatus::instance()->get_auth_subsystem()->users()[index.row()];
|
auto item = apparatus::instance()->get_auth_subsystem()->users()[index.row()];
|
||||||
int col = index.column();
|
|
||||||
|
|
||||||
|
int col = index.column();
|
||||||
switch (col) {
|
switch (col) {
|
||||||
case 0:
|
case 0:
|
||||||
return QString::number(item.id());
|
return QString::number(item.id());
|
||||||
case 1:
|
case 1:
|
||||||
return item.login();
|
return item.login();
|
||||||
case 2:
|
case 2:
|
||||||
QString role = "unknown";
|
QString _role = "unknown";
|
||||||
|
|
||||||
switch(item.role()) {
|
switch(item.role()) {
|
||||||
case UserRole::ADMINISTRATOR:
|
case UserRole::ADMINISTRATOR:
|
||||||
role = "Administrator";
|
_role = "Administrator";
|
||||||
break;
|
break;
|
||||||
case UserRole::DISPATCHER:
|
case UserRole::DISPATCHER:
|
||||||
role = "Dispatcher";
|
_role = "Dispatcher";
|
||||||
break;
|
break;
|
||||||
case UserRole::SKIPPER:
|
case UserRole::SKIPPER:
|
||||||
role = "Skipper";
|
_role = "Skipper";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return role;
|
return _role;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "UNKNOWN FIELD";
|
return "UNKNOWN FIELD";
|
||||||
|
|
@ -61,5 +61,6 @@ QVariant UsersViewModel::data(const QModelIndex &index, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsersViewModel::update() {
|
void UsersViewModel::update() {
|
||||||
this->resetInternalData();
|
this->beginResetModel();
|
||||||
|
this->endResetModel();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,15 @@
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
class UsersViewModel : public QAbstractTableModel
|
class UsersViewModel : public QAbstractTableModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UsersViewModel(QObject *parent = nullptr);
|
UsersViewModel(QObject *parent = nullptr);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void update();
|
void update();
|
||||||
|
|
|
||||||
70
sea_transport/viewmodels/vesselsviewmodel.cpp
Normal file
70
sea_transport/viewmodels/vesselsviewmodel.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include "vesselsviewmodel.h"
|
||||||
|
|
||||||
|
VesselsViewModel::VesselsViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int VesselsViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return apparatus::instance()->get_object_subsystem()->vessels().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int VesselsViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant VesselsViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||||
|
switch (section) {
|
||||||
|
case 0:
|
||||||
|
return QString("VID");
|
||||||
|
case 1:
|
||||||
|
return QString("Skipper");
|
||||||
|
case 2:
|
||||||
|
return QString("Harbor");
|
||||||
|
case 3:
|
||||||
|
return QString("Capacity");
|
||||||
|
case 4:
|
||||||
|
return QString("Cargo count");
|
||||||
|
case 5:
|
||||||
|
return QString("Cargo volume");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant VesselsViewModel::data(const QModelIndex &index, int role) const {
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
auto item = apparatus::instance()->get_object_subsystem()->vessels()[index.row()];
|
||||||
|
bool hs = false;
|
||||||
|
auto harbor = apparatus::instance()->get_object_subsystem()->get_dpoint(item.harbor(), hs);
|
||||||
|
|
||||||
|
int col = index.column();
|
||||||
|
switch (col) {
|
||||||
|
case 0:
|
||||||
|
return QString::number(item.id());
|
||||||
|
case 1:
|
||||||
|
return item.skipper();
|
||||||
|
case 2:
|
||||||
|
return (hs? harbor->title() : tr("##ERROR[%1]##").arg(item.harbor()));
|
||||||
|
case 3:
|
||||||
|
return item.capacity();
|
||||||
|
case 4:
|
||||||
|
return item.cargo().length();
|
||||||
|
case 5:
|
||||||
|
int cvol = 0;
|
||||||
|
foreach (auto cargo, item.cargo()) {
|
||||||
|
cvol += cargo.volume();
|
||||||
|
}
|
||||||
|
return cvol;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "UNKNOWN FIELD";
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VesselsViewModel::update() {
|
||||||
|
this->beginResetModel();
|
||||||
|
this->endResetModel();
|
||||||
|
}
|
||||||
22
sea_transport/viewmodels/vesselsviewmodel.h
Normal file
22
sea_transport/viewmodels/vesselsviewmodel.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef VESSELSVIEWMODEL_H
|
||||||
|
#define VESSELSVIEWMODEL_H
|
||||||
|
|
||||||
|
#include "system/apparatus.h"
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
|
class VesselsViewModel : public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
VesselsViewModel(QObject *parent = nullptr);
|
||||||
|
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;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VESSELSVIEWMODEL_H
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.13.3, 2020-12-22T14:58:07. -->
|
<!-- Written by QtCreator 4.13.3, 2020-12-23T04:25:48. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|
@ -169,7 +169,7 @@
|
||||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||||
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
||||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||||
|
|
@ -221,7 +221,7 @@
|
||||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||||
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
||||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ void st_test::dpoint_entity_serialization_test() {
|
||||||
f.open(QIODevice::WriteOnly);
|
f.open(QIODevice::WriteOnly);
|
||||||
stream.setDevice(&f);
|
stream.setDevice(&f);
|
||||||
|
|
||||||
ent1 = dpoint_entity("some_test_point");
|
ent1 = dpoint_entity(0, "some_test_point");
|
||||||
ent1.serialize(stream);
|
ent1.serialize(stream);
|
||||||
|
|
||||||
stream.setDevice(nullptr);
|
stream.setDevice(nullptr);
|
||||||
|
|
@ -164,8 +164,8 @@ void st_test::vessel_entity_serialization_test() {
|
||||||
f.open(QIODevice::WriteOnly);
|
f.open(QIODevice::WriteOnly);
|
||||||
stream.setDevice(&f);
|
stream.setDevice(&f);
|
||||||
|
|
||||||
dpoint_entity test_harbor("test_harbor_for_vessel");
|
dpoint_entity test_harbor(0, "test_harbor_for_vessel");
|
||||||
ent1 = vessel_entity(test_harbor, 256);
|
ent1 = vessel_entity(0, test_harbor.id(), 256);
|
||||||
ent1.serialize(stream);
|
ent1.serialize(stream);
|
||||||
|
|
||||||
stream.setDevice(nullptr);
|
stream.setDevice(nullptr);
|
||||||
|
|
@ -181,7 +181,7 @@ void st_test::vessel_entity_serialization_test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY2(
|
QVERIFY2(
|
||||||
ent1.id() == ent2.id() && ent1.harbor().id() == ent2.harbor().id() && ent1.capacity() == ent2.capacity(),
|
ent1.id() == ent2.id() && ent1.harbor() == ent2.harbor() && ent1.capacity() == ent2.capacity(),
|
||||||
"Delivery Point entity not serialized properly"
|
"Delivery Point entity not serialized properly"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +265,7 @@ void st_test::apparatus_check_auth_subsystem() {
|
||||||
void st_test::apparatus_check_object_subsystem() {
|
void st_test::apparatus_check_object_subsystem() {
|
||||||
apparatus::init();
|
apparatus::init();
|
||||||
auto os = apparatus::instance()->get_object_subsystem();
|
auto os = apparatus::instance()->get_object_subsystem();
|
||||||
dpoint_entity p("test");
|
dpoint_entity p(0, "test");
|
||||||
{
|
{
|
||||||
bool test = os->add_dpoint(p);
|
bool test = os->add_dpoint(p);
|
||||||
QVERIFY(test);
|
QVERIFY(test);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue