Vessel edit dialog

This commit is contained in:
Andrew nuark G 2020-12-23 18:43:41 +07:00
parent 9686b96d8a
commit eb097588ba
21 changed files with 589 additions and 97 deletions

View file

@ -1,5 +1,10 @@
#include "cargo_entity.h"
cargo_entity::cargo_entity() {
this->_id += QRandomGenerator().generate64();
}
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);

View file

@ -10,12 +10,12 @@
class cargo_entity : public IEntity {
private:
entity_id _id;
entity_id _id = 0;
QString _title;
unsigned int _volume;
unsigned int _volume = 50000;
public:
cargo_entity() = default;
cargo_entity();
cargo_entity(const QString &title, unsigned int volume);
entity_id id() const;

View file

@ -1,5 +1,10 @@
#include "dpoint_entity.h"
dpoint_entity::dpoint_entity() {
this->_id += QRandomGenerator().generate64();
}
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);
@ -29,15 +34,24 @@ const QVector<storage_entity> dpoint_entity::storages() {
return this->_storages;
}
storage_entity* dpoint_entity::get_storage(entity_id sid, bool &success) {
success = false;
for (int i = 0; i < this->_storages.length(); i++) {
if (this->_storages[i].id() != sid) {
continue;
}
success = true;
return &this->_storages[i];
}
return nullptr;
}
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;
// });
QVector<storage_entity> st(this->_storages);
for (int i = 0; i < st.length(); i++) {

View file

@ -12,13 +12,13 @@
class dpoint_entity : public IEntity {
private:
entity_id _id;
entity_id _id = 0;
entity_id _dispatcher_id;
QString _title;
QVector<storage_entity> _storages;
public:
dpoint_entity() = default;
dpoint_entity();
dpoint_entity(entity_id dispatcher_id, const QString &title);
entity_id id() const;
@ -26,6 +26,7 @@ public:
QString title() const;
void set_title(const QString &new_title);
const QVector<storage_entity> storages();
storage_entity* get_storage(entity_id sid, bool &success);
void set_storages(QVector<storage_entity> storages);
void remove_storage(entity_id sid);
void add_storage(storage_entity ent);

View file

@ -3,10 +3,13 @@
entity_id storage_entity::__global_id = 0;
storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
storage_entity::storage_entity() {
this->_id = ++storage_entity::__global_id + QRandomGenerator().generate64();
}
storage_entity::storage_entity(unsigned int capacity) : _capacity(capacity) {
this->_id = ++storage_entity::__global_id + QRandomGenerator().generate64();
}
entity_id storage_entity::id() const {
return this->_id;
@ -25,7 +28,7 @@ const QVector<cargo_entity> storage_entity::cargo() {
}
void storage_entity::add_cargo(cargo_entity object, bool &success) {
success = ((int)this->_capacity - (int)object.volume()) > 0;
success = ((int)this->_capacity - (int)object.volume()) >= 0;
if (success) {
this->_cargo.push_back(object);
this->_capacity -= object.volume();

View file

@ -12,12 +12,12 @@ class storage_entity : public IEntity {
private:
static entity_id __global_id;
entity_id _id;
entity_id _id = 0;
unsigned int _capacity = 500000;
QVector<cargo_entity> _cargo;
public:
storage_entity() = default;
storage_entity();
storage_entity(unsigned int capacity);
entity_id id() const;

View file

@ -1,10 +1,18 @@
#include "user_entity.h"
user_entity::user_entity() {
this->_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);
foreach (auto bit, this->_pwd_hash) {
this->_id += bit;
}
foreach (auto bit, QCryptographicHash::hash(login.toLocal8Bit(), QCryptographicHash::Sha3_256)) {
this->_id += bit;
}
this->_id += QRandomGenerator().generate64();
}

View file

@ -15,13 +15,13 @@ enum class UserRole {
class user_entity : public IEntity {
private:
entity_id _id;
entity_id _id = 0;
QString _login;
UserRole _role;
QByteArray _pwd_hash;
public:
user_entity() = default;
user_entity();
user_entity(const QString &login, const QString &password, UserRole role);
entity_id id() const;

View file

@ -3,38 +3,69 @@
entity_id vessel_entity::__global_id = 0;
vessel_entity::vessel_entity(entity_id skipper_id, entity_id harbor_id, unsigned int capacity) : _skipper_id(skipper_id), _harbor_id(harbor_id), _capacity(capacity) {
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();
}
entity_id vessel_entity::id() const {
return this->_id;
}
entity_id vessel_entity::skipper() const {
return this->_skipper_id;
QString vessel_entity::skipper() const {
return this->_skipper;
}
void vessel_entity::set_skipper(const QString &new_skipper) {
this->_skipper = new_skipper;
}
entity_id vessel_entity::harbor() const {
return this->_harbor_id;
}
void vessel_entity::set_harbor(entity_id new_harbor) {
this->_harbor_id = new_harbor;
}
unsigned int vessel_entity::capacity() const {
return this->_capacity;
}
void vessel_entity::set_capacity(unsigned int new_capacity) {
this->_capacity = new_capacity;
}
const QVector<cargo_entity> vessel_entity::cargo() {
return this->_cargo;
}
void vessel_entity::add_cargo(cargo_entity object, bool &success) {
success = ((int)this->_capacity - (int)object.volume()) > 0;
success = ((int)this->_capacity - (int)object.volume()) >= 0;
if (success) {
this->_cargo.push_back(object);
this->_capacity -= object.volume();
}
}
cargo_entity vessel_entity::get_cargo(entity_id oid, bool &found) {
cargo_entity ent;
found = false;
auto vit = this->_cargo.begin();
for (; vit != this->_cargo.end(); vit++) {
if ((*vit).id() == oid) {
ent = *vit;
found = true;
break;
}
}
return ent;
}
void vessel_entity::withdraw_cargo(entity_id oid, bool &success) {
success = false;
auto vit = this->_cargo.begin();
@ -49,7 +80,7 @@ void vessel_entity::withdraw_cargo(entity_id oid, bool &success) {
}
void vessel_entity::serialize(QDataStream &output) {
output << this->_id << this->_harbor_id;
output << this->_id << this->_skipper << this->_harbor_id;
output << this->_capacity << this->_cargo.size();
for (auto item : this->_cargo) {
item.serialize(output);
@ -57,7 +88,7 @@ void vessel_entity::serialize(QDataStream &output) {
}
void vessel_entity::deserialize(QDataStream &input) {
input >> this->_id >> this->_harbor_id;
input >> this->_id >> this->_skipper >> this->_harbor_id;
int icnt;
input >> this->_capacity >> icnt;
this->_cargo.resize(icnt);

View file

@ -12,23 +12,27 @@ class vessel_entity : public IEntity {
private:
static entity_id __global_id;
entity_id _id;
entity_id _skipper_id;
entity_id _id = 0;
QString _skipper;
entity_id _harbor_id;
unsigned int _capacity;
unsigned int _capacity = 50000;
QVector<cargo_entity> _cargo;
public:
vessel_entity() = default;
vessel_entity(entity_id skipper_id, entity_id harbor_id, unsigned int capacity);
vessel_entity();
vessel_entity(QString skipper, entity_id harbor_id, unsigned int capacity);
entity_id id() const;
entity_id skipper() const;
QString skipper() const;
void set_skipper(const QString &new_skipper);
entity_id harbor() const;
void set_harbor(entity_id new_harbor);
unsigned int capacity() const;
void set_capacity(unsigned int new_capacity);
const QVector<cargo_entity> cargo();
void add_cargo(cargo_entity object, bool &success);
cargo_entity get_cargo(entity_id oid, bool &found);
void withdraw_cargo(entity_id oid, bool &success);
void serialize(QDataStream &output);