Another big change, rewriting things again.

Memo to self: Keep working on it, these long breaks between developing lead to too much structural changes...
This commit is contained in:
Marcel Otte 2018-01-11 15:45:01 +01:00
parent 8182e72a26
commit 691e387554
38 changed files with 420 additions and 171 deletions

View File

@ -4,16 +4,14 @@ set(HEADERS
TreeNode.h TreeNode.h
BinaryPacketComposer.h BinaryPacketComposer.h
APluginManager.h APluginManager.h
model/ARepositoryFactory.h model/Repository.h
model/ARepository.h model/Model.h
model/AModelFactory.h model/Structure.h
model/AModel.h model/Field.h
model/AStructureFactory.h control/ARepositoryFactory.h
model/AStructure.h control/AFieldFactory.h
model/AFieldFactory.h control/AStructureFactory.h
model/AField.h control/AModelFactory.h
model/IModelPlugin.h
model/ModelPluginManager.h
schemaio/AStructureReaderFactory.h schemaio/AStructureReaderFactory.h
schemaio/AStructureWriterFactory.h schemaio/AStructureWriterFactory.h
@ -26,16 +24,14 @@ set(HEADERS
set(SOURCES set(SOURCES
BinaryPacketComposer.cpp BinaryPacketComposer.cpp
APluginManager.cpp APluginManager.cpp
model/ARepositoryFactory.cpp model/Repository.cpp
model/ARepository.cpp model/Model.cpp
model/AModelFactory.cpp model/Structure.cpp
model/AModel.cpp model/Field.cpp
model/AStructureFactory.cpp control/ARepositoryFactory.cpp
model/AStructure.cpp control/AFieldFactory.cpp
model/AFieldFactory.cpp control/AStructureFactory.cpp
model/AField.cpp control/AModelFactory.cpp
model/IModelPlugin.cpp
model/ModelPluginManager.cpp
schemaio/AStructureReaderFactory.cpp schemaio/AStructureReaderFactory.cpp
schemaio/AStructureWriterFactory.cpp schemaio/AStructureWriterFactory.cpp

View File

@ -171,50 +171,50 @@ bool RandomAccessBinary::getBit(uint64_t position)
const std::vector<bool> RandomAccessBinary::getBits(uint byteOffset, uint8_t bitOffset, uint64_t length) const std::vector<bool> RandomAccessBinary::getBits(uint byteOffset, uint8_t bitOffset, uint64_t length)
{ {
return std::vector<bool>();
} }
const std::vector<bool> RandomAccessBinary::getBits(uint64_t position, uint64_t length) const std::vector<bool> RandomAccessBinary::getBits(uint64_t position, uint64_t length)
{ {
return std::vector<bool>();
} }
uint16_t RandomAccessBinary::get_uint16(uint byteOffset) uint16_t RandomAccessBinary::get_uint16(uint byteOffset)
{ {
return 0;
} }
uint32_t RandomAccessBinary::get_uint32(uint byteOffset) uint32_t RandomAccessBinary::get_uint32(uint byteOffset)
{ {
return 0;
} }
uint64_t RandomAccessBinary::get_uint64(uint byteOffset) uint64_t RandomAccessBinary::get_uint64(uint byteOffset)
{ {
return 0;
} }
float RandomAccessBinary::get_float(uint byteOffset) float RandomAccessBinary::get_float(uint byteOffset)
{ {
return 0.0f;
} }
double RandomAccessBinary::get_double(uint byteOffset) double RandomAccessBinary::get_double(uint byteOffset)
{ {
return 0.0;
} }
std::__cxx11::string RandomAccessBinary::get_string(uint byteOffset, uint length) std::__cxx11::string RandomAccessBinary::get_string(uint byteOffset, uint length)
{ {
return "";
} }
std::__cxx11::string RandomAccessBinary::get_hex_string(uint byteOffset, uint length) std::__cxx11::string RandomAccessBinary::get_hex_string(uint byteOffset, uint length)
{ {
return "";
} }
std::__cxx11::string RandomAccessBinary::get_hex_string() std::__cxx11::string RandomAccessBinary::get_hex_string()
{ {
return "";
} }

View File

@ -22,12 +22,15 @@ public:
explicit TreeNode(std::shared_ptr<T> data); explicit TreeNode(std::shared_ptr<T> data);
virtual ~TreeNode(); virtual ~TreeNode();
std::shared_ptr<TreeNode<T>> copy(); // copy only this node, without children!
std::shared_ptr<TreeNode<T>> rcopy(); // recursive copy
const std::shared_ptr<TreeNode<T>> nextSibling(); const std::shared_ptr<TreeNode<T>> nextSibling();
const std::shared_ptr<TreeNode<T>> next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst); const std::shared_ptr<TreeNode<T>> next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst);
const std::shared_ptr<TreeNode<T>> getRoot(); const std::shared_ptr<TreeNode<T>> getRoot();
void move(std::shared_ptr<TreeNode<T>> to); //as child void move(std::shared_ptr<TreeNode<T>> to); //as child
void moveChildren(std::shared_ptr<TreeNode<T>> to); //all void moveChildren(std::shared_ptr<TreeNode<T>> to); //all children but not the 'executing' element
void addChild(std::shared_ptr<TreeNode<T>> child); void addChild(std::shared_ptr<TreeNode<T>> child);
void addChildren(std::shared_ptr<TreeNode<T>> nodeWithChildren); void addChildren(std::shared_ptr<TreeNode<T>> nodeWithChildren);
@ -87,6 +90,21 @@ TreeNode<T>::~TreeNode()
} }
template<class T>
std::shared_ptr<TreeNode<T> > TreeNode<T>::copy()
{
return std::make_shared<TreeNode<T>>(std::make_shared<T>(*this->getData()));
}
template<class T>
std::shared_ptr<TreeNode<T> > TreeNode<T>::rcopy()
{
auto n = std::make_shared<TreeNode<T>>(std::make_shared<T>(*this->getData()));
for(auto c : this->getChildren())
n->addChild(c->rcopy());
return n;
}
template <class T> template <class T>
const std::shared_ptr<TreeNode<T>> TreeNode<T>::nextSibling() const std::shared_ptr<TreeNode<T>> TreeNode<T>::nextSibling()
{ {
@ -150,7 +168,7 @@ const std::shared_ptr<TreeNode<T>> TreeNode<T>::next(TreeWalkStrategy walkStrate
if (parent != nullptr) { if (parent != nullptr) {
auto nextOnLvl = nextOnSameLevel(); auto nextOnLvl = nextOnSameLevel();
if (nextOnLvl == nullptr){ if (nextOnLvl == nullptr){
for (auto n : this->getChildren()) for (auto n : parent->getChildren())
if (n->getChildren().size() > 0) if (n->getChildren().size() > 0)
return n->getChildren().front(); return n->getChildren().front();
//return n->getChildren().first(); //return n->getChildren().first();

View File

@ -0,0 +1,25 @@
#include "FieldFactory.h"
namespace NPC_core {
namespace Control {
AFieldFactory::AFieldFactory()
{
}
std::shared_ptr<Model::Field> AFieldFactory::createField(std::string name, std::shared_ptr<Model::AStructure> parentStructure)
{
auto f = std::make_shared<Model::Field>();
f->setName(name);
f->setParentStructure(parentStructure);
return f;
}
std::shared_ptr<Model::Field> AFieldFactory::createFieldFull(std::string name, std::map<std::string, std::string> syntaxes, std::shared_ptr<Model::AStructure> parentStructure)
{
auto f = std::make_shared<Model::Field>();
f->setName(name);
f->setSyntaxes(syntaxes);
f->setParentStructure(parentStructure);
return f;
}
}}

View File

@ -0,0 +1,19 @@
#ifndef AFIELDFACTORY_H
#define AFIELDFACTORY_H
#include "../model/Field.h"
#include <memory>
namespace NPC_core {
namespace Control {
class AFieldFactory
{
public:
AFieldFactory();
virtual ~AFieldFactory();
virtual std::shared_ptr<Model::Field> createField(std::string name, std::shared_ptr<Model::AStructure> parentStructure = nullptr);
virtual std::shared_ptr<Model::Field> createFieldFull(std::string name, std::map<std::string, std::string> syntaxes, std::shared_ptr<Model::AStructure> parentStructure = nullptr);
};
}}
#endif // AFIELDFACTORY_H

View File

@ -0,0 +1,19 @@
#ifndef AFIELDFACTORY_H
#define AFIELDFACTORY_H
#include "../model/Field.h"
#include <memory>
namespace NPC_core {
namespace Control {
class AFieldFactory
{
public:
AFieldFactory();
virtual ~AFieldFactory();
virtual std::shared_ptr<Model::Field> createField(std::string name, std::shared_ptr<Model::Structure> parentStructure = nullptr);
virtual std::shared_ptr<Model::Field> createFieldFull(std::string name, std::map<std::string, std::string> syntaxes, std::shared_ptr<Model::Structure> parentStructure = nullptr);
};
}}
#endif // AFIELDFACTORY_H

View File

@ -1,6 +1,8 @@
#include "AModelFactory.h" #include "AModelFactory.h"
namespace NPC_core {
namespace Control {
AModelFactory::AModelFactory() AModelFactory::AModelFactory()
{ {
} }
}}

View File

@ -1,11 +1,12 @@
#ifndef AMODELFACTORY_H #ifndef AMODELFACTORY_H
#define AMODELFACTORY_H #define AMODELFACTORY_H
namespace NPC_core {
namespace Control {
class AModelFactory class AModelFactory
{ {
public: public:
AModelFactory(); AModelFactory();
}; };
}}
#endif // AMODELFACTORY_H #endif // AMODELFACTORY_H

View File

@ -1,6 +1,8 @@
#include "ARepositoryFactory.h" #include "ARepositoryFactory.h"
namespace NPC_core {
namespace Control {
ARepositoryFactory::ARepositoryFactory() ARepositoryFactory::ARepositoryFactory()
{ {
} }
}}

View File

@ -1,11 +1,12 @@
#ifndef AREPOSITORYFACTORY_H #ifndef AREPOSITORYFACTORY_H
#define AREPOSITORYFACTORY_H #define AREPOSITORYFACTORY_H
namespace NPC_core {
namespace Control {
class ARepositoryFactory class ARepositoryFactory
{ {
public: public:
ARepositoryFactory(); ARepositoryFactory();
}; };
}}
#endif // AREPOSITORYFACTORY_H #endif // AREPOSITORYFACTORY_H

View File

@ -1,6 +1,8 @@
#include "AStructureFactory.h" #include "AStructureFactory.h"
namespace NPC_core {
namespace Control {
AStructureFactory::AStructureFactory() AStructureFactory::AStructureFactory()
{ {
} }
}}

View File

@ -1,11 +1,12 @@
#ifndef ASTRUCTUREFACTORY_H #ifndef ASTRUCTUREFACTORY_H
#define ASTRUCTUREFACTORY_H #define ASTRUCTUREFACTORY_H
namespace NPC_core {
namespace Control {
class AStructureFactory class AStructureFactory
{ {
public: public:
AStructureFactory(); AStructureFactory();
}; };
}}
#endif // ASTRUCTUREFACTORY_H #endif // ASTRUCTUREFACTORY_H

View File

@ -1,6 +0,0 @@
#include "AField.h"
AField::AField()
{
}

View File

@ -1,11 +0,0 @@
#ifndef AFIELD_H
#define AFIELD_H
class AField
{
public:
AField();
};
#endif // AFIELD_H

View File

@ -1,6 +0,0 @@
#include "AFieldFactory.h"
AFieldFactory::AFieldFactory()
{
}

View File

@ -1,11 +0,0 @@
#ifndef AFIELDFACTORY_H
#define AFIELDFACTORY_H
class AFieldFactory
{
public:
AFieldFactory();
};
#endif // AFIELDFACTORY_H

View File

@ -1,6 +0,0 @@
#include "AModel.h"
AModel::AModel()
{
}

View File

@ -1,11 +0,0 @@
#ifndef AMODEL_H
#define AMODEL_H
class AModel
{
public:
AModel();
};
#endif // AMODEL_H

View File

@ -1,6 +0,0 @@
#include "ARepository.h"
ARepository::ARepository()
{
}

View File

@ -1,11 +0,0 @@
#ifndef AREPOSITORY_H
#define AREPOSITORY_H
class ARepository
{
public:
ARepository();
};
#endif // AREPOSITORY_H

View File

@ -1,6 +0,0 @@
#include "AStructure.h"
AStructure::AStructure()
{
}

View File

@ -1,17 +0,0 @@
#ifndef ASTRUCTURE_H
#define ASTRUCTURE_H
#include <memory>
#include <list>
#include "AField.h"
class AStructure
{
public:
AStructure();
private:
std::list<std::shared_ptr<AField>> fields;
};
#endif // ASTRUCTURE_H

51
src/core/model/Field.cpp Normal file
View File

@ -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<std::string, std::string> Field::getSyntaxes() const
{
return syntaxes;
}
void Field::setSyntaxes(const std::map<std::string, std::string> &value)
{
syntaxes = value;
}
std::string Field::getValue() const
{
return value;
}
void Field::setValue(const std::string &value)
{
value = value;
}
std::shared_ptr<AStructure> Field::getParentStructure() const
{
return parentStructure;
}
void Field::setParentStructure(const std::shared_ptr<AStructure> &value)
{
parentStructure = value;
}
}
}

40
src/core/model/Field.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef AFIELD_H
#define AFIELD_H
#include "Structure.h"
#include <memory>
#include <string>
#include <map>
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<std::string, std::string> getSyntaxes() const;
void setSyntaxes(const std::map<std::string, std::string> &value);
std::string getValue() const;
void setValue(const std::string &value);
std::shared_ptr<Structure> getParentStructure() const;
void setParentStructure(const std::shared_ptr<Structure> &value);
protected:
std::shared_ptr<Structure> parentStructure;
std::string name;
std::map<std::string, std::string> syntaxes; // example : regex; for validation
std::string value;
};
}}
#endif // AFIELD_H

View File

@ -1,6 +0,0 @@
#include "IModelPlugin.h"
IModelPlugin::IModelPlugin()
{
}

View File

@ -1,11 +0,0 @@
#ifndef IMODELPLUGIN_H
#define IMODELPLUGIN_H
class IModelPlugin
{
public:
IModelPlugin();
};
#endif // IMODELPLUGIN_H

8
src/core/model/Model.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "Model.h"
namespace NPC_core {
namespace Model {
Model::Model()
{
}
}}

19
src/core/model/Model.h Normal file
View File

@ -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<Field> stack;
};
}}
#endif // AMODEL_H

View File

@ -1,6 +0,0 @@
#include "ModelPluginManager.h"
ModelPluginManager::ModelPluginManager()
{
}

View File

@ -1,12 +0,0 @@
#ifndef MODELPLUGINMANAGER_H
#define MODELPLUGINMANAGER_H
#include "../APluginManager.h"
class ModelPluginManager : public APluginManager
{
public:
ModelPluginManager();
};
#endif // MODELPLUGINMANAGER_H

View File

@ -0,0 +1,8 @@
#include "Repository.h"
namespace NPC_core {
namespace Model {
Repository::Repository()
{
}
}}

View File

@ -0,0 +1,19 @@
#ifndef AREPOSITORY_H
#define AREPOSITORY_H
#include <map>
#include "Structure.h"
namespace NPC_core {
namespace Model {
class Repository
{
public:
Repository();
virtual ~Repository();
private:
std::map<std::string, Structure> structures;
};
}}
#endif // AREPOSITORY_H

View File

@ -0,0 +1,8 @@
#include "Structure.h"
namespace NPC_core {
namespace Model {
AStructure::AStructure()
{
}
}}

View File

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

View File

@ -0,0 +1,29 @@
#ifndef ASTRUCTURE_H
#define ASTRUCTURE_H
#include <memory>
#include <list>
#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<Field> elements;
std::string name;
};
}}
#endif // ASTRUCTURE_H

View File

@ -3,6 +3,7 @@ set(HEADERS editorelementdata.h
guidededitorelementview.h guidededitorelementview.h
flowlayout.h flowlayout.h
EditorElementValue.h EditorElementValue.h
StructureField.h
) )
set(SOURCES guidededitorelementview.cpp set(SOURCES guidededitorelementview.cpp
@ -10,7 +11,7 @@ set(SOURCES guidededitorelementview.cpp
guidededitorview.cpp guidededitorview.cpp
flowlayout.cpp flowlayout.cpp
EditorElementValue.cpp EditorElementValue.cpp
StructureField.cpp
) )
add_library(editor ${HEADERS} ${SOURCES}) add_library(editor ${HEADERS} ${SOURCES})

View File

@ -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<NPC_core::Model::Field> 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();
}
}

View File

@ -0,0 +1,44 @@
#ifndef STRUCTUREFIELD_H
#define STRUCTUREFIELD_H
#include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QRegExpValidator>
#include "../core/model/AField.h"
#include <memory>
namespace NPC_editor {
class StructureField : public QWidget
{
Q_OBJECT
public:
explicit StructureField(QWidget *parent = nullptr);
explicit StructureField(const std::shared_ptr<NPC_core::Model::Field> field, QWidget *parent = nullptr);
signals:
public slots:
void inputChanged();
void dataChanged();
void nodeChanged();
void render();
void initialRender();
private:
std::shared_ptr<NPC_core::Model::Field> field;
// layout
QVBoxLayout* layout;
QLabel* title;
QTextEdit* edit;
QLineEdit* line;
QMap<QString, QWidget*> otherWidgets;
QRegExpValidator* validator;
QWidget* subContainer;
};
}
#endif // STRUCTUREFIELD_H