diff --git a/src/editor/EditorNode.cpp b/src/editor/EditorNode.cpp index 569dabc..94848e5 100644 --- a/src/editor/EditorNode.cpp +++ b/src/editor/EditorNode.cpp @@ -20,9 +20,10 @@ EditorNode::~EditorNode() const std::shared_ptr EditorNode::nextSibling() { if (parent != nullptr) { - int i = parent->getChildren().indexOf(std::shared_ptr(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(this)); + if (it != l.end() && ++it != l.end()) + return *(++it); //next sibling... else return nullptr; } @@ -41,7 +42,8 @@ const std::shared_ptr 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::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(this); while (node->nextSibling() == nullptr && node->getParent() != nullptr) @@ -75,7 +80,8 @@ const std::shared_ptr 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::getRoot() void EditorNode::move(std::shared_ptr to) { - this->getParent()->getChildren().removeOne(std::shared_ptr(this)); - to->getChildren().append(std::shared_ptr(this)); + this->getParent()->getChildren().remove(std::shared_ptr(this)); + //this->getParent()->getChildren().removeOne(std::shared_ptr(this)); + to->getChildren().push_back(std::shared_ptr(this)); + //to->getChildren().append(std::shared_ptr(this)); fireTreeChanged(); } @@ -106,14 +114,16 @@ void EditorNode::moveChildren(std::shared_ptr to) void EditorNode::addChild(std::shared_ptr child) { - this->getChildren().append(child); + this->getChildren().push_back(child); + //this->getChildren().append(child); child->setParent(std::shared_ptr(this)); fireTreeChanged(); } bool EditorNode::removeChild(std::shared_ptr 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(this)); + parent->getChildren().remove(std::shared_ptr(this)); + //worked &= parent->getChildren().removeOne(std::shared_ptr(this)); } if (worked) fireTreeChanged(); return worked; @@ -165,7 +176,7 @@ void EditorNode::setValue(const std::shared_ptr &value) this->value = value; } -QList > EditorNode::getChildren() const +std::list > EditorNode::getChildren() const { return children; } @@ -191,7 +202,8 @@ std::shared_ptr EditorNode::nextOnSameLevel() auto pnode = std::shared_ptr(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; diff --git a/src/editor/EditorNode.h b/src/editor/EditorNode.h index 909c0d7..55aa754 100644 --- a/src/editor/EditorNode.h +++ b/src/editor/EditorNode.h @@ -2,8 +2,8 @@ #define EDITORNODE_H #include -#include #include +#include #include "editorelementdata.h" #include "EditorElementValue.h" @@ -43,7 +43,7 @@ public: std::shared_ptr getValue() const; void setValue(const std::shared_ptr &value); - QList > getChildren() const; + std::list > getChildren() const; void setDataChangedSignal(std::function)> f) { @@ -68,7 +68,7 @@ private: std::shared_ptr parent; std::shared_ptr data; std::shared_ptr value; - QList> children; + std::list> children; }; #endif // EDITORNODE_H diff --git a/src/editor/editorelementdata.h b/src/editor/editorelementdata.h index 5189dd1..749ee0e 100644 --- a/src/editor/editorelementdata.h +++ b/src/editor/editorelementdata.h @@ -3,6 +3,8 @@ #include #include #include +#include +#include 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 getSyntaxes() const; void setSyntaxes(const QList &value); + void setSyntaxes(const std::list &value) { + QList 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 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); diff --git a/src/protocol/DataLoader.cpp b/src/protocol/DataLoader.cpp index 6a4194a..f4a146a 100644 --- a/src/protocol/DataLoader.cpp +++ b/src/protocol/DataLoader.cpp @@ -1,37 +1,47 @@ #include "DataLoader.h" -#include +#include +#include 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 DataLoader::generateTree(YAML::Node &node) { if(!node["protocol"]) @@ -41,9 +51,9 @@ std::shared_ptr DataLoader::generateTree(YAML::Node &node) std::shared_ptr editorNode = std::shared_ptr(new EditorNode()); std::shared_ptr data = std::shared_ptr(new EditorElementData()); - data->setTitle(QString::fromStdString(node["protocol"]["name"].as())); + data->setTitle(node["protocol"]["name"].as()); if(node["protocol"]["longname"]) - data->setHint("subtitle", QString::fromStdString(node["protocol"]["longname"].as())); + data->setHint("subtitle", node["protocol"]["longname"].as()); editorNode->setData(data); // add children containing the fields auto fields = node["protocol"]["fields"]; @@ -53,11 +63,11 @@ std::shared_ptr 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())) { + if(name.compare(n["protocol"]["name"].as()) == 0) { node = n; return true; } @@ -66,12 +76,12 @@ bool DataLoader::getProtocolByName(QString name, YAML::Node &node) return false; } -QStringList DataLoader::getProtocolNames() +std::list DataLoader::getProtocolNames() { - QStringList names; + std::list names; for(YAML::Node node : protocolList) { if(node["protocol"]) { - names << QString::fromStdString(node["protocol"]["name"].as()); + names.push_back(node["protocol"]["name"].as()); } } return names; @@ -83,9 +93,9 @@ std::shared_ptr DataLoader::genNode(YAML::Node &n, std::shared_ptr newNode = std::shared_ptr(new EditorNode()); newNode->setParent(parent); std::shared_ptr newData = std::shared_ptr(new EditorElementData()); - newData->setTitle(QString::fromStdString(n["field"].as())); + newData->setTitle(n["field"].as()); if(n["desc"]) - newData->setHint("desc", QString::fromStdString(n["desc"].as())); + newData->setHint("desc",n["desc"].as()); if(n["bytes"]) newData->setBytes(n["bytes"].as()); else if (n["bits"]) diff --git a/src/protocol/DataLoader.h b/src/protocol/DataLoader.h index a236aad..cd1029c 100644 --- a/src/protocol/DataLoader.h +++ b/src/protocol/DataLoader.h @@ -3,8 +3,8 @@ #include -#include -#include +#include +#include #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 generateTree(YAML::Node &node); - bool getProtocolByName(QString name, YAML::Node &node); - QStringList getProtocolNames(); + bool getProtocolByName(std::string name, YAML::Node &node); + std::list getProtocolNames(); private: std::shared_ptr genNode(YAML::Node& n, std::shared_ptr parent = nullptr); - QString directory; - QList protocolList; + std::string directory; + std::list protocolList; };