From 46d6468e5c4fa5a72b4ef23873dd8d76eee8e058 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 4 Oct 2019 14:05:19 +0200 Subject: [PATCH] files renamed --- src/core/CMakeLists.txt | 1 + src/core/article.h | 6 +++--- src/core/entityuuid.cpp | 33 +++++++++++++++++++++++++++++++++ src/core/entityuuid.h | 35 +++++++++++++++++++++++++++++++++++ src/core/sale.h | 4 ++-- src/core/seller.cpp | 4 ++-- src/core/seller.h | 6 +++--- src/gui/salemodel.cpp | 2 +- 8 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 src/core/entityuuid.cpp create mode 100644 src/core/entityuuid.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3d9fa92..48191c1 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,6 +13,7 @@ endif (MINGW) set(CORE_SOURCES database.cpp entity.cpp + entityuuid.cpp seller.cpp article.cpp sale.cpp diff --git a/src/core/article.h b/src/core/article.h index a497242..50c0a9d 100644 --- a/src/core/article.h +++ b/src/core/article.h @@ -1,7 +1,7 @@ #ifndef ARTICLE_H #define ARTICLE_H -#include "entity.h" +#include "entityuuid.h" //#include "sale.h" //#include "seller.h" @@ -11,7 +11,7 @@ class Seller; class Sale; -class Article : public Entity +class Article : public EntityUuid { public: Article() = default; @@ -41,4 +41,4 @@ class Article : public Entity std::string description_{}; }; -#endif \ No newline at end of file +#endif diff --git a/src/core/entityuuid.cpp b/src/core/entityuuid.cpp new file mode 100644 index 0000000..53703b5 --- /dev/null +++ b/src/core/entityuuid.cpp @@ -0,0 +1,33 @@ +#include "entityuuid.h" + +#include + +#include +#include + +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_; +} diff --git a/src/core/entityuuid.h b/src/core/entityuuid.h new file mode 100644 index 0000000..6af931b --- /dev/null +++ b/src/core/entityuuid.h @@ -0,0 +1,35 @@ +#ifndef ENTITY_UUID_H +#define ENTITY_UUID_H + +#include "entity.h" + +#include + +#include +#include + +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 diff --git a/src/core/sale.h b/src/core/sale.h index c6de317..0cfb18c 100644 --- a/src/core/sale.h +++ b/src/core/sale.h @@ -14,7 +14,7 @@ namespace using ArticlesVec = std::vector; } -class Sale : public Entity +class Sale : public EntityUuid { public: void addArticle(Article* articlePtr); @@ -34,4 +34,4 @@ class Sale : public Entity mutable ArticlesVec articles_{}; }; -#endif \ No newline at end of file +#endif diff --git a/src/core/seller.cpp b/src/core/seller.cpp index 9147934..57830cd 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -7,7 +7,7 @@ Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo, int numArticlesOffered) - : Entity() + : EntityUuid() { firstName_ = firstName; 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& li, const std::unique_ptr& re) { return li->sellerNo_ < re->sellerNo_; -} \ No newline at end of file +} diff --git a/src/core/seller.h b/src/core/seller.h index db44a0f..5828266 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -2,7 +2,7 @@ #define SELLER_H #include "article.h" -#include "entity.h" +#include "entityuuid.h" #include #include @@ -10,7 +10,7 @@ // class Article; -class Seller : public Entity +class Seller : public EntityUuid { public: Seller() = default; @@ -49,4 +49,4 @@ class Seller : public Entity std::vector> articles_{}; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/salemodel.cpp b/src/gui/salemodel.cpp index 0bf9a71..3549003 100644 --- a/src/gui/salemodel.cpp +++ b/src/gui/salemodel.cpp @@ -44,7 +44,7 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const Sale* sale{}; Article* article{}; - Entity* ent = static_cast(index.internalPointer()); + EntityUuid* ent = static_cast(index.internalPointer()); sale = dynamic_cast(ent);