base viewmodel and interactions
This commit is contained in:
parent
50aa95e659
commit
d69b18f083
14 changed files with 228 additions and 77 deletions
|
|
@ -24,7 +24,14 @@ apparatus::apparatus() {
|
|||
}
|
||||
|
||||
apparatus::~apparatus() {
|
||||
this->shutdown();
|
||||
|
||||
}
|
||||
|
||||
void apparatus::generate_lock_file() {
|
||||
QFile init("lock");
|
||||
init.open(QIODevice::ReadWrite);
|
||||
init.write("lock");
|
||||
init.close();
|
||||
}
|
||||
|
||||
apparatus* apparatus::instance() {
|
||||
|
|
@ -36,38 +43,30 @@ apparatus* apparatus::instance() {
|
|||
}
|
||||
|
||||
bool apparatus::isFirstRun() {
|
||||
return QFile().exists("init");
|
||||
return !QFile().exists("lock");
|
||||
}
|
||||
|
||||
void apparatus::generate_empty_data() {
|
||||
this->open_stream();
|
||||
this->writeGIDS();
|
||||
this->serialize_data();
|
||||
this->close_stream();
|
||||
}
|
||||
|
||||
const auth_system& apparatus::get_auth_subsystem() {
|
||||
auth_system& apparatus::get_auth_subsystem() {
|
||||
return this->_auth_system;
|
||||
}
|
||||
|
||||
const object_system& apparatus::get_object_subsystem() {
|
||||
object_system& apparatus::get_object_subsystem() {
|
||||
return this->_object_system;
|
||||
}
|
||||
|
||||
void apparatus::init() {
|
||||
apparatus::_instance = new apparatus();
|
||||
|
||||
apparatus::instance()->open_stream();
|
||||
apparatus::instance()->loadGIDS();
|
||||
apparatus::instance()->deserialize_data();
|
||||
apparatus::instance()->close_stream();
|
||||
apparatus::_instance->open_stream();
|
||||
apparatus::_instance->loadGIDS();
|
||||
apparatus::_instance->deserialize_data();
|
||||
}
|
||||
|
||||
void apparatus::shutdown() {
|
||||
apparatus::instance()->open_stream();
|
||||
apparatus::instance()->writeGIDS();
|
||||
apparatus::instance()->serialize_data();
|
||||
apparatus::instance()->close_stream();
|
||||
apparatus::_instance->writeGIDS();
|
||||
apparatus::_instance->serialize_data();
|
||||
apparatus::_instance->close_stream();
|
||||
delete apparatus::_instance;
|
||||
}
|
||||
|
||||
void apparatus::writeGIDS() {
|
||||
|
|
@ -84,12 +83,11 @@ void apparatus::loadGIDS() {
|
|||
}
|
||||
|
||||
void apparatus::serialize_data() {
|
||||
this->_auth_system.init(this->stream);
|
||||
this->_object_system.init(this->stream);
|
||||
this->_auth_system.serialize_data(this->stream);
|
||||
this->_object_system.serialize_data(this->stream);
|
||||
}
|
||||
|
||||
void apparatus::deserialize_data() {
|
||||
QFile("init").open(QIODevice::ReadWrite);
|
||||
this->_auth_system.shutdown(this->stream);
|
||||
this->_object_system.shutdown(this->stream);
|
||||
this->_auth_system.deserialize_data(this->stream);
|
||||
this->_object_system.deserialize_data(this->stream);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,14 +35,15 @@ public:
|
|||
~apparatus();
|
||||
|
||||
void generate_empty_data();
|
||||
const auth_system& get_auth_subsystem();
|
||||
const object_system& get_object_subsystem();
|
||||
auth_system& get_auth_subsystem();
|
||||
object_system& get_object_subsystem();
|
||||
|
||||
|
||||
void serialize_data();
|
||||
void deserialize_data();
|
||||
|
||||
static bool isFirstRun();
|
||||
static void generate_lock_file();
|
||||
static apparatus* instance();
|
||||
static void init();
|
||||
static void shutdown();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,11 @@ bool auth_system::register_user(const QString &login, const QString &password, U
|
|||
return false;
|
||||
}
|
||||
|
||||
void auth_system::init(QDataStream &stream) {
|
||||
const QVector<user_entity> auth_system::users() const {
|
||||
return this->_users;
|
||||
}
|
||||
|
||||
void auth_system::deserialize_data(QDataStream &stream) {
|
||||
int icnt;
|
||||
stream >> icnt;
|
||||
this->_users.resize(icnt);
|
||||
|
|
@ -48,7 +52,7 @@ void auth_system::init(QDataStream &stream) {
|
|||
}
|
||||
}
|
||||
|
||||
void auth_system::shutdown(QDataStream &stream) {
|
||||
void auth_system::serialize_data(QDataStream &stream) {
|
||||
stream << this->_users.size();
|
||||
for (auto &item : this->_users) {
|
||||
item.serialize(stream);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef AUTH_SYSTEM_H
|
||||
#define AUTH_SYSTEM_H
|
||||
|
||||
#include<QVector>
|
||||
#include <QVector>
|
||||
|
||||
#include "../entities/user_entity.h"
|
||||
|
||||
|
|
@ -17,8 +17,10 @@ public:
|
|||
bool remove_user(const QString &login);
|
||||
bool register_user(const QString &login, const QString &password, UserRole role);
|
||||
|
||||
void init(QDataStream &stream);
|
||||
void shutdown(QDataStream &stream);
|
||||
const QVector<user_entity> users() const;
|
||||
|
||||
void deserialize_data(QDataStream &stream);
|
||||
void serialize_data(QDataStream &stream);
|
||||
};
|
||||
|
||||
#endif // AUTH_SYSTEM_H
|
||||
|
|
|
|||
|
|
@ -77,7 +77,15 @@ bool object_system::add_vessel(vessel_entity dpoint) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void object_system::init(QDataStream &stream) {
|
||||
const QVector<dpoint_entity> object_system::dpoints() const {
|
||||
return this->_dpoints;
|
||||
}
|
||||
|
||||
const QVector<vessel_entity> object_system::vessels() const {
|
||||
return this->_vessels;
|
||||
}
|
||||
|
||||
void object_system::deserialize_data(QDataStream &stream) {
|
||||
int dicnt;
|
||||
stream >> dicnt;
|
||||
this->_dpoints.resize(dicnt);
|
||||
|
|
@ -93,7 +101,7 @@ void object_system::init(QDataStream &stream) {
|
|||
}
|
||||
}
|
||||
|
||||
void object_system::shutdown(QDataStream &stream) {
|
||||
void object_system::serialize_data(QDataStream &stream) {
|
||||
stream << this->_dpoints.size();
|
||||
for (auto &item : this->_dpoints) {
|
||||
item.serialize(stream);
|
||||
|
|
|
|||
|
|
@ -25,8 +25,11 @@ public:
|
|||
bool add_vessel(vessel_entity dpoint);
|
||||
|
||||
|
||||
void init(QDataStream &stream);
|
||||
void shutdown(QDataStream &stream);
|
||||
const QVector<dpoint_entity> dpoints() const;
|
||||
const QVector<vessel_entity> vessels() const;
|
||||
|
||||
void deserialize_data(QDataStream &stream);
|
||||
void serialize_data(QDataStream &stream);
|
||||
};
|
||||
|
||||
#endif // OBJECT_SYSTEM_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue