files renamed

This commit is contained in:
Martin Brodbeck 2019-10-04 14:05:19 +02:00
parent dd23da5f72
commit 46d6468e5c
8 changed files with 80 additions and 11 deletions

View file

@ -13,6 +13,7 @@ endif (MINGW)
set(CORE_SOURCES
database.cpp
entity.cpp
entityuuid.cpp
seller.cpp
article.cpp
sale.cpp

View file

@ -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;

33
src/core/entityuuid.cpp Normal file
View 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
View 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

View file

@ -14,7 +14,7 @@ namespace
using ArticlesVec = std::vector<Article*>;
}
class Sale : public Entity
class Sale : public EntityUuid
{
public:
void addArticle(Article* articlePtr);

View file

@ -7,7 +7,7 @@
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
int numArticlesOffered)
: Entity()
: EntityUuid()
{
firstName_ = firstName;
lastName_ = lastName;

View file

@ -2,7 +2,7 @@
#define SELLER_H
#include "article.h"
#include "entity.h"
#include "entityuuid.h"
#include <memory>
#include <string>
@ -10,7 +10,7 @@
// class Article;
class Seller : public Entity
class Seller : public EntityUuid
{
public:
Seller() = default;

View file

@ -44,7 +44,7 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const
Sale* sale{};
Article* article{};
Entity* ent = static_cast<Entity*>(index.internalPointer());
EntityUuid* ent = static_cast<EntityUuid*>(index.internalPointer());
sale = dynamic_cast<Sale*>(ent);