Delivery point editor done
This commit is contained in:
parent
a6c080d36b
commit
3e196f3574
22 changed files with 379 additions and 74 deletions
|
|
@ -78,7 +78,7 @@ void AdminPanel::on_logout_requested() {
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_vessel_add_edit(bool edit) {
|
void AdminPanel::on_vessel_add_edit(bool /*edit*/) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ void AdminPanel::on_user_add_edit(bool edit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = ued.user();
|
auto data = ued.user_data();
|
||||||
if (edit) {
|
if (edit) {
|
||||||
bool success;
|
bool success;
|
||||||
auto user = apparatus::instance()->get_auth_subsystem()->get_user(usr.login(), success);
|
auto user = apparatus::instance()->get_auth_subsystem()->get_user(usr.login(), success);
|
||||||
|
|
@ -188,7 +188,41 @@ void AdminPanel::on_user_remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_delivery_point_add_edit(bool edit) {
|
void AdminPanel::on_delivery_point_add_edit(bool edit) {
|
||||||
|
auto selected = ui->tv_dp->selectionModel()->selectedRows();
|
||||||
|
if (edit && selected.length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dpoint_entity dpoint;
|
||||||
|
if (edit) {
|
||||||
|
int idx = selected[0].row();
|
||||||
|
dpoint = apparatus::instance()->get_object_subsystem()->dpoints()[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
DeliveryPointEditDialog dped(this);
|
||||||
|
dped.setWindowTitle(edit? "Edit delivery point" : "New delivery point");
|
||||||
|
dped.set_dpoint(&dpoint, edit);
|
||||||
|
if (dped.exec() != UserEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = dped.dpoint();
|
||||||
|
if (edit) {
|
||||||
|
bool success;
|
||||||
|
auto dp = apparatus::instance()->get_object_subsystem()->get_dpoint(dpoint.id(), success);
|
||||||
|
if (!success) {
|
||||||
|
QMessageBox::critical(this, "Error", "Error editing delivery point");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dp->set_title(data->title());
|
||||||
|
dp->set_storages(data->storages());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
apparatus::instance()->get_object_subsystem()->add_dpoint(*data);
|
||||||
|
}
|
||||||
|
|
||||||
|
dpvm->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminPanel::on_delivery_point_remove() {
|
void AdminPanel::on_delivery_point_remove() {
|
||||||
|
|
@ -208,8 +242,8 @@ void AdminPanel::on_delivery_point_remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (auto mIdx, selected) {
|
foreach (auto mIdx, selected) {
|
||||||
int idx = mIdx.row();
|
entity_id oid = mIdx.data().toULongLong();
|
||||||
qDebug() << idx << ' ' << mIdx.data() << '\n';
|
apparatus::instance()->get_object_subsystem()->remove_dpoint(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
dpvm->update();
|
dpvm->update();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "viewmodels/deliverypointsviewmodel.h"
|
#include "viewmodels/deliverypointsviewmodel.h"
|
||||||
|
|
||||||
#include "entities/user_entity.h"
|
#include "entities/user_entity.h"
|
||||||
|
#include "entities/dpoint_entity.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class AdminPanel;
|
class AdminPanel;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &CargoEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &CargoEditDialog::reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
CargoEditDialog::~CargoEditDialog() {
|
CargoEditDialog::~CargoEditDialog() {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,116 @@
|
||||||
#include "deliverypointeditdialog.h"
|
#include "deliverypointeditdialog.h"
|
||||||
#include "ui_deliverypointeditdialog.h"
|
#include "ui_deliverypointeditdialog.h"
|
||||||
|
|
||||||
DeliveryPointEditDialog::DeliveryPointEditDialog(QWidget *parent) :
|
|
||||||
QDialog(parent),
|
DeliveryPointEditDialog::DeliveryPointEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DeliveryPointEditDialog) {
|
||||||
ui(new Ui::DeliveryPointEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
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->pb_storage_remove, &QPushButton::clicked, [this]() {
|
||||||
|
auto sel = ui->lv_storages->selectionModel()->selectedRows();
|
||||||
|
if (sel.length() == 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeliveryPointEditDialog::~DeliveryPointEditDialog()
|
foreach (auto mIdx, sel) {
|
||||||
{
|
auto cuid = mIdx.data().toString().toULongLong();
|
||||||
|
auto st = this->_dp->storages();
|
||||||
|
|
||||||
|
for (int i = 0; i < st.length(); i++) {
|
||||||
|
if (st[i].id() == cuid) {
|
||||||
|
st.removeAt(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_dp->set_storages(st);
|
||||||
|
}
|
||||||
|
this->update_list();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_storage_edit, &QPushButton::clicked, [this]() {
|
||||||
|
this->on_storage_edit_add(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_storage_add, &QPushButton::clicked, [this]() {
|
||||||
|
this->on_storage_edit_add(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &DeliveryPointEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &DeliveryPointEditDialog::reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeliveryPointEditDialog::~DeliveryPointEditDialog() {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::update_list() {
|
||||||
|
QStringList slist;
|
||||||
|
foreach (auto storage, this->_dp->storages()) {
|
||||||
|
slist << QString::number(storage.id());
|
||||||
|
}
|
||||||
|
this->svm->setStringList(slist);
|
||||||
|
}
|
||||||
|
|
||||||
|
dpoint_entity* DeliveryPointEditDialog::dpoint() const {
|
||||||
|
return this->_dp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::on_storage_edit_add(bool edit) {
|
||||||
|
auto selected = ui->lv_storages->selectionModel()->selectedRows();
|
||||||
|
if (edit && selected.length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_entity stor;
|
||||||
|
if (edit) {
|
||||||
|
int idx = selected[0].row();
|
||||||
|
stor = this->_dp->storages()[idx];
|
||||||
|
this->_dp->remove_storage(stor.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
StorageEditDialog sed(this);
|
||||||
|
sed.setWindowTitle(edit? "Edit storage" : "New storage");
|
||||||
|
sed.set_storage(&stor, edit);
|
||||||
|
if (sed.exec() != StorageEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto n_storage = sed.storage();
|
||||||
|
if (edit) {
|
||||||
|
this->_dp->remove_storage(stor.id());
|
||||||
|
}
|
||||||
|
this->_dp->add_storage(*n_storage);
|
||||||
|
|
||||||
|
this->update_list();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::set_dpoint(dpoint_entity* dpoint, bool edit) {
|
||||||
|
this->_dp = new dpoint_entity(*dpoint);
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
ui->et_title->setText(dpoint->title());
|
||||||
|
this->update_list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeliveryPointEditDialog::accept() {
|
||||||
|
bool emptyTitle = ui->et_title->text().trimmed().isEmpty();
|
||||||
|
if (emptyTitle) {;
|
||||||
|
QString message = "Some errors happend, while saving your note:"
|
||||||
|
"<br>- Title cannot be empty (all spaces - empty too)";
|
||||||
|
QMessageBox::critical(this, "Error", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_dp->set_title(ui->et_title->text().trimmed());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,42 @@
|
||||||
#ifndef DELIVERYPOINTEDITDIALOG_H
|
#ifndef DELIVERYPOINTEDITDIALOG_H
|
||||||
#define DELIVERYPOINTEDITDIALOG_H
|
#define DELIVERYPOINTEDITDIALOG_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
#include "entities/dpoint_entity.h"
|
||||||
|
#include "system/apparatus.h"
|
||||||
|
#include "storageeditdialog.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DeliveryPointEditDialog;
|
class DeliveryPointEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeliveryPointEditDialog : public QDialog
|
class DeliveryPointEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::DeliveryPointEditDialog *ui;
|
||||||
|
|
||||||
|
QStringListModel *svm;
|
||||||
|
dpoint_entity *_dp;
|
||||||
|
|
||||||
|
void update_list();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeliveryPointEditDialog(QWidget *parent = nullptr);
|
explicit DeliveryPointEditDialog(QWidget *parent = nullptr);
|
||||||
~DeliveryPointEditDialog();
|
~DeliveryPointEditDialog();
|
||||||
|
|
||||||
private:
|
dpoint_entity* dpoint() const;
|
||||||
Ui::DeliveryPointEditDialog *ui;
|
void set_dpoint(dpoint_entity* dpoint, bool edit);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_storage_edit_add(bool edit);
|
||||||
|
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DELIVERYPOINTEDITDIALOG_H
|
#endif // DELIVERYPOINTEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -44,19 +44,33 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="lv_storages"/>
|
<widget class="QListView" name="lv_storages">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_storage_add">
|
<widget class="QPushButton" name="pb_storage_add">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add storage</string>
|
<string>Add storage</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_storage_remove">
|
<widget class="QPushButton" name="pb_storage_edit">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Edit storage</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_storage_remove">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -83,14 +97,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,28 @@ QString dpoint_entity::title() const {
|
||||||
return this->_title;
|
return this->_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::set_title(const QString &new_title) {
|
||||||
|
this->_title = new_title;
|
||||||
|
}
|
||||||
|
|
||||||
const QVector<storage_entity> dpoint_entity::storages() {
|
const QVector<storage_entity> dpoint_entity::storages() {
|
||||||
return this->_storages;
|
return this->_storages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::set_storages(QVector<storage_entity> storages) {
|
||||||
|
this->_storages = storages;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::remove_storage(entity_id sid) {
|
||||||
|
std::remove_if(this->_storages.begin(), this->_storages.end(), [sid](storage_entity ent) {
|
||||||
|
return ent.id() == sid;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void dpoint_entity::add_storage(storage_entity ent) {
|
||||||
|
this->_storages.push_back(ent);
|
||||||
|
}
|
||||||
|
|
||||||
void dpoint_entity::serialize(QDataStream &output) {
|
void dpoint_entity::serialize(QDataStream &output) {
|
||||||
output << this->_id << this->_title << this->_storages.size();
|
output << this->_id << this->_title << this->_storages.size();
|
||||||
for (auto &item : this->_storages) {
|
for (auto &item : this->_storages) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,11 @@ public:
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
entity_id dispatcher() const;
|
entity_id dispatcher() const;
|
||||||
QString title() const;
|
QString title() const;
|
||||||
|
void set_title(const QString &new_title);
|
||||||
const QVector<storage_entity> storages();
|
const QVector<storage_entity> storages();
|
||||||
|
void set_storages(QVector<storage_entity> storages);
|
||||||
|
void remove_storage(entity_id sid);
|
||||||
|
void add_storage(storage_entity ent);
|
||||||
|
|
||||||
void serialize(QDataStream &output);
|
void serialize(QDataStream &output);
|
||||||
void deserialize(QDataStream &input);
|
void deserialize(QDataStream &input);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ unsigned int storage_entity::capacity() const {
|
||||||
return this->_capacity;
|
return this->_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void storage_entity::set_capacity(unsigned int new_capacity) {
|
||||||
|
this->_capacity = new_capacity;
|
||||||
|
}
|
||||||
|
|
||||||
const QVector<cargo_entity> storage_entity::cargo() {
|
const QVector<cargo_entity> storage_entity::cargo() {
|
||||||
return this->_cargo;
|
return this->_cargo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public:
|
||||||
|
|
||||||
entity_id id() const;
|
entity_id id() const;
|
||||||
unsigned int capacity() const;
|
unsigned int capacity() const;
|
||||||
|
void set_capacity(unsigned int new_capacity);
|
||||||
const QVector<cargo_entity> cargo();
|
const QVector<cargo_entity> cargo();
|
||||||
|
|
||||||
void add_cargo(cargo_entity object, bool &success);
|
void add_cargo(cargo_entity object, bool &success);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ SOURCES += \
|
||||||
system/object_system.cpp \
|
system/object_system.cpp \
|
||||||
usereditdialog.cpp \
|
usereditdialog.cpp \
|
||||||
vesseleditdialog.cpp \
|
vesseleditdialog.cpp \
|
||||||
|
viewmodels/cargoviewmodel.cpp \
|
||||||
viewmodels/deliverypointsviewmodel.cpp \
|
viewmodels/deliverypointsviewmodel.cpp \
|
||||||
viewmodels/usersviewmodel.cpp \
|
viewmodels/usersviewmodel.cpp \
|
||||||
viewmodels/vesselsviewmodel.cpp
|
viewmodels/vesselsviewmodel.cpp
|
||||||
|
|
@ -47,6 +48,7 @@ HEADERS += \
|
||||||
system/object_system.h \
|
system/object_system.h \
|
||||||
usereditdialog.h \
|
usereditdialog.h \
|
||||||
vesseleditdialog.h \
|
vesseleditdialog.h \
|
||||||
|
viewmodels/cargoviewmodel.h \
|
||||||
viewmodels/deliverypointsviewmodel.h \
|
viewmodels/deliverypointsviewmodel.h \
|
||||||
viewmodels/usersviewmodel.h \
|
viewmodels/usersviewmodel.h \
|
||||||
viewmodels/vesselsviewmodel.h
|
viewmodels/vesselsviewmodel.h
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,80 @@
|
||||||
#include "storageeditdialog.h"
|
#include "storageeditdialog.h"
|
||||||
#include "ui_storageeditdialog.h"
|
#include "ui_storageeditdialog.h"
|
||||||
|
|
||||||
StorageEditDialog::StorageEditDialog(QWidget *parent) :
|
StorageEditDialog::StorageEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StorageEditDialog) {
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::StorageEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
this->cvm = new CargoViewModel(this);
|
||||||
|
ui->lv_cargo->setModel(this->cvm);
|
||||||
|
|
||||||
|
connect(ui->lv_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->lv_cargo->selectionModel()->selectedRows();
|
||||||
|
if (sel.length() == 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageEditDialog::~StorageEditDialog()
|
foreach (auto mIdx, sel) {
|
||||||
{
|
auto cdata = mIdx.data().toInt();
|
||||||
|
qDebug() << cdata << '\n';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->pb_cargo_add, &QPushButton::clicked, this, &StorageEditDialog::on_cargo_add);
|
||||||
|
|
||||||
|
connect(ui->pb_save, &QPushButton::clicked, this, &StorageEditDialog::accept);
|
||||||
|
connect(ui->pb_discard, &QPushButton::clicked, this, &StorageEditDialog::reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
StorageEditDialog::~StorageEditDialog() {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_entity* StorageEditDialog::storage() {
|
||||||
|
return this->_storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageEditDialog::set_storage(storage_entity *ent, bool edit) {
|
||||||
|
this->_storage = new storage_entity(*ent);
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
ui->sb_capacity->setValue(ent->capacity());
|
||||||
|
this->cvm->set_data(this->_storage->cargo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageEditDialog::on_cargo_add() {
|
||||||
|
CargoEditDialog ced(this);
|
||||||
|
ced.setWindowTitle("New cargo");
|
||||||
|
if (ced.exec() != CargoEditDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
this->_storage->add_cargo(*ced.cargo(), success);
|
||||||
|
if (success) {
|
||||||
|
this->cvm->set_data(this->_storage->cargo());
|
||||||
|
QMessageBox::information(this, "Success", "Cargo successfully put into storage");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::critical(this, "Error", "Not enough space to put cargo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageEditDialog::accept() {
|
||||||
|
int cvs = 0;
|
||||||
|
foreach (auto c, this->_storage->cargo()) {
|
||||||
|
cvs += c.volume();
|
||||||
|
}
|
||||||
|
if (cvs > ui->sb_capacity->value()) {
|
||||||
|
QMessageBox::critical(this, "Error", "Cargo volume bigger than capacity");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_storage->set_capacity(ui->sb_capacity->value());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,36 @@
|
||||||
#ifndef STORAGEEDITDIALOG_H
|
#ifndef STORAGEEDITDIALOG_H
|
||||||
#define STORAGEEDITDIALOG_H
|
#define STORAGEEDITDIALOG_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "entities/storage_entity.h"
|
||||||
|
#include "viewmodels/cargoviewmodel.h"
|
||||||
|
#include "cargoeditdialog.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class StorageEditDialog;
|
class StorageEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StorageEditDialog : public QDialog
|
class StorageEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::StorageEditDialog *ui;
|
||||||
|
|
||||||
|
CargoViewModel *cvm;
|
||||||
|
storage_entity *_storage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StorageEditDialog(QWidget *parent = nullptr);
|
explicit StorageEditDialog(QWidget *parent = nullptr);
|
||||||
~StorageEditDialog();
|
~StorageEditDialog();
|
||||||
|
|
||||||
private:
|
storage_entity* storage();
|
||||||
Ui::StorageEditDialog *ui;
|
void set_storage(storage_entity *ent, bool edit);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_cargo_add();
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STORAGEEDITDIALOG_H
|
#endif // STORAGEEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>190</height>
|
<height>336</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
|
@ -17,24 +17,45 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Storage num.:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLineEdit" name="et_storage_num"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Capacity:</string>
|
<string>Capacity:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="et_capacity"/>
|
<widget class="QSpinBox" name="sb_capacity">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>500</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListView" name="lv_cargo"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_cargo_add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add cargo</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_cargo_remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove cargo</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -54,14 +75,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "object_system.h"
|
#include "object_system.h"
|
||||||
|
|
||||||
|
|
||||||
const dpoint_entity* object_system::get_dpoint(entity_id oid, bool &success) {
|
dpoint_entity* object_system::get_dpoint(entity_id oid, bool &success) {
|
||||||
dpoint_entity *out = nullptr;
|
dpoint_entity *out = nullptr;
|
||||||
|
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -39,7 +39,7 @@ bool object_system::add_dpoint(dpoint_entity dpoint) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vessel_entity* object_system::get_vessel(entity_id oid, bool &success) {
|
vessel_entity* object_system::get_vessel(entity_id oid, bool &success) {
|
||||||
vessel_entity *out = nullptr;
|
vessel_entity *out = nullptr;
|
||||||
|
|
||||||
success = false;
|
success = false;
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ private:
|
||||||
public:
|
public:
|
||||||
object_system() = default;
|
object_system() = default;
|
||||||
|
|
||||||
const dpoint_entity* get_dpoint(entity_id oid, bool &success);
|
dpoint_entity* get_dpoint(entity_id oid, bool &success);
|
||||||
bool remove_dpoint(entity_id oid);
|
bool remove_dpoint(entity_id oid);
|
||||||
bool add_dpoint(dpoint_entity dpoint);
|
bool add_dpoint(dpoint_entity dpoint);
|
||||||
|
|
||||||
const vessel_entity* get_vessel(entity_id oid, bool &success);
|
vessel_entity* get_vessel(entity_id oid, bool &success);
|
||||||
bool remove_vessel(entity_id oid);
|
bool remove_vessel(entity_id oid);
|
||||||
bool add_vessel(vessel_entity dpoint);
|
bool add_vessel(vessel_entity dpoint);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "usereditdialog.h"
|
#include "usereditdialog.h"
|
||||||
#include "ui_usereditdialog.h"
|
#include "ui_usereditdialog.h"
|
||||||
|
|
||||||
|
|
||||||
UserEditDialog::UserEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::UserEditDialog) {
|
UserEditDialog::UserEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::UserEditDialog) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
@ -12,24 +13,22 @@ UserEditDialog::~UserEditDialog() {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserEditDialog::user_data* UserEditDialog::user() const {
|
user_data_struct* UserEditDialog::user_data() const {
|
||||||
return this->_user;
|
return this->_user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserEditDialog::set_user(user_entity* user, bool edit) {
|
void UserEditDialog::set_user(user_entity* user, bool edit) {
|
||||||
if (edit) {
|
if (edit) {
|
||||||
this->_user = new UserEditDialog::user_data {
|
this->_user_data = new user_data_struct();
|
||||||
user->login(), "", user->role(), true
|
|
||||||
};
|
|
||||||
|
|
||||||
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());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->_user = new UserEditDialog::user_data{};
|
this->_user_data = new user_data_struct{};
|
||||||
}
|
}
|
||||||
this->_user->edit = edit;
|
this->_user_data->edit = edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserEditDialog::accept() {
|
void UserEditDialog::accept() {
|
||||||
|
|
@ -47,7 +46,7 @@ void UserEditDialog::accept() {
|
||||||
}
|
}
|
||||||
bool emptyTitle = ui->et_login->text().trimmed().isEmpty();
|
bool emptyTitle = ui->et_login->text().trimmed().isEmpty();
|
||||||
bool emptyPassword = ui->et_password->text().trimmed().isEmpty();
|
bool emptyPassword = ui->et_password->text().trimmed().isEmpty();
|
||||||
bool lowerank = this->_user->edit && this->_user->role < role;
|
bool lowerank = this->_user_data->edit && this->_user_data->role < role;
|
||||||
if (emptyTitle || emptyPassword || lowerank) {
|
if (emptyTitle || emptyPassword || lowerank) {
|
||||||
QMessageBox errDlg(this);
|
QMessageBox errDlg(this);
|
||||||
errDlg.setTextFormat(Qt::RichText);
|
errDlg.setTextFormat(Qt::RichText);
|
||||||
|
|
@ -67,11 +66,10 @@ void UserEditDialog::accept() {
|
||||||
errDlg.exec();
|
errDlg.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
this->_user->login = ui->et_login->text().trimmed();
|
this->_user_data->login = ui->et_login->text().trimmed();
|
||||||
this->_user->password = ui->et_password->text().trimmed();
|
this->_user_data->password = ui->et_password->text().trimmed();
|
||||||
this->_user->role = role;
|
this->_user_data->role = role;
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,25 +11,26 @@ namespace Ui {
|
||||||
class UserEditDialog;
|
class UserEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserEditDialog : public QDialog {
|
struct user_data_struct {
|
||||||
Q_OBJECT
|
|
||||||
Ui::UserEditDialog *ui;
|
|
||||||
|
|
||||||
struct user_data {
|
|
||||||
QString login;
|
QString login;
|
||||||
QString password;
|
QString password;
|
||||||
UserRole role;
|
UserRole role;
|
||||||
bool edit;
|
bool edit;
|
||||||
} *_user;
|
};
|
||||||
|
|
||||||
|
class UserEditDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
Ui::UserEditDialog *ui;
|
||||||
|
|
||||||
|
user_data_struct *_user_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UserEditDialog(QWidget *parent = nullptr);
|
explicit UserEditDialog(QWidget *parent = nullptr);
|
||||||
~UserEditDialog();
|
~UserEditDialog();
|
||||||
|
|
||||||
UserEditDialog::user_data* user() const;
|
user_data_struct* user_data() const;
|
||||||
void set_user(user_entity* user, bool edit);
|
void set_user(user_entity* user, bool edit);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept() Q_DECL_OVERRIDE;
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -55,5 +55,6 @@ QVariant DeliveryPointsViewModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeliveryPointsViewModel::update() {
|
void DeliveryPointsViewModel::update() {
|
||||||
dataChanged(QModelIndex(), QModelIndex());
|
this->beginResetModel();
|
||||||
|
this->endResetModel();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,5 +61,6 @@ QVariant VesselsViewModel::data(const QModelIndex &index, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VesselsViewModel::update() {
|
void VesselsViewModel::update() {
|
||||||
dataChanged(QModelIndex(), QModelIndex());
|
this->beginResetModel();
|
||||||
|
this->endResetModel();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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-22T14:58:07. -->
|
<!-- Written by QtCreator 4.13.3, 2020-12-23T04:25:48. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|
@ -169,7 +169,7 @@
|
||||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||||
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
||||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||||
|
|
@ -221,7 +221,7 @@
|
||||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||||
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
|
||||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ void st_test::dpoint_entity_serialization_test() {
|
||||||
f.open(QIODevice::WriteOnly);
|
f.open(QIODevice::WriteOnly);
|
||||||
stream.setDevice(&f);
|
stream.setDevice(&f);
|
||||||
|
|
||||||
ent1 = dpoint_entity("some_test_point");
|
ent1 = dpoint_entity(0, "some_test_point");
|
||||||
ent1.serialize(stream);
|
ent1.serialize(stream);
|
||||||
|
|
||||||
stream.setDevice(nullptr);
|
stream.setDevice(nullptr);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue