Code style refactoring done

This commit is contained in:
Andrew nuark G 2021-01-10 19:49:24 +07:00
parent 02766bd5d2
commit c5f1572efa
36 changed files with 202 additions and 130 deletions

View file

@ -5,7 +5,6 @@
AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminPanel) { AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminPanel) {
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, [this](){ connect(ui->pb_vessels_add, &QPushButton::clicked, this, [this](){
@ -32,7 +31,6 @@ AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminP
}); });
connect(ui->pb_dp_remove, &QPushButton::clicked, this, &AdminPanel::on_delivery_point_remove); connect(ui->pb_dp_remove, &QPushButton::clicked, this, &AdminPanel::on_delivery_point_remove);
uvm = new UsersViewModel(this); uvm = new UsersViewModel(this);
ui->tv_users->setModel(this->uvm); ui->tv_users->setModel(this->uvm);
@ -42,20 +40,26 @@ AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminP
dpvm = new DeliveryPointsViewModel(this); dpvm = new DeliveryPointsViewModel(this);
ui->tv_dp->setModel(dpvm); ui->tv_dp->setModel(dpvm);
connect(ui->tv_users->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) { connect(ui->tv_users->selectionModel(), &QItemSelectionModel::selectionChanged,
ui->pb_users_remove->setEnabled(selected.length() > 0); [this](const QItemSelection &selected) {
ui->pb_users_edit->setEnabled(selected.length() == 1); ui->pb_users_remove->setEnabled(selected.length() > 0);
}); ui->pb_users_edit->setEnabled(selected.length() == 1);
}
);
connect(ui->tv_vessels->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) { connect(ui->tv_vessels->selectionModel(), &QItemSelectionModel::selectionChanged,
ui->pb_vessels_remove->setEnabled(selected.length() > 0); [this](const QItemSelection &selected) {
ui->pb_vessels_edit->setEnabled(selected.length() == 1); 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) { connect(ui->tv_dp->selectionModel(), &QItemSelectionModel::selectionChanged,
ui->pb_dp_remove->setEnabled(selected.length() > 0); [this](const QItemSelection &selected) {
ui->pb_dp_edit->setEnabled(selected.length() == 1); ui->pb_dp_remove->setEnabled(selected.length() > 0);
}); ui->pb_dp_edit->setEnabled(selected.length() == 1);
}
);
connect(this, &AdminPanel::user_set, this, &AdminPanel::on_user_set); connect(this, &AdminPanel::user_set, this, &AdminPanel::on_user_set);
} }
@ -199,7 +203,8 @@ void AdminPanel::on_user_add_edit(bool edit) {
if (success) { if (success) {
user->set_password(data->password); user->set_password(data->password);
user->set_role(data->role); user->set_role(data->role);
QMessageBox::information(this, "Info", "User edited successfully (note: you cannot change login)"); QMessageBox::information(this, "Info", "User edited successfully "
"(note: you cannot change login)");
} }
else { else {
QMessageBox::critical(this, "Error", "Error while editing user"); QMessageBox::critical(this, "Error", "Error while editing user");
@ -207,7 +212,8 @@ void AdminPanel::on_user_add_edit(bool edit) {
} }
} }
else { else {
bool success = apparatus::instance()->get_auth_subsystem()->register_user(data->login, data->password, data->role); bool success = apparatus::instance()->get_auth_subsystem()
->register_user(data->login, data->password, data->role);
if (success) { if (success) {
QMessageBox::information(this, "Info", "User created successfully"); QMessageBox::information(this, "Info", "User created successfully");
} }

View file

@ -16,13 +16,15 @@
#include "entities/user_entity.h" #include "entities/user_entity.h"
#include "entities/dpoint_entity.h" #include "entities/dpoint_entity.h"
namespace Ui {
class AdminPanel; namespace Ui { class AdminPanel; }
}
class AdminPanel : public QMainWindow { class AdminPanel : public QMainWindow {
private:
Q_OBJECT Q_OBJECT
Ui::AdminPanel *ui;
user_entity user; user_entity user;
UsersViewModel *uvm; UsersViewModel *uvm;
@ -42,8 +44,6 @@ private slots:
void on_user_set(); void on_user_set();
private: private:
Ui::AdminPanel *ui;
void on_logout_requested(); void on_logout_requested();
void on_vessel_add_edit(bool edit); void on_vessel_add_edit(bool edit);

View file

@ -24,7 +24,7 @@ void AuthWindow::on_auth_requested() {
bool success = false; bool success = false;
auto a = apparatus::instance()->get_auth_subsystem(); auto a = apparatus::instance()->get_auth_subsystem();
if (apparatus::isFirstRun()) { if (apparatus::is_first_run()) {
success = a->register_user(login, passw, UserRole::ADMINISTRATOR); success = a->register_user(login, passw, UserRole::ADMINISTRATOR);
if (!success) { if (!success) {
QMessageBox::critical(this, "Error", "Cannot register you. Check filesystem permission"); QMessageBox::critical(this, "Error", "Cannot register you. Check filesystem permission");
@ -61,9 +61,11 @@ void AuthWindow::on_auth_requested() {
((AdminPanel*) w)->set_user(*user); ((AdminPanel*) w)->set_user(*user);
} }
else if (user->role() == UserRole::SKIPPER) { else if (user->role() == UserRole::SKIPPER) {
QMessageBox::information(this, "Info", "Please note: if you have more than one vessel assigned to you " QMessageBox::information(this, "Info",
"only first will be shown (it is intended by design, you cannot physically control two ships). \n" "Please note: if you have more than one vessel assigned to you "
"Please, ask your local dispatcher/administrator to unassign you from other vessels."); "only first will be shown (it is intended by design, you cannot "
"physically control two ships). \nPlease, ask your local "
"dispatcher/administrator to unassign you from other vessels.");
w = new SkipperPanel(nullptr); w = new SkipperPanel(nullptr);
((SkipperPanel*) w)->set_user(*user); ((SkipperPanel*) w)->set_user(*user);
} }

View file

@ -9,20 +9,20 @@
#include <QMainWindow> #include <QMainWindow>
#include <QMessageBox> #include <QMessageBox>
namespace Ui {
class AuthWindow; namespace Ui { class AuthWindow; }
}
class AuthWindow : public QMainWindow { class AuthWindow : public QMainWindow {
private:
Q_OBJECT Q_OBJECT
Ui::AuthWindow *ui;
public: public:
explicit AuthWindow(QWidget *parent = nullptr); explicit AuthWindow(QWidget *parent = nullptr);
~AuthWindow(); ~AuthWindow();
private: private:
Ui::AuthWindow *ui;
void on_auth_requested(); void on_auth_requested();
}; };

View file

@ -1,6 +1,7 @@
#include "cargoeditdialog.h" #include "cargoeditdialog.h"
#include "ui_cargoeditdialog.h" #include "ui_cargoeditdialog.h"
CargoEditDialog::CargoEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CargoEditDialog) { CargoEditDialog::CargoEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CargoEditDialog) {
ui->setupUi(this); ui->setupUi(this);

View file

@ -6,11 +6,11 @@
#include "entities/cargo_entity.h" #include "entities/cargo_entity.h"
namespace Ui {
class CargoEditDialog; namespace Ui { class CargoEditDialog; }
}
class CargoEditDialog : public QDialog { class CargoEditDialog : public QDialog {
private:
Q_OBJECT Q_OBJECT
Ui::CargoEditDialog *ui; Ui::CargoEditDialog *ui;

View file

@ -2,29 +2,34 @@
#include "ui_deliverypointeditdialog.h" #include "ui_deliverypointeditdialog.h"
DeliveryPointEditDialog::DeliveryPointEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DeliveryPointEditDialog) { DeliveryPointEditDialog::DeliveryPointEditDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::DeliveryPointEditDialog) {
ui->setupUi(this); ui->setupUi(this);
this->svm = new QStringListModel(this); this->svm = new QStringListModel(this);
ui->lv_storages->setModel(this->svm); ui->lv_storages->setModel(this->svm);
connect(ui->lv_storages->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) { connect(ui->lv_storages->selectionModel(), &QItemSelectionModel::selectionChanged,
ui->pb_storage_remove->setEnabled(selected.length() > 0); [this](const QItemSelection &selected) {
ui->pb_storage_edit->setEnabled(selected.length() == 1); ui->pb_storage_remove->setEnabled(selected.length() > 0);
}); ui->pb_storage_edit->setEnabled(selected.length() == 1);
}
);
connect(ui->pb_storage_remove, &QPushButton::clicked, [this]() { connect(ui->pb_storage_remove, &QPushButton::clicked,
auto sel = ui->lv_storages->selectionModel()->selectedRows(); [this]() {
if (sel.length() == 0) { auto sel = ui->lv_storages->selectionModel()->selectedRows();
return; if (sel.length() == 0) {
} return;
}
foreach (auto mIdx, sel) { foreach (auto mIdx, sel) {
auto cuid = mIdx.data().toString().toULongLong(); auto cuid = mIdx.data().toString().toULongLong();
this->_dp->remove_storage(cuid); this->_dp->remove_storage(cuid);
} }
this->update_list(); this->update_list();
}); }
);
connect(ui->pb_storage_edit, &QPushButton::clicked, [this]() { connect(ui->pb_storage_edit, &QPushButton::clicked, [this]() {
this->on_storage_edit_add(true); this->on_storage_edit_add(true);

View file

@ -13,19 +13,16 @@
#include "storageeditdialog.h" #include "storageeditdialog.h"
namespace Ui { namespace Ui { class DeliveryPointEditDialog; }
class DeliveryPointEditDialog;
}
class DeliveryPointEditDialog : public QDialog { class DeliveryPointEditDialog : public QDialog {
private:
Q_OBJECT Q_OBJECT
Ui::DeliveryPointEditDialog *ui; Ui::DeliveryPointEditDialog *ui;
QStringListModel *svm; QStringListModel *svm;
dpoint_entity *_dp; dpoint_entity *_dp;
void update_list();
public: public:
explicit DeliveryPointEditDialog(QWidget *parent = nullptr); explicit DeliveryPointEditDialog(QWidget *parent = nullptr);
~DeliveryPointEditDialog(); ~DeliveryPointEditDialog();
@ -37,6 +34,9 @@ public slots:
void on_storage_edit_add(bool edit); void on_storage_edit_add(bool edit);
void accept() Q_DECL_OVERRIDE; void accept() Q_DECL_OVERRIDE;
private:
void update_list();
}; };
#endif // DELIVERYPOINTEDITDIALOG_H #endif // DELIVERYPOINTEDITDIALOG_H

View file

@ -7,7 +7,8 @@ cargo_entity::cargo_entity() {
this->_id = ++cargo_entity::__global_id + QRandomGenerator().generate64(); 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) {

View file

@ -7,7 +7,8 @@ dpoint_entity::dpoint_entity() {
this->_id = ++dpoint_entity::__global_id + QRandomGenerator().generate64(); 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) { dpoint_entity::dpoint_entity(entity_id dispatcher_id, const QString &title)
: _dispatcher_id(dispatcher_id), _title(title) {
this->_id = dispatcher_id; 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) {

View file

@ -7,12 +7,15 @@ user_entity::user_entity() {
this->_id = ++user_entity::__global_id + QRandomGenerator().generate64(); 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)
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256); : _login(login), _role(role) {
this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(),
QCryptographicHash::Sha3_256);
foreach (auto bit, this->_pwd_hash) { foreach (auto bit, this->_pwd_hash) {
this->_id += bit; this->_id += bit;
} }
foreach (auto bit, QCryptographicHash::hash(login.toLocal8Bit(), QCryptographicHash::Sha3_256)) { foreach (auto bit,
QCryptographicHash::hash(login.toLocal8Bit(), QCryptographicHash::Sha3_256)) {
this->_id += bit; this->_id += bit;
} }
this->_id += QRandomGenerator().generate64(); this->_id += QRandomGenerator().generate64();
@ -31,11 +34,13 @@ UserRole user_entity::role() const {
} }
bool user_entity::verify_password(const QString &password) const { 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) { void user_entity::set_password(const QString &new_password) {
this->_pwd_hash = QCryptographicHash::hash(new_password.toLocal8Bit(), QCryptographicHash::Sha3_256); this->_pwd_hash = QCryptographicHash::hash(new_password.toLocal8Bit(),
QCryptographicHash::Sha3_256);
} }
void user_entity::set_role(UserRole new_role) { void user_entity::set_role(UserRole new_role) {

View file

@ -12,7 +12,6 @@ enum class UserRole {
ADMINISTRATOR, DISPATCHER, SKIPPER ADMINISTRATOR, DISPATCHER, SKIPPER
}; };
class user_entity : public IEntity { class user_entity : public IEntity {
private: private:
static entity_id __global_id; static entity_id __global_id;

View file

@ -7,8 +7,10 @@ vessel_entity::vessel_entity() {
this->_id = ++vessel_entity::__global_id + QRandomGenerator().generate64(); 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) { vessel_entity::vessel_entity(QString skipper, entity_id harbor_id, unsigned int capacity)
this->_id = ++vessel_entity::__global_id + harbor_id + capacity + QRandomGenerator().generate64(); : _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 {

View file

@ -1,9 +1,9 @@
#include "authwindow.h" #include "authwindow.h"
#include "system/apparatus.h" #include "system/apparatus.h"
#include <QApplication> #include <QApplication>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
@ -14,7 +14,8 @@ int main(int argc, char *argv[]) {
QObject::connect(&a, &QApplication::aboutToQuit, []() { QObject::connect(&a, &QApplication::aboutToQuit, []() {
apparatus::instance()->save(); apparatus::instance()->save();
if (apparatus::isFirstRun() && apparatus::instance()->get_auth_subsystem()->users().length() > 0) { if (apparatus::is_first_run()
&& apparatus::instance()->get_auth_subsystem()->users().length() > 0) {
apparatus::generate_lock_file(); apparatus::generate_lock_file();
} }
}); });

View file

@ -5,7 +5,6 @@
SkipperPanel::SkipperPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::SkipperPanel) { SkipperPanel::SkipperPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::SkipperPanel) {
ui->setupUi(this); ui->setupUi(this);
connect(ui->pb_logout, &QPushButton::clicked, this, &SkipperPanel::on_logout_requested); connect(ui->pb_logout, &QPushButton::clicked, this, &SkipperPanel::on_logout_requested);
cvm = new CargoViewModel(this); cvm = new CargoViewModel(this);
@ -52,23 +51,27 @@ void SkipperPanel::on_user_set() {
} }
if (!success) { if (!success) {
QMessageBox::critical(this, "Error", "You are not assigned to vessel. \n" QMessageBox::critical(this, "Error",
"Ask you local dispatcher/administrator to do it. \n" "You are not assigned to vessel. \nAsk you local "
"System will now close."); "dispatcher/administrator to do it. \nSystem will now close.");
this->close(); this->close();
} }
ui->lab_vid->setText(QString::number(vessel.id())); ui->lab_vid->setText(QString::number(vessel.id()));
bool h_success; bool h_success;
auto harbor = apparatus::instance()->get_object_subsystem()->get_dpoint(vessel.harbor(), h_success); auto harbor = apparatus::instance()->get_object_subsystem()
->get_dpoint(vessel.harbor(), h_success);
ui->lab_harbor->setText(h_success? harbor->title() : "#UNKNOWN#"); ui->lab_harbor->setText(h_success? harbor->title() : "#UNKNOWN#");
int cap_used = 0; int cap_used = 0;
foreach (auto c, vessel.cargo()) { foreach (auto c, vessel.cargo()) {
cap_used += c.volume(); cap_used += c.volume();
} }
ui->lab_capacity->setText(tr("%1/%2/%3").arg(cap_used).arg(vessel.capacity() - cap_used).arg(vessel.capacity())); ui->lab_capacity->setText(tr("%1/%2/%3")
.arg(cap_used)
.arg(vessel.capacity() - cap_used)
.arg(vessel.capacity()));
this->cvm->set_data(vessel.cargo()); this->cvm->set_data(vessel.cargo());
} }

View file

@ -10,15 +10,16 @@
#include "entities/user_entity.h" #include "entities/user_entity.h"
#include "entities/vessel_entity.h" #include "entities/vessel_entity.h"
namespace Ui {
class SkipperPanel; namespace Ui { class SkipperPanel; }
}
class SkipperPanel : public QMainWindow { class SkipperPanel : public QMainWindow {
private:
Q_OBJECT Q_OBJECT
user_entity user; Ui::SkipperPanel *ui;
user_entity user;
CargoViewModel *cvm; CargoViewModel *cvm;
public: public:
@ -34,8 +35,6 @@ private slots:
void on_user_set(); void on_user_set();
private: private:
Ui::SkipperPanel *ui;
void on_logout_requested(); void on_logout_requested();
}; };

View file

@ -1,15 +1,19 @@
#include "storageeditdialog.h" #include "storageeditdialog.h"
#include "ui_storageeditdialog.h" #include "ui_storageeditdialog.h"
StorageEditDialog::StorageEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StorageEditDialog) {
StorageEditDialog::StorageEditDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::StorageEditDialog) {
ui->setupUi(this); ui->setupUi(this);
this->cvm = new CargoViewModel(this); this->cvm = new CargoViewModel(this);
ui->tv_cargo->setModel(this->cvm); ui->tv_cargo->setModel(this->cvm);
connect(ui->tv_cargo->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) { connect(ui->tv_cargo->selectionModel(), &QItemSelectionModel::selectionChanged,
ui->pb_cargo_remove->setEnabled(selected.length() > 0); [this](const QItemSelection &selected) {
}); ui->pb_cargo_remove->setEnabled(selected.length() > 0);
}
);
connect(ui->pb_cargo_remove, &QPushButton::clicked, [this]() { connect(ui->pb_cargo_remove, &QPushButton::clicked, [this]() {
auto sel = ui->tv_cargo->selectionModel()->selectedRows(); auto sel = ui->tv_cargo->selectionModel()->selectedRows();

View file

@ -10,11 +10,10 @@
#include "cargoeditdialog.h" #include "cargoeditdialog.h"
namespace Ui { namespace Ui { class StorageEditDialog; }
class StorageEditDialog;
}
class StorageEditDialog : public QDialog { class StorageEditDialog : public QDialog {
private:
Q_OBJECT Q_OBJECT
Ui::StorageEditDialog *ui; Ui::StorageEditDialog *ui;

View file

@ -77,7 +77,7 @@ void apparatus::load() {
f.close(); f.close();
} }
bool apparatus::isFirstRun() { bool apparatus::is_first_run() {
return !QFile().exists("lock"); return !QFile().exists("lock");
} }
@ -94,7 +94,7 @@ void apparatus::init() {
throw std::runtime_error("System already initialized!"); throw std::runtime_error("System already initialized!");
} }
bool fr = apparatus::isFirstRun(); bool fr = apparatus::is_first_run();
apparatus::_instance = new apparatus(); apparatus::_instance = new apparatus();
if (fr) { if (fr) {
@ -111,9 +111,10 @@ void apparatus::init() {
void apparatus::shutdown() { void apparatus::shutdown() {
apparatus::instance()->save(); apparatus::instance()->save();
if (apparatus::isFirstRun() && apparatus::instance()->get_auth_subsystem()->users().length() > 0) { if (apparatus::is_first_run()
&& apparatus::instance()->get_auth_subsystem()->users().length() > 0) {
apparatus::generate_lock_file(); apparatus::generate_lock_file();
} }
// delete apparatus::_instance;
apparatus::_instance = nullptr; apparatus::_instance = nullptr;
} }

View file

@ -12,8 +12,7 @@
#include <QDataStream> #include <QDataStream>
class apparatus class apparatus {
{
private: private:
static apparatus *_instance; static apparatus *_instance;
static const QString filename; static const QString filename;
@ -31,7 +30,7 @@ public:
void save(); void save();
void load(); void load();
static bool isFirstRun(); static bool is_first_run();
static void generate_lock_file(); static void generate_lock_file();
static apparatus* instance(); static apparatus* instance();
static void init(); static void init();

View file

@ -6,8 +6,7 @@
#include "../entities/user_entity.h" #include "../entities/user_entity.h"
class auth_system class auth_system {
{
private: private:
QVector<user_entity> _users; QVector<user_entity> _users;
public: public:

View file

@ -7,8 +7,7 @@
#include "../entities/vessel_entity.h" #include "../entities/vessel_entity.h"
class object_system class object_system {
{
private: private:
QVector<dpoint_entity> _dpoints; QVector<dpoint_entity> _dpoints;
QVector<vessel_entity> _vessels; QVector<vessel_entity> _vessels;

View file

@ -22,7 +22,7 @@ void UserEditDialog::set_user(user_entity* user, bool edit) {
this->_user_data = new user_data_struct(); this->_user_data = new user_data_struct();
ui->et_login->setText(user->login()); ui->et_login->setText(user->login());
ui->et_password->setText("##########UNEDITED##########"); ui->et_password->setText("#UNEDITED#");
ui->cb_role->setCurrentIndex((int)user->role()); ui->cb_role->setCurrentIndex((int)user->role());
ui->cb_role->setEnabled(false); ui->cb_role->setEnabled(false);
} }

View file

@ -7,9 +7,7 @@
#include "entities/user_entity.h" #include "entities/user_entity.h"
namespace Ui { namespace Ui { class UserEditDialog; }
class UserEditDialog;
}
struct user_data_struct { struct user_data_struct {
QString login; QString login;
@ -19,6 +17,7 @@ struct user_data_struct {
}; };
class UserEditDialog : public QDialog { class UserEditDialog : public QDialog {
private:
Q_OBJECT Q_OBJECT
Ui::UserEditDialog *ui; Ui::UserEditDialog *ui;

View file

@ -1,15 +1,19 @@
#include "vesseleditdialog.h" #include "vesseleditdialog.h"
#include "ui_vesseleditdialog.h" #include "ui_vesseleditdialog.h"
VesselEditDialog::VesselEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VesselEditDialog) {
VesselEditDialog::VesselEditDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::VesselEditDialog) {
ui->setupUi(this); ui->setupUi(this);
this->cvm = new CargoViewModel(this); this->cvm = new CargoViewModel(this);
ui->tv_cargo->setModel(this->cvm); ui->tv_cargo->setModel(this->cvm);
connect(ui->tv_cargo->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected) { connect(ui->tv_cargo->selectionModel(), &QItemSelectionModel::selectionChanged,
ui->pb_cargo_remove->setEnabled(selected.length() > 0); [this](const QItemSelection &selected) {
}); ui->pb_cargo_remove->setEnabled(selected.length() > 0);
}
);
connect(ui->pb_cargo_remove, &QPushButton::clicked, [this]() { connect(ui->pb_cargo_remove, &QPushButton::clicked, [this]() {
auto sel = ui->tv_cargo->selectionModel()->selectedRows(); auto sel = ui->tv_cargo->selectionModel()->selectedRows();
@ -40,8 +44,10 @@ VesselEditDialog::VesselEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui
connect(ui->pb_cargo_add, &QPushButton::clicked, this, &VesselEditDialog::on_cargo_add); 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_harbor, &QPushButton::clicked,
connect(ui->pb_withdraw_from_vessel, &QPushButton::clicked, this, &VesselEditDialog::on_withdraw_from_vessel); 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_save, &QPushButton::clicked, this, &VesselEditDialog::accept);
connect(ui->pb_discard, &QPushButton::clicked, this, &VesselEditDialog::reject); connect(ui->pb_discard, &QPushButton::clicked, this, &VesselEditDialog::reject);
@ -116,11 +122,13 @@ void VesselEditDialog::on_cargo_add() {
} }
void VesselEditDialog::on_withdraw_from_harbor() { void VesselEditDialog::on_withdraw_from_harbor() {
QMessageBox::information(this, "Note", "Please note, old storage will be used.\n" QMessageBox::information(this, "Note",
"Also, movement cannot be undone by discarding vessel edit dialog"); "Please note, old storage will be used.\nAlso, movement cannot be "
"undone by discarding vessel edit dialog");
bool success; bool success;
auto dpoint = apparatus::instance()->get_object_subsystem()->get_dpoint(this->_vessel->harbor(), success); auto dpoint = apparatus::instance()->get_object_subsystem()
->get_dpoint(this->_vessel->harbor(), success);
if (!success) { if (!success) {
QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB"); QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB");
return; return;
@ -135,7 +143,8 @@ void VesselEditDialog::on_withdraw_from_harbor() {
harbor_storage << QString::number(storage.id()); harbor_storage << QString::number(storage.id());
} }
bool ok; bool ok;
QString storage_id_str = QInputDialog::getItem(this, "Select storage", "Storages in harbor:", harbor_storage, 0, false, &ok); QString storage_id_str = QInputDialog::getItem(this, "Select storage", "Storages in harbor:",
harbor_storage, 0, false, &ok);
if (!ok || storage_id_str.isEmpty()) { if (!ok || storage_id_str.isEmpty()) {
QMessageBox::information(this, "Aborted", "Operation aborted by user."); QMessageBox::information(this, "Aborted", "Operation aborted by user.");
return; return;
@ -156,7 +165,8 @@ void VesselEditDialog::on_withdraw_from_harbor() {
foreach (auto storage, storage->cargo()) { foreach (auto storage, storage->cargo()) {
storage_cargo << tr("%1 :%2").arg(storage.title()).arg(storage.id()); 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); QString cargo_id_str = QInputDialog::getItem(this, "Select cargo", "Cargo in storage:",
storage_cargo, 0, false, &ok);
if (!ok || cargo_id_str.isEmpty()) { if (!ok || cargo_id_str.isEmpty()) {
QMessageBox::information(this, "Aborted", "Operation aborted by user."); QMessageBox::information(this, "Aborted", "Operation aborted by user.");
return; return;
@ -189,11 +199,13 @@ void VesselEditDialog::on_withdraw_from_vessel() {
return; return;
} }
QMessageBox::information(this, "Note", "Please note, old storage will be used.\n" QMessageBox::information(this, "Note",
"Also, movement cannot be undone by discarding vessel edit dialog"); "Please note, old storage will be used.\nAlso, movement cannot be "
"undone by discarding vessel edit dialog");
bool success; bool success;
auto dpoint = apparatus::instance()->get_object_subsystem()->get_dpoint(this->_vessel->harbor(), success); auto dpoint = apparatus::instance()->get_object_subsystem()
->get_dpoint(this->_vessel->harbor(), success);
if (!success) { if (!success) {
QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB"); QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB");
return; return;
@ -204,7 +216,8 @@ void VesselEditDialog::on_withdraw_from_vessel() {
vessel_cargo << tr("%1 :%2").arg(storage.title()).arg(storage.id()); vessel_cargo << tr("%1 :%2").arg(storage.title()).arg(storage.id());
} }
bool ok; bool ok;
QString cargo_id_str = QInputDialog::getItem(this, "Select cargo", "Cargo in storage:", vessel_cargo, 0, false, &ok); QString cargo_id_str = QInputDialog::getItem(this, "Select cargo", "Cargo in storage:",
vessel_cargo, 0, false, &ok);
if (!ok || cargo_id_str.isEmpty()) { if (!ok || cargo_id_str.isEmpty()) {
QMessageBox::information(this, "Aborted", "Operation aborted by user."); QMessageBox::information(this, "Aborted", "Operation aborted by user.");
return; return;
@ -221,7 +234,8 @@ void VesselEditDialog::on_withdraw_from_vessel() {
foreach (auto storage, dpoint->storages()) { foreach (auto storage, dpoint->storages()) {
harbor_storage << QString::number(storage.id()); harbor_storage << QString::number(storage.id());
} }
QString storage_id_str = QInputDialog::getItem(this, "Select storage", "Storages in harbor:", harbor_storage, 0, false, &ok); QString storage_id_str = QInputDialog::getItem(this, "Select storage", "Storages in harbor:",
harbor_storage, 0, false, &ok);
if (!ok || storage_id_str.isEmpty()) { if (!ok || storage_id_str.isEmpty()) {
QMessageBox::information(this, "Aborted", "Operation aborted by user."); QMessageBox::information(this, "Aborted", "Operation aborted by user.");
return; return;

View file

@ -10,20 +10,17 @@
#include "viewmodels/cargoviewmodel.h" #include "viewmodels/cargoviewmodel.h"
#include "cargoeditdialog.h" #include "cargoeditdialog.h"
namespace Ui {
class VesselEditDialog; namespace Ui { class VesselEditDialog; }
}
class VesselEditDialog : public QDialog { class VesselEditDialog : public QDialog {
private:
Q_OBJECT Q_OBJECT
Ui::VesselEditDialog *ui; Ui::VesselEditDialog *ui;
CargoViewModel *cvm; CargoViewModel *cvm;
vessel_entity *_vessel; 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();
@ -36,6 +33,10 @@ public slots:
void on_withdraw_from_harbor(); void on_withdraw_from_harbor();
void on_withdraw_from_vessel(); void on_withdraw_from_vessel();
void accept() Q_DECL_OVERRIDE; void accept() Q_DECL_OVERRIDE;
private:
void select_proper_skipper();
void select_proper_port();
}; };
#endif // VESSELEDITDIALOG_H #endif // VESSELEDITDIALOG_H

View file

@ -1,5 +1,6 @@
#include "cargoviewmodel.h" #include "cargoviewmodel.h"
CargoViewModel::CargoViewModel(QObject *parent) : QAbstractTableModel(parent) { CargoViewModel::CargoViewModel(QObject *parent) : QAbstractTableModel(parent) {
} }

View file

@ -6,7 +6,9 @@
#include "entities/cargo_entity.h" #include "entities/cargo_entity.h"
class CargoViewModel : public QAbstractTableModel { class CargoViewModel : public QAbstractTableModel {
private:
Q_OBJECT Q_OBJECT
QVector<cargo_entity> _data; QVector<cargo_entity> _data;

View file

@ -1,5 +1,6 @@
#include "deliverypointsviewmodel.h" #include "deliverypointsviewmodel.h"
DeliveryPointsViewModel::DeliveryPointsViewModel(QObject *parent) : QAbstractTableModel(parent) { DeliveryPointsViewModel::DeliveryPointsViewModel(QObject *parent) : QAbstractTableModel(parent) {
} }
@ -12,7 +13,8 @@ int DeliveryPointsViewModel::columnCount(const QModelIndex &/*parent*/) const {
return 4; return 4;
} }
QVariant DeliveryPointsViewModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant DeliveryPointsViewModel::headerData(int section, Qt::Orientation orientation,
int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch (section) { switch (section) {
case 0: case 0:

View file

@ -5,7 +5,9 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
class DeliveryPointsViewModel : public QAbstractTableModel { class DeliveryPointsViewModel : public QAbstractTableModel {
private:
Q_OBJECT Q_OBJECT
public: public:

View file

@ -1,5 +1,6 @@
#include "usersviewmodel.h" #include "usersviewmodel.h"
UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) { UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) {
} }

View file

@ -5,7 +5,9 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
class UsersViewModel : public QAbstractTableModel { class UsersViewModel : public QAbstractTableModel {
private:
Q_OBJECT Q_OBJECT
public: public:

View file

@ -1,5 +1,6 @@
#include "vesselsviewmodel.h" #include "vesselsviewmodel.h"
VesselsViewModel::VesselsViewModel(QObject *parent) : QAbstractTableModel(parent) { VesselsViewModel::VesselsViewModel(QObject *parent) : QAbstractTableModel(parent) {
} }
@ -35,8 +36,8 @@ QVariant VesselsViewModel::headerData(int section, Qt::Orientation orientation,
QVariant VesselsViewModel::data(const QModelIndex &index, int role) const { QVariant VesselsViewModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
auto item = apparatus::instance()->get_object_subsystem()->vessels()[index.row()]; auto item = apparatus::instance()->get_object_subsystem()->vessels()[index.row()];
bool hs = false; bool s = false;
auto harbor = apparatus::instance()->get_object_subsystem()->get_dpoint(item.harbor(), hs); auto harbor = apparatus::instance()->get_object_subsystem()->get_dpoint(item.harbor(), s);
int col = index.column(); int col = index.column();
switch (col) { switch (col) {
@ -45,7 +46,7 @@ QVariant VesselsViewModel::data(const QModelIndex &index, int role) const {
case 1: case 1:
return item.skipper(); return item.skipper();
case 2: case 2:
return (hs? harbor->title() : tr("##ERROR[%1]##").arg(item.harbor())); return (s? harbor->title() : tr("##ERROR[%1]##").arg(item.harbor()));
case 3: case 3:
return item.capacity(); return item.capacity();
case 4: case 4:

View file

@ -5,7 +5,9 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
class VesselsViewModel : public QAbstractTableModel { class VesselsViewModel : public QAbstractTableModel {
private:
Q_OBJECT Q_OBJECT
public: public:

View file

@ -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-30T12:27:51. --> <!-- Written by QtCreator 4.13.3, 2021-01-10T19:49:10. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -64,7 +64,26 @@
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value> <value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value> <value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/> <valuemap type="QVariantMap" key="AutoTest.CheckStates">
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:apparatus_check_first_registered_user">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:apparatus_check_first_registration">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:apparatus_check_first_run">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:apparatus_check_not_first_run">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:apparatus_check_null_throws_error">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:apparatus_check_remove_user">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:cargo_entity_serialization_test">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:cleanupTestCase">Unchecked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:dpoint_entity_serialization_test">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:initTestCase">Unchecked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:object_subsystem_check_add_dpoint">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:object_subsystem_check_find_dpoint">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:object_subsystem_check_remove_dpoint">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:st_test">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:storage_entity_serialization_test">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:user_entity_password_verification_test">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:user_entity_serialization_test">Checked</value>
<value type="Qt::CheckState" key="C:/Users/Admin/Documents/repos/sea_transport_project/st_test/tst_st_test.cpp:vessel_entity_serialization_test">Checked</value>
</valuemap>
<value type="int" key="AutoTest.RunAfterBuild">0</value> <value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value> <value type="bool" key="AutoTest.UseGlobal">true</value>
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey"> <valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">

View file

@ -249,7 +249,7 @@ void st_test::apparatus_check_null_throws_error() {
void st_test::apparatus_check_first_run() { void st_test::apparatus_check_first_run() {
apparatus::init(); apparatus::init();
QVERIFY(apparatus::instance()->isFirstRun()); QVERIFY(apparatus::instance()->is_first_run());
apparatus::shutdown(); apparatus::shutdown();
} }
@ -265,7 +265,7 @@ void st_test::apparatus_check_first_registration() {
void st_test::apparatus_check_not_first_run() { void st_test::apparatus_check_not_first_run() {
apparatus::init(); apparatus::init();
QVERIFY(!apparatus::instance()->isFirstRun()); QVERIFY(!apparatus::instance()->is_first_run());
apparatus::shutdown(); apparatus::shutdown();
} }