files renamed
This commit is contained in:
parent
dd23da5f72
commit
46d6468e5c
8 changed files with 80 additions and 11 deletions
|
@ -13,6 +13,7 @@ endif (MINGW)
|
||||||
set(CORE_SOURCES
|
set(CORE_SOURCES
|
||||||
database.cpp
|
database.cpp
|
||||||
entity.cpp
|
entity.cpp
|
||||||
|
entityuuid.cpp
|
||||||
seller.cpp
|
seller.cpp
|
||||||
article.cpp
|
article.cpp
|
||||||
sale.cpp
|
sale.cpp
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef ARTICLE_H
|
#ifndef ARTICLE_H
|
||||||
#define ARTICLE_H
|
#define ARTICLE_H
|
||||||
|
|
||||||
#include "entity.h"
|
#include "entityuuid.h"
|
||||||
//#include "sale.h"
|
//#include "sale.h"
|
||||||
//#include "seller.h"
|
//#include "seller.h"
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
class Seller;
|
class Seller;
|
||||||
class Sale;
|
class Sale;
|
||||||
|
|
||||||
class Article : public Entity
|
class Article : public EntityUuid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Article() = default;
|
Article() = default;
|
||||||
|
@ -41,4 +41,4 @@ class Article : public Entity
|
||||||
std::string description_{};
|
std::string description_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
33
src/core/entityuuid.cpp
Normal file
33
src/core/entityuuid.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include "entityuuid.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid_generators.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
|
EntityUuid::~EntityUuid() = default;
|
||||||
|
|
||||||
|
void EntityUuid::createUuid()
|
||||||
|
{
|
||||||
|
static boost::uuids::random_generator generator{};
|
||||||
|
uuid_ = generator();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityUuid::setUuidFromString(const std::string& uuidString)
|
||||||
|
{
|
||||||
|
boost::uuids::string_generator generator{};
|
||||||
|
uuid_ = generator(uuidString);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity::State EntityUuid::getState() const
|
||||||
|
{
|
||||||
|
return state_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityUuid::setSourceNo(int sourceNo) {
|
||||||
|
sourceNo_ = sourceNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EntityUuid::getSourceNo() const {
|
||||||
|
return sourceNo_;
|
||||||
|
}
|
35
src/core/entityuuid.h
Normal file
35
src/core/entityuuid.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef ENTITY_UUID_H
|
||||||
|
#define ENTITY_UUID_H
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
|
class EntityUuid : public Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Entity() = default;
|
||||||
|
virtual ~EntityUuid() = 0;
|
||||||
|
|
||||||
|
void createUuid();
|
||||||
|
void setUuidFromString(const std::string& uuidString);
|
||||||
|
void setState(State state) { state_ = state; }
|
||||||
|
void setSourceNo(int sourceNo);
|
||||||
|
|
||||||
|
const boost::uuids::uuid& getUuid() const { return uuid_; };
|
||||||
|
std::string getUuidAsString() const { return boost::uuids::to_string(uuid_); }
|
||||||
|
virtual State getState() const;
|
||||||
|
virtual int getSourceNo() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int sourceNo_{};
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::uuids::uuid uuid_{};
|
||||||
|
State state_{State::NEW};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ENTITY_UUID_H
|
|
@ -14,7 +14,7 @@ namespace
|
||||||
using ArticlesVec = std::vector<Article*>;
|
using ArticlesVec = std::vector<Article*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sale : public Entity
|
class Sale : public EntityUuid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void addArticle(Article* articlePtr);
|
void addArticle(Article* articlePtr);
|
||||||
|
@ -34,4 +34,4 @@ class Sale : public Entity
|
||||||
mutable ArticlesVec articles_{};
|
mutable ArticlesVec articles_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
|
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
|
||||||
int numArticlesOffered)
|
int numArticlesOffered)
|
||||||
: Entity()
|
: EntityUuid()
|
||||||
{
|
{
|
||||||
firstName_ = firstName;
|
firstName_ = firstName;
|
||||||
lastName_ = lastName;
|
lastName_ = lastName;
|
||||||
|
@ -108,4 +108,4 @@ bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.se
|
||||||
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
|
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
|
||||||
{
|
{
|
||||||
return li->sellerNo_ < re->sellerNo_;
|
return li->sellerNo_ < re->sellerNo_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define SELLER_H
|
#define SELLER_H
|
||||||
|
|
||||||
#include "article.h"
|
#include "article.h"
|
||||||
#include "entity.h"
|
#include "entityuuid.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// class Article;
|
// class Article;
|
||||||
|
|
||||||
class Seller : public Entity
|
class Seller : public EntityUuid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Seller() = default;
|
Seller() = default;
|
||||||
|
@ -49,4 +49,4 @@ class Seller : public Entity
|
||||||
std::vector<std::unique_ptr<Article>> articles_{};
|
std::vector<std::unique_ptr<Article>> articles_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -44,7 +44,7 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const
|
||||||
Sale* sale{};
|
Sale* sale{};
|
||||||
Article* article{};
|
Article* article{};
|
||||||
|
|
||||||
Entity* ent = static_cast<Entity*>(index.internalPointer());
|
EntityUuid* ent = static_cast<EntityUuid*>(index.internalPointer());
|
||||||
|
|
||||||
sale = dynamic_cast<Sale*>(ent);
|
sale = dynamic_cast<Sale*>(ent);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue