All entities now have GID

This commit is contained in:
Andrew nuark G 2020-12-23 19:00:57 +07:00
parent eb097588ba
commit 2be2e9f5e3
9 changed files with 59 additions and 11 deletions

View file

@ -94,7 +94,7 @@ void DeliveryPointEditDialog::set_dpoint(dpoint_entity* dpoint, bool edit) {
void DeliveryPointEditDialog::accept() { void DeliveryPointEditDialog::accept() {
bool emptyTitle = ui->et_title->text().trimmed().isEmpty(); bool emptyTitle = ui->et_title->text().trimmed().isEmpty();
if (emptyTitle) {; if (emptyTitle) {;
QString message = "Some errors happend, while saving your note:" QString message = "Some errors happend, while saving:"
"<br>- Title cannot be empty (all spaces - empty too)"; "<br>- Title cannot be empty (all spaces - empty too)";
QMessageBox::critical(this, "Error", message); QMessageBox::critical(this, "Error", message);
return; return;

View file

@ -1,8 +1,10 @@
#include "cargo_entity.h" #include "cargo_entity.h"
entity_id cargo_entity::__global_id = 0;
cargo_entity::cargo_entity() { cargo_entity::cargo_entity() {
this->_id += QRandomGenerator().generate64(); 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) {
@ -33,3 +35,11 @@ void cargo_entity::serialize(QDataStream &output) {
void cargo_entity::deserialize(QDataStream &input) { void cargo_entity::deserialize(QDataStream &input) {
input >> this->_id >> this->_title >> this->_volume; input >> this->_id >> this->_title >> this->_volume;
} }
void cargo_entity::preloadGlobalId(entity_id gid) {
cargo_entity::__global_id = gid;
}
entity_id cargo_entity::GID() {
return cargo_entity::__global_id;
}

View file

@ -10,6 +10,8 @@
class cargo_entity : public IEntity { class cargo_entity : public IEntity {
private: private:
static entity_id __global_id;
entity_id _id = 0; entity_id _id = 0;
QString _title; QString _title;
unsigned int _volume = 50000; unsigned int _volume = 50000;
@ -24,6 +26,8 @@ public:
void serialize(QDataStream &output); void serialize(QDataStream &output);
void deserialize(QDataStream &input); void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
static entity_id GID();
}; };
#endif // CARGO_ENTITY_H #endif // CARGO_ENTITY_H

View file

@ -1,8 +1,10 @@
#include "dpoint_entity.h" #include "dpoint_entity.h"
entity_id dpoint_entity::__global_id = 0;
dpoint_entity::dpoint_entity() { dpoint_entity::dpoint_entity() {
this->_id += QRandomGenerator().generate64(); 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) {
@ -83,3 +85,11 @@ void dpoint_entity::deserialize(QDataStream &input) {
this->_storages[i].deserialize(input); this->_storages[i].deserialize(input);
} }
} }
void dpoint_entity::preloadGlobalId(entity_id gid) {
dpoint_entity::__global_id = gid;
}
entity_id dpoint_entity::GID() {
return dpoint_entity::__global_id;
}

View file

@ -12,6 +12,8 @@
class dpoint_entity : public IEntity { class dpoint_entity : public IEntity {
private: private:
static entity_id __global_id;
entity_id _id = 0; entity_id _id = 0;
entity_id _dispatcher_id; entity_id _dispatcher_id;
QString _title; QString _title;
@ -33,6 +35,8 @@ public:
void serialize(QDataStream &output); void serialize(QDataStream &output);
void deserialize(QDataStream &input); void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
static entity_id GID();
}; };
#endif // DPOINT_ENTITY_H #endif // DPOINT_ENTITY_H

View file

@ -1,8 +1,10 @@
#include "user_entity.h" #include "user_entity.h"
entity_id user_entity::__global_id = 0;
user_entity::user_entity() { user_entity::user_entity() {
this->_id += QRandomGenerator().generate64(); this->_id = ++user_entity::__global_id + QRandomGenerator().generate64();
} }
user_entity::user_entity(const QString &login, const QString &password, UserRole role) : _login(login), _role(role) { user_entity::user_entity(const QString &login, const QString &password, UserRole role) : _login(login), _role(role) {
@ -47,3 +49,11 @@ void user_entity::serialize(QDataStream &output) {
void user_entity::deserialize(QDataStream &input) { void user_entity::deserialize(QDataStream &input) {
input >> this->_id >> this->_login >> this->_role >> this->_pwd_hash; input >> this->_id >> this->_login >> this->_role >> this->_pwd_hash;
} }
void user_entity::preloadGlobalId(entity_id gid) {
user_entity::__global_id = gid;
}
entity_id user_entity::GID() {
return user_entity::__global_id;
}

View file

@ -15,6 +15,8 @@ enum class UserRole {
class user_entity : public IEntity { class user_entity : public IEntity {
private: private:
static entity_id __global_id;
entity_id _id = 0; entity_id _id = 0;
QString _login; QString _login;
UserRole _role; UserRole _role;
@ -33,6 +35,8 @@ public:
void serialize(QDataStream &output); void serialize(QDataStream &output);
void deserialize(QDataStream &input); void deserialize(QDataStream &input);
static void preloadGlobalId(entity_id gid);
static entity_id GID();
}; };
#endif // USER_ENTITY_H #endif // USER_ENTITY_H

View file

@ -39,9 +39,12 @@ void apparatus::save() {
QDataStream stream(&f); QDataStream stream(&f);
// saving GIDs // saving GIDs
entity_id vgid = vessel_entity::GID(); entity_id cgid = cargo_entity::GID();
entity_id dgid = dpoint_entity::GID();
entity_id sgid = storage_entity::GID(); entity_id sgid = storage_entity::GID();
stream << vgid << sgid; entity_id ugid = user_entity::GID();
entity_id vgid = vessel_entity::GID();
stream << cgid << dgid << sgid << ugid << vgid;
// serializing data // serializing data
this->_auth_system->serialize_data(&stream); this->_auth_system->serialize_data(&stream);
@ -52,17 +55,20 @@ void apparatus::save() {
void apparatus::load() { void apparatus::load() {
if (_instance == nullptr) { if (_instance == nullptr) {
throw std::runtime_error("HOW DU FUCK INSTANCE IS NULL????"); throw std::runtime_error("NO WAY INSTANCE IS NULL!");
} }
QFile f(apparatus::filename); QFile f(apparatus::filename);
f.open(QIODevice::ReadOnly); f.open(QIODevice::ReadOnly);
QDataStream stream(&f); QDataStream stream(&f);
// loading GIDs // loading GIDs
entity_id vgid, sgid = vgid = 0; entity_id cgid, dgid, sgid, ugid, vgid = ugid = sgid = dgid = cgid = 0;
stream >> vgid >> sgid; stream >> cgid >> dgid >> sgid >> ugid >> vgid;
vessel_entity::preloadGlobalId(vgid); cargo_entity::preloadGlobalId(cgid);
dpoint_entity::preloadGlobalId(dgid);
storage_entity::preloadGlobalId(sgid); storage_entity::preloadGlobalId(sgid);
user_entity::preloadGlobalId(ugid);
vessel_entity::preloadGlobalId(vgid);
// deserializing data // deserializing data
this->_auth_system->deserialize_data(&stream); this->_auth_system->deserialize_data(&stream);

View file

@ -52,7 +52,7 @@ void UserEditDialog::accept() {
errDlg.setTextFormat(Qt::RichText); errDlg.setTextFormat(Qt::RichText);
errDlg.setWindowTitle(tr("Error")); errDlg.setWindowTitle(tr("Error"));
errDlg.setIcon(QMessageBox::Critical); errDlg.setIcon(QMessageBox::Critical);
QString message = tr("Some errors happend, while saving your note:"); QString message = tr("Some errors happend, while saving:");
if (emptyTitle) { if (emptyTitle) {
message.append("<br>- Title cannot be empty (all spaces - empty too)"); message.append("<br>- Title cannot be empty (all spaces - empty too)");
} }