Code style refactoring done
This commit is contained in:
parent
02766bd5d2
commit
c5f1572efa
36 changed files with 202 additions and 130 deletions
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,20 +9,20 @@
|
|||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "cargoeditdialog.h"
|
||||
#include "ui_cargoeditdialog.h"
|
||||
|
||||
|
||||
CargoEditDialog::CargoEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CargoEditDialog) {
|
||||
ui->setupUi(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ enum class UserRole {
|
|||
ADMINISTRATOR, DISPATCHER, SKIPPER
|
||||
};
|
||||
|
||||
|
||||
class user_entity : public IEntity {
|
||||
private:
|
||||
static entity_id __global_id;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include "authwindow.h"
|
||||
|
||||
#include "system/apparatus.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
#include <QDataStream>
|
||||
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
#include "../entities/user_entity.h"
|
||||
|
||||
|
||||
class auth_system
|
||||
{
|
||||
class auth_system {
|
||||
private:
|
||||
QVector<user_entity> _users;
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
#include "../entities/vessel_entity.h"
|
||||
|
||||
|
||||
class object_system
|
||||
{
|
||||
class object_system {
|
||||
private:
|
||||
QVector<dpoint_entity> _dpoints;
|
||||
QVector<vessel_entity> _vessels;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "cargoviewmodel.h"
|
||||
|
||||
|
||||
CargoViewModel::CargoViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include "entities/cargo_entity.h"
|
||||
|
||||
|
||||
class CargoViewModel : public QAbstractTableModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
QVector<cargo_entity> _data;
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
|
||||
class DeliveryPointsViewModel : public QAbstractTableModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "usersviewmodel.h"
|
||||
|
||||
|
||||
UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
|
||||
class UsersViewModel : public QAbstractTableModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
|
||||
class VesselsViewModel : public QAbstractTableModel {
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue