diff --git a/sea_transport/adminpanel.cpp b/sea_transport/adminpanel.cpp index c845cfd..d160861 100644 --- a/sea_transport/adminpanel.cpp +++ b/sea_transport/adminpanel.cpp @@ -5,7 +5,6 @@ AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminPanel) { ui->setupUi(this); - connect(ui->pb_logout, &QPushButton::clicked, this, &AdminPanel::on_logout_requested); 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); - uvm = new UsersViewModel(this); ui->tv_users->setModel(this->uvm); @@ -42,20 +40,26 @@ AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminP 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); - }); + 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); + } + ); - 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_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); - }); + 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); + } + ); connect(this, &AdminPanel::user_set, this, &AdminPanel::on_user_set); } @@ -199,7 +203,8 @@ void AdminPanel::on_user_add_edit(bool edit) { if (success) { user->set_password(data->password); 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 { QMessageBox::critical(this, "Error", "Error while editing user"); @@ -207,7 +212,8 @@ void AdminPanel::on_user_add_edit(bool edit) { } } 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) { QMessageBox::information(this, "Info", "User created successfully"); } diff --git a/sea_transport/adminpanel.h b/sea_transport/adminpanel.h index d3db004..8a729ce 100644 --- a/sea_transport/adminpanel.h +++ b/sea_transport/adminpanel.h @@ -16,13 +16,15 @@ #include "entities/user_entity.h" #include "entities/dpoint_entity.h" -namespace Ui { - class AdminPanel; -} + +namespace Ui { class AdminPanel; } class AdminPanel : public QMainWindow { +private: Q_OBJECT + Ui::AdminPanel *ui; + user_entity user; UsersViewModel *uvm; @@ -42,8 +44,6 @@ private slots: void on_user_set(); private: - Ui::AdminPanel *ui; - void on_logout_requested(); void on_vessel_add_edit(bool edit); diff --git a/sea_transport/authwindow.cpp b/sea_transport/authwindow.cpp index ecfe549..b7598d9 100644 --- a/sea_transport/authwindow.cpp +++ b/sea_transport/authwindow.cpp @@ -24,7 +24,7 @@ void AuthWindow::on_auth_requested() { bool success = false; auto a = apparatus::instance()->get_auth_subsystem(); - if (apparatus::isFirstRun()) { + if (apparatus::is_first_run()) { success = a->register_user(login, passw, UserRole::ADMINISTRATOR); if (!success) { QMessageBox::critical(this, "Error", "Cannot register you. Check filesystem permission"); @@ -61,9 +61,11 @@ void AuthWindow::on_auth_requested() { ((AdminPanel*) w)->set_user(*user); } else if (user->role() == UserRole::SKIPPER) { - QMessageBox::information(this, "Info", "Please note: if you have more than one vessel assigned to you " - "only first will be shown (it is intended by design, you cannot physically control two ships). \n" - "Please, ask your local dispatcher/administrator to unassign you from other vessels."); + QMessageBox::information(this, "Info", + "Please note: if you have more than one vessel assigned to you " + "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); ((SkipperPanel*) w)->set_user(*user); } diff --git a/sea_transport/authwindow.h b/sea_transport/authwindow.h index f438c65..bf7efb8 100644 --- a/sea_transport/authwindow.h +++ b/sea_transport/authwindow.h @@ -9,20 +9,20 @@ #include #include -namespace Ui { -class AuthWindow; -} + +namespace Ui { class AuthWindow; } class AuthWindow : public QMainWindow { +private: Q_OBJECT + Ui::AuthWindow *ui; + public: explicit AuthWindow(QWidget *parent = nullptr); ~AuthWindow(); private: - Ui::AuthWindow *ui; - void on_auth_requested(); }; diff --git a/sea_transport/cargoeditdialog.cpp b/sea_transport/cargoeditdialog.cpp index a55ba79..9730900 100644 --- a/sea_transport/cargoeditdialog.cpp +++ b/sea_transport/cargoeditdialog.cpp @@ -1,6 +1,7 @@ #include "cargoeditdialog.h" #include "ui_cargoeditdialog.h" + CargoEditDialog::CargoEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CargoEditDialog) { ui->setupUi(this); diff --git a/sea_transport/cargoeditdialog.h b/sea_transport/cargoeditdialog.h index fcab6ea..29822b1 100644 --- a/sea_transport/cargoeditdialog.h +++ b/sea_transport/cargoeditdialog.h @@ -6,11 +6,11 @@ #include "entities/cargo_entity.h" -namespace Ui { -class CargoEditDialog; -} + +namespace Ui { class CargoEditDialog; } class CargoEditDialog : public QDialog { +private: Q_OBJECT Ui::CargoEditDialog *ui; diff --git a/sea_transport/deliverypointeditdialog.cpp b/sea_transport/deliverypointeditdialog.cpp index c57d7e4..2954077 100644 --- a/sea_transport/deliverypointeditdialog.cpp +++ b/sea_transport/deliverypointeditdialog.cpp @@ -2,29 +2,34 @@ #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); 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->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; - } + 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(); - }); + 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); diff --git a/sea_transport/deliverypointeditdialog.h b/sea_transport/deliverypointeditdialog.h index 3eeb00b..8d1b9a7 100644 --- a/sea_transport/deliverypointeditdialog.h +++ b/sea_transport/deliverypointeditdialog.h @@ -13,19 +13,16 @@ #include "storageeditdialog.h" -namespace Ui { -class DeliveryPointEditDialog; -} +namespace Ui { class DeliveryPointEditDialog; } class DeliveryPointEditDialog : public QDialog { +private: Q_OBJECT Ui::DeliveryPointEditDialog *ui; QStringListModel *svm; dpoint_entity *_dp; - void update_list(); - public: explicit DeliveryPointEditDialog(QWidget *parent = nullptr); ~DeliveryPointEditDialog(); @@ -37,6 +34,9 @@ public slots: void on_storage_edit_add(bool edit); void accept() Q_DECL_OVERRIDE; + +private: + void update_list(); }; #endif // DELIVERYPOINTEDITDIALOG_H diff --git a/sea_transport/entities/cargo_entity.cpp b/sea_transport/entities/cargo_entity.cpp index 1fee72e..cd15fd0 100644 --- a/sea_transport/entities/cargo_entity.cpp +++ b/sea_transport/entities/cargo_entity.cpp @@ -7,7 +7,8 @@ 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; auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5); for (auto bit : hash) { diff --git a/sea_transport/entities/dpoint_entity.cpp b/sea_transport/entities/dpoint_entity.cpp index 13b7873..7b7a8eb 100644 --- a/sea_transport/entities/dpoint_entity.cpp +++ b/sea_transport/entities/dpoint_entity.cpp @@ -7,7 +7,8 @@ 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) { +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); for (auto bit : hash) { diff --git a/sea_transport/entities/user_entity.cpp b/sea_transport/entities/user_entity.cpp index 9d0e641..4089496 100644 --- a/sea_transport/entities/user_entity.cpp +++ b/sea_transport/entities/user_entity.cpp @@ -7,12 +7,15 @@ 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) { - this->_pwd_hash = QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha3_256); +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); foreach (auto bit, this->_pwd_hash) { 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 += QRandomGenerator().generate64(); @@ -31,11 +34,13 @@ UserRole user_entity::role() 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) { - 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) { diff --git a/sea_transport/entities/user_entity.h b/sea_transport/entities/user_entity.h index f3387a1..e382afc 100644 --- a/sea_transport/entities/user_entity.h +++ b/sea_transport/entities/user_entity.h @@ -12,7 +12,6 @@ enum class UserRole { ADMINISTRATOR, DISPATCHER, SKIPPER }; - class user_entity : public IEntity { private: static entity_id __global_id; diff --git a/sea_transport/entities/vessel_entity.cpp b/sea_transport/entities/vessel_entity.cpp index 383d116..8762b42 100644 --- a/sea_transport/entities/vessel_entity.cpp +++ b/sea_transport/entities/vessel_entity.cpp @@ -7,8 +7,10 @@ vessel_entity::vessel_entity() { 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(); +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 { diff --git a/sea_transport/main.cpp b/sea_transport/main.cpp index 5a92eef..89c4247 100644 --- a/sea_transport/main.cpp +++ b/sea_transport/main.cpp @@ -1,9 +1,9 @@ #include "authwindow.h" - #include "system/apparatus.h" #include + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -14,7 +14,8 @@ int main(int argc, char *argv[]) { QObject::connect(&a, &QApplication::aboutToQuit, []() { 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(); } }); diff --git a/sea_transport/skipperpanel.cpp b/sea_transport/skipperpanel.cpp index 8618d7f..a86ef48 100644 --- a/sea_transport/skipperpanel.cpp +++ b/sea_transport/skipperpanel.cpp @@ -5,7 +5,6 @@ SkipperPanel::SkipperPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::SkipperPanel) { ui->setupUi(this); - connect(ui->pb_logout, &QPushButton::clicked, this, &SkipperPanel::on_logout_requested); cvm = new CargoViewModel(this); @@ -52,23 +51,27 @@ void SkipperPanel::on_user_set() { } if (!success) { - QMessageBox::critical(this, "Error", "You are not assigned to vessel. \n" - "Ask you local dispatcher/administrator to do it. \n" - "System will now close."); + QMessageBox::critical(this, "Error", + "You are not assigned to vessel. \nAsk you local " + "dispatcher/administrator to do it. \nSystem will now close."); this->close(); } ui->lab_vid->setText(QString::number(vessel.id())); 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#"); int cap_used = 0; foreach (auto c, vessel.cargo()) { 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()); } diff --git a/sea_transport/skipperpanel.h b/sea_transport/skipperpanel.h index d82aa18..edce0fd 100644 --- a/sea_transport/skipperpanel.h +++ b/sea_transport/skipperpanel.h @@ -10,15 +10,16 @@ #include "entities/user_entity.h" #include "entities/vessel_entity.h" -namespace Ui { - class SkipperPanel; -} + +namespace Ui { class SkipperPanel; } class SkipperPanel : public QMainWindow { +private: Q_OBJECT - user_entity user; + Ui::SkipperPanel *ui; + user_entity user; CargoViewModel *cvm; public: @@ -34,8 +35,6 @@ private slots: void on_user_set(); private: - Ui::SkipperPanel *ui; - void on_logout_requested(); }; diff --git a/sea_transport/storageeditdialog.cpp b/sea_transport/storageeditdialog.cpp index e7426c0..8adeb6f 100644 --- a/sea_transport/storageeditdialog.cpp +++ b/sea_transport/storageeditdialog.cpp @@ -1,15 +1,19 @@ #include "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); 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->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(); diff --git a/sea_transport/storageeditdialog.h b/sea_transport/storageeditdialog.h index 372833a..95ae41d 100644 --- a/sea_transport/storageeditdialog.h +++ b/sea_transport/storageeditdialog.h @@ -10,11 +10,10 @@ #include "cargoeditdialog.h" -namespace Ui { -class StorageEditDialog; -} +namespace Ui { class StorageEditDialog; } class StorageEditDialog : public QDialog { +private: Q_OBJECT Ui::StorageEditDialog *ui; diff --git a/sea_transport/system/apparatus.cpp b/sea_transport/system/apparatus.cpp index d89d55a..75de92f 100644 --- a/sea_transport/system/apparatus.cpp +++ b/sea_transport/system/apparatus.cpp @@ -77,7 +77,7 @@ void apparatus::load() { f.close(); } -bool apparatus::isFirstRun() { +bool apparatus::is_first_run() { return !QFile().exists("lock"); } @@ -94,7 +94,7 @@ void apparatus::init() { throw std::runtime_error("System already initialized!"); } - bool fr = apparatus::isFirstRun(); + bool fr = apparatus::is_first_run(); apparatus::_instance = new apparatus(); if (fr) { @@ -111,9 +111,10 @@ void apparatus::init() { void apparatus::shutdown() { 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(); } -// delete apparatus::_instance; + apparatus::_instance = nullptr; } diff --git a/sea_transport/system/apparatus.h b/sea_transport/system/apparatus.h index 43ddeee..ff628e8 100644 --- a/sea_transport/system/apparatus.h +++ b/sea_transport/system/apparatus.h @@ -12,8 +12,7 @@ #include -class apparatus -{ +class apparatus { private: static apparatus *_instance; static const QString filename; @@ -31,7 +30,7 @@ public: void save(); void load(); - static bool isFirstRun(); + static bool is_first_run(); static void generate_lock_file(); static apparatus* instance(); static void init(); diff --git a/sea_transport/system/auth_system.h b/sea_transport/system/auth_system.h index 21dd056..8d0d3bf 100644 --- a/sea_transport/system/auth_system.h +++ b/sea_transport/system/auth_system.h @@ -6,8 +6,7 @@ #include "../entities/user_entity.h" -class auth_system -{ +class auth_system { private: QVector _users; public: diff --git a/sea_transport/system/object_system.h b/sea_transport/system/object_system.h index 7551201..40d09f1 100644 --- a/sea_transport/system/object_system.h +++ b/sea_transport/system/object_system.h @@ -7,8 +7,7 @@ #include "../entities/vessel_entity.h" -class object_system -{ +class object_system { private: QVector _dpoints; QVector _vessels; diff --git a/sea_transport/usereditdialog.cpp b/sea_transport/usereditdialog.cpp index bec2fa0..4308fd1 100644 --- a/sea_transport/usereditdialog.cpp +++ b/sea_transport/usereditdialog.cpp @@ -22,7 +22,7 @@ void UserEditDialog::set_user(user_entity* user, bool edit) { this->_user_data = new user_data_struct(); 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->setEnabled(false); } diff --git a/sea_transport/usereditdialog.h b/sea_transport/usereditdialog.h index ada392e..c352b50 100644 --- a/sea_transport/usereditdialog.h +++ b/sea_transport/usereditdialog.h @@ -7,9 +7,7 @@ #include "entities/user_entity.h" -namespace Ui { -class UserEditDialog; -} +namespace Ui { class UserEditDialog; } struct user_data_struct { QString login; @@ -19,6 +17,7 @@ struct user_data_struct { }; class UserEditDialog : public QDialog { +private: Q_OBJECT Ui::UserEditDialog *ui; diff --git a/sea_transport/vesseleditdialog.cpp b/sea_transport/vesseleditdialog.cpp index a49384a..925f16e 100644 --- a/sea_transport/vesseleditdialog.cpp +++ b/sea_transport/vesseleditdialog.cpp @@ -1,15 +1,19 @@ #include "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); 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->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(); @@ -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_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_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); @@ -116,11 +122,13 @@ void VesselEditDialog::on_cargo_add() { } 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"); + QMessageBox::information(this, "Note", + "Please note, old storage will be used.\nAlso, movement cannot be " + "undone by discarding vessel edit dialog"); 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) { QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB"); return; @@ -135,7 +143,8 @@ void VesselEditDialog::on_withdraw_from_harbor() { 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); + 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; @@ -156,7 +165,8 @@ void VesselEditDialog::on_withdraw_from_harbor() { 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); + 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; @@ -189,11 +199,13 @@ void VesselEditDialog::on_withdraw_from_vessel() { return; } - QMessageBox::information(this, "Note", "Please note, old storage will be used.\n" - "Also, movement cannot be undone by discarding vessel edit dialog"); + QMessageBox::information(this, "Note", + "Please note, old storage will be used.\nAlso, movement cannot be " + "undone by discarding vessel edit dialog"); 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) { QMessageBox::critical(this, "Error", "Cannot find associated harbor in DB"); return; @@ -204,7 +216,8 @@ void VesselEditDialog::on_withdraw_from_vessel() { 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); + 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; @@ -221,7 +234,8 @@ void VesselEditDialog::on_withdraw_from_vessel() { 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); + 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; diff --git a/sea_transport/vesseleditdialog.h b/sea_transport/vesseleditdialog.h index f616972..75f87dc 100644 --- a/sea_transport/vesseleditdialog.h +++ b/sea_transport/vesseleditdialog.h @@ -10,20 +10,17 @@ #include "viewmodels/cargoviewmodel.h" #include "cargoeditdialog.h" -namespace Ui { -class VesselEditDialog; -} + +namespace Ui { class VesselEditDialog; } class VesselEditDialog : public QDialog { +private: Q_OBJECT Ui::VesselEditDialog *ui; CargoViewModel *cvm; vessel_entity *_vessel; - void select_proper_skipper(); - void select_proper_port(); - public: explicit VesselEditDialog(QWidget *parent = nullptr); ~VesselEditDialog(); @@ -36,6 +33,10 @@ public slots: void on_withdraw_from_harbor(); void on_withdraw_from_vessel(); void accept() Q_DECL_OVERRIDE; + +private: + void select_proper_skipper(); + void select_proper_port(); }; #endif // VESSELEDITDIALOG_H diff --git a/sea_transport/viewmodels/cargoviewmodel.cpp b/sea_transport/viewmodels/cargoviewmodel.cpp index ef6621a..ee60b4d 100644 --- a/sea_transport/viewmodels/cargoviewmodel.cpp +++ b/sea_transport/viewmodels/cargoviewmodel.cpp @@ -1,5 +1,6 @@ #include "cargoviewmodel.h" + CargoViewModel::CargoViewModel(QObject *parent) : QAbstractTableModel(parent) { } diff --git a/sea_transport/viewmodels/cargoviewmodel.h b/sea_transport/viewmodels/cargoviewmodel.h index 26db7b1..4190382 100644 --- a/sea_transport/viewmodels/cargoviewmodel.h +++ b/sea_transport/viewmodels/cargoviewmodel.h @@ -6,7 +6,9 @@ #include "entities/cargo_entity.h" + class CargoViewModel : public QAbstractTableModel { +private: Q_OBJECT QVector _data; diff --git a/sea_transport/viewmodels/deliverypointsviewmodel.cpp b/sea_transport/viewmodels/deliverypointsviewmodel.cpp index 487e768..621e6dc 100644 --- a/sea_transport/viewmodels/deliverypointsviewmodel.cpp +++ b/sea_transport/viewmodels/deliverypointsviewmodel.cpp @@ -1,5 +1,6 @@ #include "deliverypointsviewmodel.h" + DeliveryPointsViewModel::DeliveryPointsViewModel(QObject *parent) : QAbstractTableModel(parent) { } @@ -12,7 +13,8 @@ int DeliveryPointsViewModel::columnCount(const QModelIndex &/*parent*/) const { 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) { switch (section) { case 0: diff --git a/sea_transport/viewmodels/deliverypointsviewmodel.h b/sea_transport/viewmodels/deliverypointsviewmodel.h index bfbfb40..d7c836d 100644 --- a/sea_transport/viewmodels/deliverypointsviewmodel.h +++ b/sea_transport/viewmodels/deliverypointsviewmodel.h @@ -5,7 +5,9 @@ #include + class DeliveryPointsViewModel : public QAbstractTableModel { +private: Q_OBJECT public: diff --git a/sea_transport/viewmodels/usersviewmodel.cpp b/sea_transport/viewmodels/usersviewmodel.cpp index 9269d34..dbde3ad 100644 --- a/sea_transport/viewmodels/usersviewmodel.cpp +++ b/sea_transport/viewmodels/usersviewmodel.cpp @@ -1,5 +1,6 @@ #include "usersviewmodel.h" + UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) { } diff --git a/sea_transport/viewmodels/usersviewmodel.h b/sea_transport/viewmodels/usersviewmodel.h index 40e3813..e0693e6 100644 --- a/sea_transport/viewmodels/usersviewmodel.h +++ b/sea_transport/viewmodels/usersviewmodel.h @@ -5,7 +5,9 @@ #include + class UsersViewModel : public QAbstractTableModel { +private: Q_OBJECT public: diff --git a/sea_transport/viewmodels/vesselsviewmodel.cpp b/sea_transport/viewmodels/vesselsviewmodel.cpp index bbfeef5..a34d33b 100644 --- a/sea_transport/viewmodels/vesselsviewmodel.cpp +++ b/sea_transport/viewmodels/vesselsviewmodel.cpp @@ -1,5 +1,6 @@ #include "vesselsviewmodel.h" + 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 { 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); + bool s = false; + auto harbor = apparatus::instance()->get_object_subsystem()->get_dpoint(item.harbor(), s); int col = index.column(); switch (col) { @@ -45,7 +46,7 @@ QVariant VesselsViewModel::data(const QModelIndex &index, int role) const { case 1: return item.skipper(); case 2: - return (hs? harbor->title() : tr("##ERROR[%1]##").arg(item.harbor())); + return (s? harbor->title() : tr("##ERROR[%1]##").arg(item.harbor())); case 3: return item.capacity(); case 4: diff --git a/sea_transport/viewmodels/vesselsviewmodel.h b/sea_transport/viewmodels/vesselsviewmodel.h index b861fb9..b50aba0 100644 --- a/sea_transport/viewmodels/vesselsviewmodel.h +++ b/sea_transport/viewmodels/vesselsviewmodel.h @@ -5,7 +5,9 @@ #include + class VesselsViewModel : public QAbstractTableModel { +private: Q_OBJECT public: diff --git a/sea_transport_project.pro.user b/sea_transport_project.pro.user index 18d2d69..f11e8c6 100644 --- a/sea_transport_project.pro.user +++ b/sea_transport_project.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -64,7 +64,26 @@ true true - + + Checked + Checked + Checked + Checked + Checked + Checked + Checked + Unchecked + Checked + Unchecked + Checked + Checked + Checked + Checked + Checked + Checked + Checked + Checked + 0 true diff --git a/st_test/tst_st_test.cpp b/st_test/tst_st_test.cpp index cec13f8..9667421 100644 --- a/st_test/tst_st_test.cpp +++ b/st_test/tst_st_test.cpp @@ -249,7 +249,7 @@ void st_test::apparatus_check_null_throws_error() { void st_test::apparatus_check_first_run() { apparatus::init(); - QVERIFY(apparatus::instance()->isFirstRun()); + QVERIFY(apparatus::instance()->is_first_run()); apparatus::shutdown(); } @@ -265,7 +265,7 @@ void st_test::apparatus_check_first_registration() { void st_test::apparatus_check_not_first_run() { apparatus::init(); - QVERIFY(!apparatus::instance()->isFirstRun()); + QVERIFY(!apparatus::instance()->is_first_run()); apparatus::shutdown(); }