diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index dd6217d..a7a8470 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -4,16 +4,14 @@ set(HEADERS TreeNode.h BinaryPacketComposer.h APluginManager.h - model/ARepositoryFactory.h - model/ARepository.h - model/AModelFactory.h - model/AModel.h - model/AStructureFactory.h - model/AStructure.h - model/AFieldFactory.h - model/AField.h - model/IModelPlugin.h - model/ModelPluginManager.h + model/Repository.h + model/Model.h + model/Structure.h + model/Field.h + control/ARepositoryFactory.h + control/AFieldFactory.h + control/AStructureFactory.h + control/AModelFactory.h schemaio/AStructureReaderFactory.h schemaio/AStructureWriterFactory.h @@ -26,16 +24,14 @@ set(HEADERS set(SOURCES BinaryPacketComposer.cpp APluginManager.cpp - model/ARepositoryFactory.cpp - model/ARepository.cpp - model/AModelFactory.cpp - model/AModel.cpp - model/AStructureFactory.cpp - model/AStructure.cpp - model/AFieldFactory.cpp - model/AField.cpp - model/IModelPlugin.cpp - model/ModelPluginManager.cpp + model/Repository.cpp + model/Model.cpp + model/Structure.cpp + model/Field.cpp + control/ARepositoryFactory.cpp + control/AFieldFactory.cpp + control/AStructureFactory.cpp + control/AModelFactory.cpp schemaio/AStructureReaderFactory.cpp schemaio/AStructureWriterFactory.cpp diff --git a/src/core/RandomAccessBinary.cpp b/src/core/RandomAccessBinary.cpp index fada871..352ec25 100644 --- a/src/core/RandomAccessBinary.cpp +++ b/src/core/RandomAccessBinary.cpp @@ -171,50 +171,50 @@ bool RandomAccessBinary::getBit(uint64_t position) const std::vector RandomAccessBinary::getBits(uint byteOffset, uint8_t bitOffset, uint64_t length) { - + return std::vector(); } const std::vector RandomAccessBinary::getBits(uint64_t position, uint64_t length) { - + return std::vector(); } uint16_t RandomAccessBinary::get_uint16(uint byteOffset) { - + return 0; } uint32_t RandomAccessBinary::get_uint32(uint byteOffset) { - + return 0; } uint64_t RandomAccessBinary::get_uint64(uint byteOffset) { - + return 0; } float RandomAccessBinary::get_float(uint byteOffset) { - + return 0.0f; } double RandomAccessBinary::get_double(uint byteOffset) { - + return 0.0; } std::__cxx11::string RandomAccessBinary::get_string(uint byteOffset, uint length) { - + return ""; } std::__cxx11::string RandomAccessBinary::get_hex_string(uint byteOffset, uint length) { - + return ""; } std::__cxx11::string RandomAccessBinary::get_hex_string() { - + return ""; } diff --git a/src/core/TreeNode.h b/src/core/TreeNode.h index c3eac94..563e2c1 100644 --- a/src/core/TreeNode.h +++ b/src/core/TreeNode.h @@ -22,12 +22,15 @@ public: explicit TreeNode(std::shared_ptr data); virtual ~TreeNode(); + std::shared_ptr> copy(); // copy only this node, without children! + std::shared_ptr> rcopy(); // recursive copy + const std::shared_ptr> nextSibling(); const std::shared_ptr> next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst); const std::shared_ptr> getRoot(); void move(std::shared_ptr> to); //as child - void moveChildren(std::shared_ptr> to); //all + void moveChildren(std::shared_ptr> to); //all children but not the 'executing' element void addChild(std::shared_ptr> child); void addChildren(std::shared_ptr> nodeWithChildren); @@ -87,6 +90,21 @@ TreeNode::~TreeNode() } +template +std::shared_ptr > TreeNode::copy() +{ + return std::make_shared>(std::make_shared(*this->getData())); +} + +template +std::shared_ptr > TreeNode::rcopy() +{ + auto n = std::make_shared>(std::make_shared(*this->getData())); + for(auto c : this->getChildren()) + n->addChild(c->rcopy()); + return n; +} + template const std::shared_ptr> TreeNode::nextSibling() { @@ -150,7 +168,7 @@ const std::shared_ptr> TreeNode::next(TreeWalkStrategy walkStrate if (parent != nullptr) { auto nextOnLvl = nextOnSameLevel(); if (nextOnLvl == nullptr){ - for (auto n : this->getChildren()) + for (auto n : parent->getChildren()) if (n->getChildren().size() > 0) return n->getChildren().front(); //return n->getChildren().first(); diff --git a/src/core/control/AFieldFactory.cpp b/src/core/control/AFieldFactory.cpp new file mode 100644 index 0000000..fa2cc98 --- /dev/null +++ b/src/core/control/AFieldFactory.cpp @@ -0,0 +1,25 @@ +#include "FieldFactory.h" +namespace NPC_core { +namespace Control { +AFieldFactory::AFieldFactory() +{ + +} + +std::shared_ptr AFieldFactory::createField(std::string name, std::shared_ptr parentStructure) +{ + auto f = std::make_shared(); + f->setName(name); + f->setParentStructure(parentStructure); + return f; +} + +std::shared_ptr AFieldFactory::createFieldFull(std::string name, std::map syntaxes, std::shared_ptr parentStructure) +{ + auto f = std::make_shared(); + f->setName(name); + f->setSyntaxes(syntaxes); + f->setParentStructure(parentStructure); + return f; +} +}} diff --git a/src/core/control/AFieldFactory.h b/src/core/control/AFieldFactory.h new file mode 100644 index 0000000..4aa8ae2 --- /dev/null +++ b/src/core/control/AFieldFactory.h @@ -0,0 +1,19 @@ +#ifndef AFIELDFACTORY_H +#define AFIELDFACTORY_H + +#include "../model/Field.h" +#include + +namespace NPC_core { +namespace Control { +class AFieldFactory +{ +public: + AFieldFactory(); + virtual ~AFieldFactory(); + + virtual std::shared_ptr createField(std::string name, std::shared_ptr parentStructure = nullptr); + virtual std::shared_ptr createFieldFull(std::string name, std::map syntaxes, std::shared_ptr parentStructure = nullptr); +}; +}} +#endif // AFIELDFACTORY_H diff --git a/src/core/control/AFieldFactory.h.autosave b/src/core/control/AFieldFactory.h.autosave new file mode 100644 index 0000000..2ffe97c --- /dev/null +++ b/src/core/control/AFieldFactory.h.autosave @@ -0,0 +1,19 @@ +#ifndef AFIELDFACTORY_H +#define AFIELDFACTORY_H + +#include "../model/Field.h" +#include + +namespace NPC_core { +namespace Control { +class AFieldFactory +{ +public: + AFieldFactory(); + virtual ~AFieldFactory(); + + virtual std::shared_ptr createField(std::string name, std::shared_ptr parentStructure = nullptr); + virtual std::shared_ptr createFieldFull(std::string name, std::map syntaxes, std::shared_ptr parentStructure = nullptr); +}; +}} +#endif // AFIELDFACTORY_H diff --git a/src/core/model/AModelFactory.cpp b/src/core/control/AModelFactory.cpp similarity index 58% rename from src/core/model/AModelFactory.cpp rename to src/core/control/AModelFactory.cpp index 1ec947b..b1d2f02 100644 --- a/src/core/model/AModelFactory.cpp +++ b/src/core/control/AModelFactory.cpp @@ -1,6 +1,8 @@ #include "AModelFactory.h" - +namespace NPC_core { +namespace Control { AModelFactory::AModelFactory() { } +}} diff --git a/src/core/model/AModelFactory.h b/src/core/control/AModelFactory.h similarity index 59% rename from src/core/model/AModelFactory.h rename to src/core/control/AModelFactory.h index eda556c..5860060 100644 --- a/src/core/model/AModelFactory.h +++ b/src/core/control/AModelFactory.h @@ -1,11 +1,12 @@ #ifndef AMODELFACTORY_H #define AMODELFACTORY_H - +namespace NPC_core { +namespace Control { class AModelFactory { public: AModelFactory(); }; - -#endif // AMODELFACTORY_H \ No newline at end of file +}} +#endif // AMODELFACTORY_H diff --git a/src/core/model/ARepositoryFactory.cpp b/src/core/control/ARepositoryFactory.cpp similarity index 63% rename from src/core/model/ARepositoryFactory.cpp rename to src/core/control/ARepositoryFactory.cpp index dca6deb..976e435 100644 --- a/src/core/model/ARepositoryFactory.cpp +++ b/src/core/control/ARepositoryFactory.cpp @@ -1,6 +1,8 @@ #include "ARepositoryFactory.h" - +namespace NPC_core { +namespace Control { ARepositoryFactory::ARepositoryFactory() { } +}} diff --git a/src/core/model/ARepositoryFactory.h b/src/core/control/ARepositoryFactory.h similarity index 62% rename from src/core/model/ARepositoryFactory.h rename to src/core/control/ARepositoryFactory.h index 854c07c..4a49c30 100644 --- a/src/core/model/ARepositoryFactory.h +++ b/src/core/control/ARepositoryFactory.h @@ -1,11 +1,12 @@ #ifndef AREPOSITORYFACTORY_H #define AREPOSITORYFACTORY_H - +namespace NPC_core { +namespace Control { class ARepositoryFactory { public: ARepositoryFactory(); }; - -#endif // AREPOSITORYFACTORY_H \ No newline at end of file +}} +#endif // AREPOSITORYFACTORY_H diff --git a/src/core/model/AStructureFactory.cpp b/src/core/control/AStructureFactory.cpp similarity index 63% rename from src/core/model/AStructureFactory.cpp rename to src/core/control/AStructureFactory.cpp index 6990242..87bd6d7 100644 --- a/src/core/model/AStructureFactory.cpp +++ b/src/core/control/AStructureFactory.cpp @@ -1,6 +1,8 @@ #include "AStructureFactory.h" - +namespace NPC_core { +namespace Control { AStructureFactory::AStructureFactory() { } +}} diff --git a/src/core/model/AStructureFactory.h b/src/core/control/AStructureFactory.h similarity index 61% rename from src/core/model/AStructureFactory.h rename to src/core/control/AStructureFactory.h index 9bb4e63..c97b645 100644 --- a/src/core/model/AStructureFactory.h +++ b/src/core/control/AStructureFactory.h @@ -1,11 +1,12 @@ #ifndef ASTRUCTUREFACTORY_H #define ASTRUCTUREFACTORY_H - +namespace NPC_core { +namespace Control { class AStructureFactory { public: AStructureFactory(); }; - -#endif // ASTRUCTUREFACTORY_H \ No newline at end of file +}} +#endif // ASTRUCTUREFACTORY_H diff --git a/src/core/model/AField.cpp b/src/core/model/AField.cpp deleted file mode 100644 index 8190a9f..0000000 --- a/src/core/model/AField.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "AField.h" - -AField::AField() -{ - -} diff --git a/src/core/model/AField.h b/src/core/model/AField.h deleted file mode 100644 index 624ede8..0000000 --- a/src/core/model/AField.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef AFIELD_H -#define AFIELD_H - - -class AField -{ -public: - AField(); -}; - -#endif // AFIELD_H \ No newline at end of file diff --git a/src/core/model/AFieldFactory.cpp b/src/core/model/AFieldFactory.cpp deleted file mode 100644 index df7215b..0000000 --- a/src/core/model/AFieldFactory.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "AFieldFactory.h" - -AFieldFactory::AFieldFactory() -{ - -} diff --git a/src/core/model/AFieldFactory.h b/src/core/model/AFieldFactory.h deleted file mode 100644 index 34744bc..0000000 --- a/src/core/model/AFieldFactory.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef AFIELDFACTORY_H -#define AFIELDFACTORY_H - - -class AFieldFactory -{ -public: - AFieldFactory(); -}; - -#endif // AFIELDFACTORY_H \ No newline at end of file diff --git a/src/core/model/AModel.cpp b/src/core/model/AModel.cpp deleted file mode 100644 index e657208..0000000 --- a/src/core/model/AModel.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "AModel.h" - -AModel::AModel() -{ - -} diff --git a/src/core/model/AModel.h b/src/core/model/AModel.h deleted file mode 100644 index 7562135..0000000 --- a/src/core/model/AModel.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef AMODEL_H -#define AMODEL_H - - -class AModel -{ -public: - AModel(); -}; - -#endif // AMODEL_H \ No newline at end of file diff --git a/src/core/model/ARepository.cpp b/src/core/model/ARepository.cpp deleted file mode 100644 index 1617b0e..0000000 --- a/src/core/model/ARepository.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "ARepository.h" - -ARepository::ARepository() -{ - -} diff --git a/src/core/model/ARepository.h b/src/core/model/ARepository.h deleted file mode 100644 index 6b0695e..0000000 --- a/src/core/model/ARepository.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef AREPOSITORY_H -#define AREPOSITORY_H - - -class ARepository -{ -public: - ARepository(); -}; - -#endif // AREPOSITORY_H \ No newline at end of file diff --git a/src/core/model/AStructure.cpp b/src/core/model/AStructure.cpp deleted file mode 100644 index e58e328..0000000 --- a/src/core/model/AStructure.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "AStructure.h" - -AStructure::AStructure() -{ - -} diff --git a/src/core/model/AStructure.h b/src/core/model/AStructure.h deleted file mode 100644 index 7b7179a..0000000 --- a/src/core/model/AStructure.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ASTRUCTURE_H -#define ASTRUCTURE_H - -#include -#include -#include "AField.h" - -class AStructure -{ -public: - AStructure(); - -private: - std::list> fields; -}; - -#endif // ASTRUCTURE_H diff --git a/src/core/model/Field.cpp b/src/core/model/Field.cpp new file mode 100644 index 0000000..e030f8d --- /dev/null +++ b/src/core/model/Field.cpp @@ -0,0 +1,51 @@ +#include "AField.h" + +namespace NPC_core { +namespace Model { +Field::Field() +{ + this->parentStructure = nullptr; +} + +std::string Field::getName() const +{ + return name; +} + +void Field::setName(const std::string &value) +{ + name = value; +} + +std::map Field::getSyntaxes() const +{ + return syntaxes; +} + +void Field::setSyntaxes(const std::map &value) +{ + syntaxes = value; +} + +std::string Field::getValue() const +{ + return value; +} + +void Field::setValue(const std::string &value) +{ + value = value; +} + +std::shared_ptr Field::getParentStructure() const +{ + return parentStructure; +} + +void Field::setParentStructure(const std::shared_ptr &value) +{ + parentStructure = value; +} + +} +} diff --git a/src/core/model/Field.h b/src/core/model/Field.h new file mode 100644 index 0000000..20dcfbf --- /dev/null +++ b/src/core/model/Field.h @@ -0,0 +1,40 @@ +#ifndef AFIELD_H +#define AFIELD_H + +#include "Structure.h" +#include +#include +#include + +namespace NPC_core { +namespace Model { + +class Structure; + +class Field +{ +public: + Field(); + virtual ~Field(); + + std::string getName() const; + void setName(const std::string &value); + + std::map getSyntaxes() const; + void setSyntaxes(const std::map &value); + + std::string getValue() const; + void setValue(const std::string &value); + + std::shared_ptr getParentStructure() const; + void setParentStructure(const std::shared_ptr &value); + +protected: + std::shared_ptr parentStructure; + std::string name; + std::map syntaxes; // example : regex; for validation + std::string value; +}; +}} + +#endif // AFIELD_H diff --git a/src/core/model/IModelPlugin.cpp b/src/core/model/IModelPlugin.cpp deleted file mode 100644 index c897494..0000000 --- a/src/core/model/IModelPlugin.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "IModelPlugin.h" - -IModelPlugin::IModelPlugin() -{ - -} diff --git a/src/core/model/IModelPlugin.h b/src/core/model/IModelPlugin.h deleted file mode 100644 index fc4ea7f..0000000 --- a/src/core/model/IModelPlugin.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef IMODELPLUGIN_H -#define IMODELPLUGIN_H - - -class IModelPlugin -{ -public: - IModelPlugin(); -}; - -#endif // IMODELPLUGIN_H \ No newline at end of file diff --git a/src/core/model/Model.cpp b/src/core/model/Model.cpp new file mode 100644 index 0000000..5a0ca97 --- /dev/null +++ b/src/core/model/Model.cpp @@ -0,0 +1,8 @@ +#include "Model.h" +namespace NPC_core { +namespace Model { +Model::Model() +{ + +} +}} diff --git a/src/core/model/Model.h b/src/core/model/Model.h new file mode 100644 index 0000000..92287c7 --- /dev/null +++ b/src/core/model/Model.h @@ -0,0 +1,19 @@ +#ifndef AMODEL_H +#define AMODEL_H + +#include "../Tree.h" +#include "Field.h" + +namespace NPC_core { +namespace Model { +class Model +{ +public: + Model(); + virtual ~Model(); + +private: + Tree stack; +}; +}} +#endif // AMODEL_H diff --git a/src/core/model/ModelPluginManager.cpp b/src/core/model/ModelPluginManager.cpp deleted file mode 100644 index 0b167ca..0000000 --- a/src/core/model/ModelPluginManager.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "ModelPluginManager.h" - -ModelPluginManager::ModelPluginManager() -{ - -} diff --git a/src/core/model/ModelPluginManager.h b/src/core/model/ModelPluginManager.h deleted file mode 100644 index 744d809..0000000 --- a/src/core/model/ModelPluginManager.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MODELPLUGINMANAGER_H -#define MODELPLUGINMANAGER_H - -#include "../APluginManager.h" - -class ModelPluginManager : public APluginManager -{ -public: - ModelPluginManager(); -}; - -#endif // MODELPLUGINMANAGER_H diff --git a/src/core/model/Repository.cpp b/src/core/model/Repository.cpp new file mode 100644 index 0000000..bc3c2c2 --- /dev/null +++ b/src/core/model/Repository.cpp @@ -0,0 +1,8 @@ +#include "Repository.h" +namespace NPC_core { +namespace Model { +Repository::Repository() +{ + +} +}} diff --git a/src/core/model/Repository.h b/src/core/model/Repository.h new file mode 100644 index 0000000..d8bf141 --- /dev/null +++ b/src/core/model/Repository.h @@ -0,0 +1,19 @@ +#ifndef AREPOSITORY_H +#define AREPOSITORY_H + +#include +#include "Structure.h" + +namespace NPC_core { +namespace Model { +class Repository +{ +public: + Repository(); + virtual ~Repository(); + +private: + std::map structures; +}; +}} +#endif // AREPOSITORY_H diff --git a/src/core/model/Structure.cpp b/src/core/model/Structure.cpp new file mode 100644 index 0000000..098171a --- /dev/null +++ b/src/core/model/Structure.cpp @@ -0,0 +1,8 @@ +#include "Structure.h" +namespace NPC_core { +namespace Model { +AStructure::AStructure() +{ + +} +}} diff --git a/src/core/model/Structure.cpp.autosave b/src/core/model/Structure.cpp.autosave new file mode 100644 index 0000000..a061eff --- /dev/null +++ b/src/core/model/Structure.cpp.autosave @@ -0,0 +1,18 @@ +#include "Structure.h" +namespace NPC_core { +namespace Model { +Structure::Structure() +{ + +} + +std::string Structure::getName() const +{ + return name; +} + +void Structure::setName(const std::string &value) +{ + name = value; +} +}} diff --git a/src/core/model/Structure.h b/src/core/model/Structure.h new file mode 100644 index 0000000..bb2e0bf --- /dev/null +++ b/src/core/model/Structure.h @@ -0,0 +1,29 @@ +#ifndef ASTRUCTURE_H +#define ASTRUCTURE_H + +#include +#include +#include "Field.h" +#include "../Tree.h" + +namespace NPC_core { +namespace Model { + +class Field; + +class Structure +{ +public: + Structure(); + virtual ~Structure(); + + std::string getName() const; + void setName(const std::string &value); + +private: + Tree elements; + std::string name; +}; +}} + +#endif // ASTRUCTURE_H diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt index a679fc0..8fb4b56 100644 --- a/src/editor/CMakeLists.txt +++ b/src/editor/CMakeLists.txt @@ -3,6 +3,7 @@ set(HEADERS editorelementdata.h guidededitorelementview.h flowlayout.h EditorElementValue.h + StructureField.h ) set(SOURCES guidededitorelementview.cpp @@ -10,7 +11,7 @@ set(SOURCES guidededitorelementview.cpp guidededitorview.cpp flowlayout.cpp EditorElementValue.cpp - + StructureField.cpp ) add_library(editor ${HEADERS} ${SOURCES}) diff --git a/src/editor/StructureField.cpp b/src/editor/StructureField.cpp new file mode 100644 index 0000000..3f77d6b --- /dev/null +++ b/src/editor/StructureField.cpp @@ -0,0 +1,44 @@ +#include "StructureField.h" + +namespace NPC_editor { + +StructureField::StructureField(QWidget *parent) : QWidget(parent) +{ + this->field = nullptr; + this->validator = new QRegExpValidator(); + this->layout = new QVBoxLayout(this); + this->setLayout(layout); + this->edit = nullptr; + this->line = nullptr; + this->title = new QLabel(this); + this->syntax = new QLabel(this); +} + +StructureField::StructureField(const std::shared_ptr field, QWidget *parent) : QWidget(parent) +{ + this->field = field; +} + +void StructureField::render() +{ + +} + +void StructureField::initialRender() +{ + for (QObject* w : this->children()) + if (w->isWidgetType()) + this->layout->removeWidget((QWidget*)w); + layout->addWidget(this->title); + layout->addWidget(this->syntax); + if (false ){// reference->getData()->isMultiLine()) { + this->edit = new QTextEdit(this); + layout->addWidget(this->edit); + } else { + this->line = new QLineEdit(this); + layout->addWidget(this->line); + } + this->render(); +} + +} diff --git a/src/editor/StructureField.h b/src/editor/StructureField.h new file mode 100644 index 0000000..e4ee9cb --- /dev/null +++ b/src/editor/StructureField.h @@ -0,0 +1,44 @@ +#ifndef STRUCTUREFIELD_H +#define STRUCTUREFIELD_H + +#include +#include +#include +#include +#include +#include +#include "../core/model/AField.h" +#include + +namespace NPC_editor { + +class StructureField : public QWidget +{ + Q_OBJECT +public: + explicit StructureField(QWidget *parent = nullptr); + explicit StructureField(const std::shared_ptr field, QWidget *parent = nullptr); + +signals: + + +public slots: + void inputChanged(); + void dataChanged(); + void nodeChanged(); + void render(); + void initialRender(); + +private: + std::shared_ptr field; + // layout + QVBoxLayout* layout; + QLabel* title; + QTextEdit* edit; + QLineEdit* line; + QMap otherWidgets; + QRegExpValidator* validator; + QWidget* subContainer; +}; +} +#endif // STRUCTUREFIELD_H