refactored classes to only use std or boost, not Qt, for easier
modularization.
This commit is contained in:
parent
a47213104c
commit
160501b7ca
|
@ -20,9 +20,10 @@ EditorNode::~EditorNode()
|
|||
const std::shared_ptr<EditorNode> EditorNode::nextSibling()
|
||||
{
|
||||
if (parent != nullptr) {
|
||||
int i = parent->getChildren().indexOf(std::shared_ptr<EditorNode>(this));
|
||||
if (i + 1 < parent->getChildren().size())
|
||||
return parent->getChildren().at(i + 1); //next sibling...
|
||||
auto l = parent->getChildren();
|
||||
auto it = std::find(l.begin(), l.end(), std::shared_ptr<EditorNode>(this));
|
||||
if (it != l.end() && ++it != l.end())
|
||||
return *(++it); //next sibling...
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -41,7 +42,8 @@ const std::shared_ptr<EditorNode> EditorNode::next(TreeWalkStrategy walkStrategy
|
|||
{
|
||||
for (auto n : parent->getChildren())
|
||||
if (n->getChildren().size() > 0)
|
||||
return n->getChildren().first();
|
||||
return n->getChildren().front();
|
||||
//return n->getChildren().first();
|
||||
auto siblingOfParent = parent->nextSibling();
|
||||
while (siblingOfParent != nullptr && siblingOfParent->getChildren().size() == 0) {
|
||||
if (siblingOfParent->nextSibling() == nullptr)
|
||||
|
@ -50,19 +52,22 @@ const std::shared_ptr<EditorNode> EditorNode::next(TreeWalkStrategy walkStrategy
|
|||
siblingOfParent = siblingOfParent->nextSibling();
|
||||
}
|
||||
if (siblingOfParent != nullptr)
|
||||
return siblingOfParent->getChildren().first();
|
||||
return siblingOfParent->getChildren().front();
|
||||
//return siblingOfParent->getChildren().first();
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
if (getChildren().size() > 0)
|
||||
return getChildren().first();
|
||||
return getChildren().front();
|
||||
//return getChildren().first();
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
else if (walkStrategy == TreeWalkStrategy::depthFirst)
|
||||
if (getChildren().size() > 0)
|
||||
return getChildren().first();
|
||||
return getChildren().front();
|
||||
//return getChildren().first();
|
||||
else {
|
||||
auto node = std::shared_ptr<EditorNode>(this);
|
||||
while (node->nextSibling() == nullptr && node->getParent() != nullptr)
|
||||
|
@ -75,7 +80,8 @@ const std::shared_ptr<EditorNode> EditorNode::next(TreeWalkStrategy walkStrategy
|
|||
if (nextOnLvl == nullptr){
|
||||
for (auto n : this->getChildren())
|
||||
if (n->getChildren().size() > 0)
|
||||
return n->getChildren().first();
|
||||
return n->getChildren().front();
|
||||
//return n->getChildren().first();
|
||||
}
|
||||
else return nextOnLvl;
|
||||
}
|
||||
|
@ -92,8 +98,10 @@ const std::shared_ptr<EditorNode> EditorNode::getRoot()
|
|||
|
||||
void EditorNode::move(std::shared_ptr<EditorNode> to)
|
||||
{
|
||||
this->getParent()->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
||||
to->getChildren().append(std::shared_ptr<EditorNode>(this));
|
||||
this->getParent()->getChildren().remove(std::shared_ptr<EditorNode>(this));
|
||||
//this->getParent()->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
||||
to->getChildren().push_back(std::shared_ptr<EditorNode>(this));
|
||||
//to->getChildren().append(std::shared_ptr<EditorNode>(this));
|
||||
fireTreeChanged();
|
||||
}
|
||||
|
||||
|
@ -106,14 +114,16 @@ void EditorNode::moveChildren(std::shared_ptr<EditorNode> to)
|
|||
|
||||
void EditorNode::addChild(std::shared_ptr<EditorNode> child)
|
||||
{
|
||||
this->getChildren().append(child);
|
||||
this->getChildren().push_back(child);
|
||||
//this->getChildren().append(child);
|
||||
child->setParent(std::shared_ptr<EditorNode>(this));
|
||||
fireTreeChanged();
|
||||
}
|
||||
|
||||
bool EditorNode::removeChild(std::shared_ptr<EditorNode> child)
|
||||
{
|
||||
bool ret = this->getChildren().removeOne(child);
|
||||
this->getChildren().remove(child);
|
||||
bool ret = true; //this->getChildren().removeOne(child);
|
||||
if (ret) fireTreeChanged();
|
||||
return ret;
|
||||
}
|
||||
|
@ -127,7 +137,8 @@ bool EditorNode::remove()
|
|||
}
|
||||
}
|
||||
if (worked && parent != nullptr) {
|
||||
worked &= parent->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
||||
parent->getChildren().remove(std::shared_ptr<EditorNode>(this));
|
||||
//worked &= parent->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
||||
}
|
||||
if (worked) fireTreeChanged();
|
||||
return worked;
|
||||
|
@ -165,7 +176,7 @@ void EditorNode::setValue(const std::shared_ptr<EditorElementValue> &value)
|
|||
this->value = value;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<EditorNode> > EditorNode::getChildren() const
|
||||
std::list<std::shared_ptr<EditorNode> > EditorNode::getChildren() const
|
||||
{
|
||||
return children;
|
||||
}
|
||||
|
@ -191,7 +202,8 @@ std::shared_ptr<EditorNode> EditorNode::nextOnSameLevel()
|
|||
auto pnode = std::shared_ptr<EditorNode>(this);
|
||||
while (lvl > 0 && node != nullptr) {
|
||||
if (node != pnode->getParent() && node->getChildren().size() > 0) {
|
||||
node = node->getChildren().first();
|
||||
node = node->getChildren().front();
|
||||
//node = node->getChildren().first();
|
||||
--lvl;
|
||||
} else {
|
||||
pnode = node;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define EDITORNODE_H
|
||||
|
||||
#include <memory>
|
||||
#include <QList>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
|
||||
#include "editorelementdata.h"
|
||||
#include "EditorElementValue.h"
|
||||
|
@ -43,7 +43,7 @@ public:
|
|||
std::shared_ptr<EditorElementValue> getValue() const;
|
||||
void setValue(const std::shared_ptr<EditorElementValue> &value);
|
||||
|
||||
QList<std::shared_ptr<EditorNode> > getChildren() const;
|
||||
std::list<std::shared_ptr<EditorNode> > getChildren() const;
|
||||
|
||||
void setDataChangedSignal(std::function<void(std::shared_ptr<EditorNode>)> f)
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ private:
|
|||
std::shared_ptr<EditorNode> parent;
|
||||
std::shared_ptr<EditorElementData> data;
|
||||
std::shared_ptr<EditorElementValue> value;
|
||||
QList<std::shared_ptr<EditorNode>> children;
|
||||
std::list<std::shared_ptr<EditorNode>> children;
|
||||
};
|
||||
|
||||
#endif // EDITORNODE_H
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
enum class ValueType {
|
||||
BIN,OCT,DEC,HEX,TXT
|
||||
|
@ -19,12 +21,24 @@ public:
|
|||
|
||||
QString getTitle() const;
|
||||
void setTitle(const QString &value);
|
||||
void setTitle(const std::string &value) {
|
||||
this->setTitle(QString::fromStdString(value));
|
||||
}
|
||||
|
||||
QString getId() const;
|
||||
void setId(const QString &value);
|
||||
void setId(const std::string &value){
|
||||
this->setId(QString::fromStdString(value));
|
||||
}
|
||||
|
||||
QList<QString> getSyntaxes() const;
|
||||
void setSyntaxes(const QList<QString> &value);
|
||||
void setSyntaxes(const std::list<std::string> &value) {
|
||||
QList<QString> newlist;
|
||||
for(std::string str : value)
|
||||
newlist.append(QString::fromStdString(str));
|
||||
this->setSyntaxes(newlist);
|
||||
}
|
||||
|
||||
bool isMultiLine() const;
|
||||
void setIsMultiLine(bool value);
|
||||
|
@ -34,9 +48,15 @@ public:
|
|||
|
||||
QString getRegex() const;
|
||||
void setRegex(const QString &value);
|
||||
void setRegex(const std::string &value){
|
||||
this->setRegex(QString::fromStdString(value));
|
||||
}
|
||||
|
||||
QMap<QString, QString> getHints() const;
|
||||
void setHint(const QString &key, const QString &value);
|
||||
void setHint(const std::string &key, const std::string &value){
|
||||
this->setHint(QString::fromStdString(key), QString::fromStdString(value));
|
||||
}
|
||||
|
||||
ulong getBytes() const;
|
||||
void setBytes(const ulong &value);
|
||||
|
|
|
@ -1,36 +1,46 @@
|
|||
#include "DataLoader.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <string>
|
||||
|
||||
DataLoader::DataLoader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DataLoader::DataLoader(QString directory)
|
||||
DataLoader::DataLoader(std::string directory) : DataLoader()
|
||||
{
|
||||
|
||||
this->loadProtocolDirectory(directory);
|
||||
}
|
||||
|
||||
void DataLoader::loadProtocolDirectory(QString directory)
|
||||
void DataLoader::loadProtocolDirectory(std::__cxx11::string directory)
|
||||
{
|
||||
using namespace boost::filesystem;
|
||||
// awaiting
|
||||
QDir dir(directory);
|
||||
QStringList filters;
|
||||
filters << "*osi*";
|
||||
for(QString entry : dir.entryList(filters)){
|
||||
if(QDir(entry).exists()) {
|
||||
QDir cdir(entry);
|
||||
QStringList ymlfilter;
|
||||
ymlfilter << "*.yml";
|
||||
for(QString file : cdir.entryList(ymlfilter)){
|
||||
YAML::Node node = YAML::LoadFile(
|
||||
QString(directory + QDir::separator() + entry + QDir::separator() + file).toStdString());
|
||||
protocolList.append(node);
|
||||
path p(directory);
|
||||
if (exists(p)) {
|
||||
// load all files in osi* directories
|
||||
for(directory_entry& d : directory_iterator(p))
|
||||
{
|
||||
if(is_directory(d) && d.path().filename().string().find("osi") != std::string::npos)
|
||||
{
|
||||
path osi = d.path();
|
||||
for(directory_entry& od: directory_iterator(p))
|
||||
{
|
||||
if(od.path().extension().string().compare(std::string(".yml")) == 0 ) {
|
||||
this->loadSingleProtocol(od.path().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataLoader::loadSingleProtocol(std::__cxx11::string filename)
|
||||
{
|
||||
YAML::Node node = YAML::LoadFile(filename);
|
||||
protocolList.push_back(node);
|
||||
}
|
||||
|
||||
std::shared_ptr<EditorNode> DataLoader::generateTree(YAML::Node &node)
|
||||
{
|
||||
|
@ -41,9 +51,9 @@ std::shared_ptr<EditorNode> DataLoader::generateTree(YAML::Node &node)
|
|||
std::shared_ptr<EditorNode> editorNode = std::shared_ptr<EditorNode>(new EditorNode());
|
||||
std::shared_ptr<EditorElementData> data = std::shared_ptr<EditorElementData>(new EditorElementData());
|
||||
|
||||
data->setTitle(QString::fromStdString(node["protocol"]["name"].as<std::string>()));
|
||||
data->setTitle(node["protocol"]["name"].as<std::string>());
|
||||
if(node["protocol"]["longname"])
|
||||
data->setHint("subtitle", QString::fromStdString(node["protocol"]["longname"].as<std::string>()));
|
||||
data->setHint("subtitle", node["protocol"]["longname"].as<std::string>());
|
||||
editorNode->setData(data);
|
||||
// add children containing the fields
|
||||
auto fields = node["protocol"]["fields"];
|
||||
|
@ -53,11 +63,11 @@ std::shared_ptr<EditorNode> DataLoader::generateTree(YAML::Node &node)
|
|||
return editorNode;
|
||||
}
|
||||
|
||||
bool DataLoader::getProtocolByName(QString name, YAML::Node &node)
|
||||
bool DataLoader::getProtocolByName(std::string name, YAML::Node &node)
|
||||
{
|
||||
for(YAML::Node n : protocolList) {
|
||||
if(n["protocol"]) {
|
||||
if(name.toStdString().compare(n["protocol"]["name"].as<std::string>())) {
|
||||
if(name.compare(n["protocol"]["name"].as<std::string>()) == 0) {
|
||||
node = n;
|
||||
return true;
|
||||
}
|
||||
|
@ -66,12 +76,12 @@ bool DataLoader::getProtocolByName(QString name, YAML::Node &node)
|
|||
return false;
|
||||
}
|
||||
|
||||
QStringList DataLoader::getProtocolNames()
|
||||
std::list<std::string> DataLoader::getProtocolNames()
|
||||
{
|
||||
QStringList names;
|
||||
std::list<std::string> names;
|
||||
for(YAML::Node node : protocolList) {
|
||||
if(node["protocol"]) {
|
||||
names << QString::fromStdString(node["protocol"]["name"].as<std::string>());
|
||||
names.push_back(node["protocol"]["name"].as<std::string>());
|
||||
}
|
||||
}
|
||||
return names;
|
||||
|
@ -83,9 +93,9 @@ std::shared_ptr<EditorNode> DataLoader::genNode(YAML::Node &n, std::shared_ptr<E
|
|||
std::shared_ptr<EditorNode> newNode = std::shared_ptr<EditorNode>(new EditorNode());
|
||||
newNode->setParent(parent);
|
||||
std::shared_ptr<EditorElementData> newData = std::shared_ptr<EditorElementData>(new EditorElementData());
|
||||
newData->setTitle(QString::fromStdString(n["field"].as<std::string>()));
|
||||
newData->setTitle(n["field"].as<std::string>());
|
||||
if(n["desc"])
|
||||
newData->setHint("desc", QString::fromStdString(n["desc"].as<std::string>()));
|
||||
newData->setHint("desc",n["desc"].as<std::string>());
|
||||
if(n["bytes"])
|
||||
newData->setBytes(n["bytes"].as<ulong>());
|
||||
else if (n["bits"])
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include "../editor/EditorNode.h"
|
||||
|
||||
|
@ -12,19 +12,21 @@
|
|||
class DataLoader {
|
||||
public:
|
||||
explicit DataLoader();
|
||||
explicit DataLoader(QString directory);
|
||||
explicit DataLoader(std::string directory);
|
||||
|
||||
void loadProtocolDirectory(QString directory);
|
||||
void loadProtocolDirectory(std::string directory);
|
||||
|
||||
void loadSingleProtocol(std::string filename);
|
||||
|
||||
std::shared_ptr<EditorNode> generateTree(YAML::Node &node);
|
||||
|
||||
bool getProtocolByName(QString name, YAML::Node &node);
|
||||
QStringList getProtocolNames();
|
||||
bool getProtocolByName(std::string name, YAML::Node &node);
|
||||
std::list<std::string> getProtocolNames();
|
||||
|
||||
private:
|
||||
std::shared_ptr<EditorNode> genNode(YAML::Node& n, std::shared_ptr<EditorNode> parent = nullptr);
|
||||
QString directory;
|
||||
QList<YAML::Node> protocolList;
|
||||
std::string directory;
|
||||
std::list<YAML::Node> protocolList;
|
||||
};
|
||||
|
||||
|
||||
|
|
Reference in New Issue