Add skipper view render code
This commit is contained in:
parent
a8e4b10d07
commit
05ac14f748
3 changed files with 94 additions and 12 deletions
|
|
@ -1,14 +1,76 @@
|
||||||
#include "skipperpanel.h"
|
#include "skipperpanel.h"
|
||||||
#include "ui_skipperpanel.h"
|
#include "ui_skipperpanel.h"
|
||||||
|
|
||||||
SkipperPanel::SkipperPanel(QWidget *parent) :
|
|
||||||
QMainWindow(parent),
|
SkipperPanel::SkipperPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::SkipperPanel) {
|
||||||
ui(new Ui::SkipperPanel)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
||||||
|
connect(ui->pb_logout, &QPushButton::clicked, this, &SkipperPanel::on_logout_requested);
|
||||||
|
|
||||||
|
cvm = new CargoViewModel(this);
|
||||||
|
ui->tv_cargo->setModel(this->cvm);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipperPanel::~SkipperPanel()
|
SkipperPanel::~SkipperPanel() {
|
||||||
{
|
|
||||||
delete ui;
|
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, vessel.capacity(), vessel.capacity() + cap_used));
|
||||||
|
|
||||||
|
this->cvm->set_data(vessel.cargo());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkipperPanel::on_logout_requested() {
|
||||||
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,41 @@
|
||||||
#define SKIPPERPANEL_H
|
#define SKIPPERPANEL_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "system/apparatus.h"
|
||||||
|
#include "viewmodels/cargoviewmodel.h"
|
||||||
|
#include "entities/user_entity.h"
|
||||||
|
#include "entities/vessel_entity.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class SkipperPanel;
|
class SkipperPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SkipperPanel : public QMainWindow
|
class SkipperPanel : public QMainWindow {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
user_entity user;
|
||||||
|
|
||||||
|
CargoViewModel *cvm;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SkipperPanel(QWidget *parent = nullptr);
|
explicit SkipperPanel(QWidget *parent = nullptr);
|
||||||
~SkipperPanel();
|
~SkipperPanel();
|
||||||
|
|
||||||
|
SkipperPanel& set_user(const user_entity &user);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void user_set();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_user_set();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SkipperPanel *ui;
|
Ui::SkipperPanel *ui;
|
||||||
|
|
||||||
|
void on_logout_requested();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SKIPPERPANEL_H
|
#endif // SKIPPERPANEL_H
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@
|
||||||
<item row="0" column="2">
|
<item row="0" column="2">
|
||||||
<widget class="QLabel" name="lab_vid">
|
<widget class="QLabel" name="lab_vid">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>####</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Capacity (left/max):</string>
|
<string>Capacity (used/left/max):</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
|
|
@ -87,7 +87,7 @@
|
||||||
<item row="2" column="2">
|
<item row="2" column="2">
|
||||||
<widget class="QLabel" name="lab_capacity">
|
<widget class="QLabel" name="lab_capacity">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>####</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
|
@ -114,7 +114,7 @@
|
||||||
<item row="4" column="1" colspan="2">
|
<item row="4" column="1" colspan="2">
|
||||||
<widget class="QLabel" name="lab_harbor">
|
<widget class="QLabel" name="lab_harbor">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>####</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue