diff --git a/sea_transport/authwindow.cpp b/sea_transport/authwindow.cpp index 1002bdb..ecfe549 100644 --- a/sea_transport/authwindow.cpp +++ b/sea_transport/authwindow.cpp @@ -61,8 +61,11 @@ void AuthWindow::on_auth_requested() { ((AdminPanel*) w)->set_user(*user); } else if (user->role() == UserRole::SKIPPER) { - // SkipperPanel(nullptr, user).set_user(user).show(); - return; + 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."); + w = new SkipperPanel(nullptr); + ((SkipperPanel*) w)->set_user(*user); } else { QMessageBox::critical(this, "Error", "Deserialized user have wrong type. " diff --git a/sea_transport/authwindow.h b/sea_transport/authwindow.h index e0f174e..f438c65 100644 --- a/sea_transport/authwindow.h +++ b/sea_transport/authwindow.h @@ -4,6 +4,7 @@ #include "system/apparatus.h" #include "adminpanel.h" +#include "skipperpanel.h" #include #include diff --git a/sea_transport/sea_transport.pro b/sea_transport/sea_transport.pro index 99e2c50..93ae602 100644 --- a/sea_transport/sea_transport.pro +++ b/sea_transport/sea_transport.pro @@ -19,6 +19,7 @@ SOURCES += \ entities/user_entity.cpp \ entities/vessel_entity.cpp \ main.cpp \ + skipperpanel.cpp \ storageeditdialog.cpp \ system/apparatus.cpp \ system/auth_system.cpp \ @@ -42,6 +43,7 @@ HEADERS += \ entities/storage_entity.h \ entities/user_entity.h \ entities/vessel_entity.h \ + skipperpanel.h \ storageeditdialog.h \ system/apparatus.h \ system/auth_system.h \ @@ -58,6 +60,7 @@ FORMS += \ authwindow.ui \ cargoeditdialog.ui \ deliverypointeditdialog.ui \ + skipperpanel.ui \ storageeditdialog.ui \ usereditdialog.ui \ vesseleditdialog.ui diff --git a/sea_transport/skipperpanel.cpp b/sea_transport/skipperpanel.cpp new file mode 100644 index 0000000..8618d7f --- /dev/null +++ b/sea_transport/skipperpanel.cpp @@ -0,0 +1,78 @@ +#include "skipperpanel.h" +#include "ui_skipperpanel.h" + + +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); + ui->tv_cargo->setModel(this->cvm); + + connect(this, &SkipperPanel::user_set, this, &SkipperPanel::on_user_set); +} + +SkipperPanel::~SkipperPanel() { + delete ui; + + delete cvm; +} + +SkipperPanel& SkipperPanel::set_user(const user_entity &user) { + this->user = user; + ui->lab_user->setText(tr("Hello, **%1**").arg(user.login())); + + emit user_set(); + + return *this; +} + +void SkipperPanel::on_user_set() { + UserRole urole = this->user.role(); + switch (urole) { + case UserRole::ADMINISTRATOR: + case UserRole::DISPATCHER: + QMessageBox::critical(this, "Error", "You shouldn't be here!"); + close(); + return; + case UserRole::SKIPPER: + break; + } + + bool success = false; + vessel_entity vessel; + foreach(auto _vessel, apparatus::instance()->get_object_subsystem()->vessels()) { + if (_vessel.skipper() == this->user.login()) { + success = true; + vessel = _vessel; + break; + } + } + + 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."); + 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); + 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())); + + this->cvm->set_data(vessel.cargo()); +} + +void SkipperPanel::on_logout_requested() { + this->close(); +} diff --git a/sea_transport/skipperpanel.h b/sea_transport/skipperpanel.h new file mode 100644 index 0000000..d82aa18 --- /dev/null +++ b/sea_transport/skipperpanel.h @@ -0,0 +1,42 @@ +#ifndef SKIPPERPANEL_H +#define SKIPPERPANEL_H + +#include +#include +#include + +#include "system/apparatus.h" +#include "viewmodels/cargoviewmodel.h" +#include "entities/user_entity.h" +#include "entities/vessel_entity.h" + +namespace Ui { + class SkipperPanel; +} + +class SkipperPanel : public QMainWindow { + Q_OBJECT + + user_entity user; + + CargoViewModel *cvm; + +public: + explicit SkipperPanel(QWidget *parent = nullptr); + ~SkipperPanel(); + + SkipperPanel& set_user(const user_entity &user); + +signals: + void user_set(); + +private slots: + void on_user_set(); + +private: + Ui::SkipperPanel *ui; + + void on_logout_requested(); +}; + +#endif // SKIPPERPANEL_H diff --git a/sea_transport/skipperpanel.ui b/sea_transport/skipperpanel.ui new file mode 100644 index 0000000..30aad65 --- /dev/null +++ b/sea_transport/skipperpanel.ui @@ -0,0 +1,151 @@ + + + SkipperPanel + + + + 0 + 0 + 560 + 337 + + + + MainWindow + + + + + + + + 0 + 0 + + + + Logout + + + + + + + Hello, %1 + + + Qt::MarkdownText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Vessel info + + + + + + VID: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + + + + Capacity (used/left/max): + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + + + + Harbor: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Vessel cargo + + + + + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + + + + + + + + + + + +