From 14605ac0cba996af1014432cb5e3bfc01a2af433 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Mon, 4 Jan 2016 17:49:12 +0100 Subject: [PATCH] more structure, proper cmake-ing and c++14 fixes --- .gitignore | 1 + CMakeLists.txt.user | 285 ------------------ src/CMakeLists.txt | 20 +- src/editor/CMakeLists.txt | 20 ++ .../abstractguidededitormodel.cpp | 0 src/{ => editor}/abstractguidededitormodel.h | 0 src/{ => editor}/flowlayout.cpp | 0 src/{ => editor}/flowlayout.h | 0 src/{ => editor}/guidededitorelement.cpp | 0 src/{ => editor}/guidededitorelement.h | 0 src/editor/guidededitorelementview.cpp | 17 ++ src/{ => editor}/guidededitorelementview.h | 10 +- src/{ => editor}/guidededitorlayer.cpp | 0 src/{ => editor}/guidededitorlayer.h | 0 src/editor/guidededitorview.cpp | 28 ++ src/editor/guidededitorview.h | 27 ++ src/guidededitorelementview.cpp | 7 - src/guidededitorview.cpp | 30 -- src/guidededitorview.h | 29 -- src/mainwindow.cpp | 14 +- src/mainwindow.h | 9 +- src/model/CMakeLists.txt | 10 + src/model/packetelement.cpp | 11 + src/model/packetelement.h | 99 ++++++ src/model/packetmodel.cpp | 13 + src/model/packetmodel.h | 20 ++ 26 files changed, 270 insertions(+), 380 deletions(-) delete mode 100644 CMakeLists.txt.user create mode 100644 src/editor/CMakeLists.txt rename src/{ => editor}/abstractguidededitormodel.cpp (100%) rename src/{ => editor}/abstractguidededitormodel.h (100%) rename src/{ => editor}/flowlayout.cpp (100%) rename src/{ => editor}/flowlayout.h (100%) rename src/{ => editor}/guidededitorelement.cpp (100%) rename src/{ => editor}/guidededitorelement.h (100%) create mode 100644 src/editor/guidededitorelementview.cpp rename src/{ => editor}/guidededitorelementview.h (83%) rename src/{ => editor}/guidededitorlayer.cpp (100%) rename src/{ => editor}/guidededitorlayer.h (100%) create mode 100644 src/editor/guidededitorview.cpp create mode 100644 src/editor/guidededitorview.h delete mode 100644 src/guidededitorelementview.cpp delete mode 100644 src/guidededitorview.cpp delete mode 100644 src/guidededitorview.h create mode 100644 src/model/CMakeLists.txt create mode 100644 src/model/packetelement.cpp create mode 100644 src/model/packetelement.h create mode 100644 src/model/packetmodel.cpp create mode 100644 src/model/packetmodel.h diff --git a/.gitignore b/.gitignore index e02e1c5..f8ac05f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.mm *.pro.user build +*.user* diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 7a2f43f..0000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,285 +0,0 @@ - - - - - - EnvironmentId - {8fe85189-3226-423c-bccf-c2236465442c} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - 1 - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop - {211a0c20-f25f-4bf4-b929-1284740fe4d9} - 0 - 0 - 0 - - - false - /home/qwc/source/npc/build - - - - - false - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - clean - - true - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Vorgabe - Vorgabe - CMakeProjectManager.CMakeBuildConfiguration - - - -DCMAKE_BUILD_TYPE=Debug - false - /home/qwc/source/npc/build/debug - - - - - false - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - clean - - true - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - -DCMAKE_BUILD_TYPE=Release - false - /home/qwc/source/npc/build/release - - - - - false - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - clean - - true - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - CMakeProjectManager.CMakeBuildConfiguration - - 3 - - - 0 - Deployment - - ProjectExplorer.BuildSteps.Deploy - - 1 - Lokales Deployment - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - npc - - - 2 - - npc - - CMakeProjectManager.CMakeRunConfiguration.npc - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f460f40..88a4a42 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,20 +1,12 @@ -set(HEADERS abstractguidededitormodel.h - flowlayout.h - guidededitorelement.h - guidededitorelementview.h - guidededitorlayer.h - guidededitorview.h - mainwindow.h +set(HEADERS mainwindow.h ) -set(SOURCES abstractguidededitormodel.cpp - flowlayout.cpp - guidededitorelement.cpp - guidededitorelementview.cpp - guidededitorlayer.cpp - guidededitorview.cpp - mainwindow.cpp +set(SOURCES mainwindow.cpp ) +add_subdirectory(model) +add_subdirectory(editor) + add_library(src ${HEADERS} ${SOURCES}) +target_link_libraries(src model editor) qt5_use_modules(src Widgets) diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt new file mode 100644 index 0000000..042095c --- /dev/null +++ b/src/editor/CMakeLists.txt @@ -0,0 +1,20 @@ + +set(HEADERS abstractguidededitormodel.h + guidededitorelement.h + guidededitorelementview.h + guidededitorlayer.h + guidededitorlayer.h + flowlayout.h +) + +set(SOURCES guidededitorelementview.cpp + guidededitorelement.cpp + abstractguidededitormodel.cpp + guidededitorlayer.cpp + guidededitorview.cpp + flowlayout.cpp +) + +add_library(editor ${HEADERS} ${SOURCES}) + +qt5_use_modules(editor Widgets) diff --git a/src/abstractguidededitormodel.cpp b/src/editor/abstractguidededitormodel.cpp similarity index 100% rename from src/abstractguidededitormodel.cpp rename to src/editor/abstractguidededitormodel.cpp diff --git a/src/abstractguidededitormodel.h b/src/editor/abstractguidededitormodel.h similarity index 100% rename from src/abstractguidededitormodel.h rename to src/editor/abstractguidededitormodel.h diff --git a/src/flowlayout.cpp b/src/editor/flowlayout.cpp similarity index 100% rename from src/flowlayout.cpp rename to src/editor/flowlayout.cpp diff --git a/src/flowlayout.h b/src/editor/flowlayout.h similarity index 100% rename from src/flowlayout.h rename to src/editor/flowlayout.h diff --git a/src/guidededitorelement.cpp b/src/editor/guidededitorelement.cpp similarity index 100% rename from src/guidededitorelement.cpp rename to src/editor/guidededitorelement.cpp diff --git a/src/guidededitorelement.h b/src/editor/guidededitorelement.h similarity index 100% rename from src/guidededitorelement.h rename to src/editor/guidededitorelement.h diff --git a/src/editor/guidededitorelementview.cpp b/src/editor/guidededitorelementview.cpp new file mode 100644 index 0000000..f4e59ca --- /dev/null +++ b/src/editor/guidededitorelementview.cpp @@ -0,0 +1,17 @@ +#include "guidededitorelementview.h" + +GuidedEditorElementView::GuidedEditorElementView(QWidget *parent) : QWidget(parent) +{ + +} + +void GuidedEditorElementView::setElement() +{ + +} + +void GuidedEditorElementView::dataChanged() +{ + +} + diff --git a/src/guidededitorelementview.h b/src/editor/guidededitorelementview.h similarity index 83% rename from src/guidededitorelementview.h rename to src/editor/guidededitorelementview.h index dfc5c14..4ad5a7f 100644 --- a/src/guidededitorelementview.h +++ b/src/editor/guidededitorelementview.h @@ -1,23 +1,24 @@ #ifndef GUIDEDEDITORELEMENTVIEW_H #define GUIDEDEDITORELEMENTVIEW_H -#include "guidededitorelement.h" #include #include #include -#include "guidededitorlayer.h" #include #include #include +#include "guidededitorlayer.h" + class GuidedEditorElementView : public QWidget { Q_OBJECT public: - explicit GuidedEditorElementView(GuidedEditorElement* element, QWidget *parent = 0); + explicit GuidedEditorElementView(QWidget *parent = 0); + //explicit GuidedEditorElementView( QWidget *parent = 0); - void setElement(GuidedEditorElement* element); + void setElement(); signals: @@ -42,6 +43,7 @@ private: std::unique_ptr combobox; // layer information std::shared_ptr layer; + }; #endif // GUIDEDEDITORELEMENTVIEW_H diff --git a/src/guidededitorlayer.cpp b/src/editor/guidededitorlayer.cpp similarity index 100% rename from src/guidededitorlayer.cpp rename to src/editor/guidededitorlayer.cpp diff --git a/src/guidededitorlayer.h b/src/editor/guidededitorlayer.h similarity index 100% rename from src/guidededitorlayer.h rename to src/editor/guidededitorlayer.h diff --git a/src/editor/guidededitorview.cpp b/src/editor/guidededitorview.cpp new file mode 100644 index 0000000..93eb34e --- /dev/null +++ b/src/editor/guidededitorview.cpp @@ -0,0 +1,28 @@ +#include "guidededitorview.h" +#include "guidededitorelementview.h" + +GuidedEditorView::GuidedEditorView(QWidget* parent) : QWidget(parent) { + editorLayout = new FlowLayout(this); + this->setLayout(editorLayout); + // tests + QString style = QString( + "QWidget {" + "border-radius: 5px;" + "background: white }" + "QLabel {border: 2px dashed black; background: gray; " + "border-radius: 5px;}" + "QLineEdit {border: 2px dashed black;background: dark-gray;" + "border-radius: 5px;}"); + this->setStyleSheet(style); +} + +GuidedEditorView::GuidedEditorView( + std::shared_ptr model, + QWidget* parent) + : GuidedEditorView(parent) {} + +GuidedEditorView::~GuidedEditorView() {} + +void GuidedEditorView::addElement() { + this->editorLayout->addWidget(new GuidedEditorElementView()); +} diff --git a/src/editor/guidededitorview.h b/src/editor/guidededitorview.h new file mode 100644 index 0000000..4814258 --- /dev/null +++ b/src/editor/guidededitorview.h @@ -0,0 +1,27 @@ +#ifndef GUIDEDEDITOR_H +#define GUIDEDEDITOR_H + +#include +#include +#include "flowlayout.h" +#include "guidededitorelement.h" +#include "abstractguidededitormodel.h" + +class GuidedEditorView : public QWidget { + Q_OBJECT +public: + explicit GuidedEditorView(QWidget* parent = 0); + GuidedEditorView(std::shared_ptr model, + QWidget* parent = 0); + ~GuidedEditorView(); + +signals: + +public slots: + void addElement(); + +private: + FlowLayout* editorLayout; +}; + +#endif // GUIDEDEDITOR_H diff --git a/src/guidededitorelementview.cpp b/src/guidededitorelementview.cpp deleted file mode 100644 index 29adf36..0000000 --- a/src/guidededitorelementview.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "guidededitorelementview.h" - -GuidedEditorElementView::GuidedEditorElementView(GuidedEditorElement *element, QWidget *parent) : QWidget(parent) -{ - -} - diff --git a/src/guidededitorview.cpp b/src/guidededitorview.cpp deleted file mode 100644 index f4d248c..0000000 --- a/src/guidededitorview.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "guidededitorview.h" - -GuidedEditorView::GuidedEditorView(QWidget * parent): QWidget(parent) { - editorLayout = new FlowLayout(this); - this->setLayout(editorLayout); - //tests - QString style = QString( - "QWidget {" - "border-radius: 5px;" - "background: white }" - "QLabel {border: 2px dashed black; background: gray; " - "border-radius: 5px;}" - "QLineEdit {border: 2px dashed black;background: dark-gray;" - "border-radius: 5px;}" - ); - this->setStyleSheet(style); -} - -GuidedEditorView::GuidedEditorView(std::shared_ptr model,QWidget *parent) :GuidedEditorView(parent) -{ - - -} - - -GuidedEditorView::~GuidedEditorView() -{ - -} - diff --git a/src/guidededitorview.h b/src/guidededitorview.h deleted file mode 100644 index d994778..0000000 --- a/src/guidededitorview.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef GUIDEDEDITOR_H -#define GUIDEDEDITOR_H - -#include -#include -#include "flowlayout.h" -#include "guidededitorelement.h" -#include "abstractguidededitormodel.h" - -class GuidedEditorView : public QWidget -{ - Q_OBJECT -public: - explicit GuidedEditorView(QWidget *parent = 0); - explicit GuidedEditorView(std::shared_ptr model, QWidget *parent); - ~GuidedEditorView(); - -signals: - -public slots: - -private: - FlowLayout* editorLayout; - - - -}; - -#endif // GUIDEDEDITOR_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 57b0555..382e184 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4,18 +4,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - editor = new GuidedEditorView(this); - this->setCentralWidget(editor); - dockWidget = new QDockWidget(this); - this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget); + editor = std::make_shared(this); + this->setCentralWidget(editor.get()); + dockWidget = std::make_shared(this); + this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget.get()); // dockwidget - QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget); + QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget.get()); dockWidget->setLayout(dockLayout); - QPushButton* button = new QPushButton(dockWidget); + QPushButton* button = new QPushButton(dockWidget.get()); button->setText("add"); dockLayout->addWidget(button); -// this->connect(button, &QPushButton::pressed,editor, &GuidedEditorView::addElement); + //this->connect(button, &QPushButton::pressed,editor, &GuidedEditorView::addElement); } diff --git a/src/mainwindow.h b/src/mainwindow.h index e4ff0cf..5d0d87d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,19 +1,20 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include #include #include -#include "flowlayout.h" -#include "guidededitorview.h" #include #include +#include "editor/guidededitorview.h" + class MainWindow : public QMainWindow { Q_OBJECT private: - GuidedEditorView* editor; - QDockWidget* dockWidget; + std::shared_ptr editor; + std::shared_ptr dockWidget; public: MainWindow(QWidget *parent = 0); diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt new file mode 100644 index 0000000..b98c3d2 --- /dev/null +++ b/src/model/CMakeLists.txt @@ -0,0 +1,10 @@ + +set(HEADERS packetmodel.h + packetelement.h +) + +set(SOURCES packetmodel.cpp + packetelement.cpp +) + +add_library(model ${HEADERS} ${SOURCES}) diff --git a/src/model/packetelement.cpp b/src/model/packetelement.cpp new file mode 100644 index 0000000..2772ef3 --- /dev/null +++ b/src/model/packetelement.cpp @@ -0,0 +1,11 @@ +#include "packetelement.h" + +PacketElement::PacketElement(std::__cxx11::string name, uint32_t sizeInBit, uint16_t layer): name(name), sizeInBit(sizeInBit), layer(layer) +{ + +} + +void PacketElement::setValue(std::__cxx11::string &value, ValueType type) +{ + +} diff --git a/src/model/packetelement.h b/src/model/packetelement.h new file mode 100644 index 0000000..b34edea --- /dev/null +++ b/src/model/packetelement.h @@ -0,0 +1,99 @@ +#ifndef PACKETELEMENT_H +#define PACKETELEMENT_H + +#include +#include +#include +#include + + +class PacketElement; + +typedef + std::list> + PacketElementList_t; + + /** + @brief The ValueType enum + */ +enum class ValueType { hexBinary, integer, text, base64 }; + +class ElementSyntax +{ +public: + std::string triggerRegex; + std::string completeRegex; + std::string example; +}; + + +/** + @brief The PacketElement class + */ + +class PacketElement +{ +public: + /** + @brief PacketElement + @param name + @param sizeInBit + @param layer + */ + PacketElement(std::string name, uint32_t sizeInBit, uint16_t layer); + /** + @brief setValue + @param value + */ + void setValue(std::string& value) {this->value = value; this->valueType = ValueType::text; } + /** + @brief setValue + @param value + @param type + */ + void setValue(std::string& value, ValueType type); + + const std::string getValue() { return value; } + uint32_t getSizeInBit() { return sizeInBit; } + uint16_t getLayer() { return layer; } + const std::string getName() { return name; } + const std::string getDescription() { return description; } + + + const std::shared_ptr getNextLayer() { return nextLayer; } + /** + @brief hasNextLayer + @return + */ + bool hasNextLayer() { return nextLayer != nullptr && sizeInBit == 0; } + /** + @brief setNextLayer + @param layerElements + */ + void setNextLayer(std::shared_ptr& layerElements) { nextLayer = layerElements; } + + void addSyntax(std::string minimalRegex, std::string completeRegex, std::string example) + { + ElementSyntax syntax; + syntax.triggerRegex = minimalRegex; + syntax.completeRegex = completeRegex; + syntax.example = example; + syntaxes.push_back(syntax); + } + +private: + std::string name; + uint32_t sizeInBit; + uint16_t layer; + std::string value; + ValueType valueType; + + std::shared_ptr nextLayer; + + //additional data + std::string description; + std::list syntaxes; + +}; + +#endif // PACKETELEMENT_H diff --git a/src/model/packetmodel.cpp b/src/model/packetmodel.cpp new file mode 100644 index 0000000..7386dad --- /dev/null +++ b/src/model/packetmodel.cpp @@ -0,0 +1,13 @@ +#include "packetmodel.h" + +#include "packetelement.h" + +PacketModel::PacketModel() +{ + this->elementList = std::make_shared(); +} + +const std::shared_ptr PacketModel::getList() +{ + return this->elementList; +} diff --git a/src/model/packetmodel.h b/src/model/packetmodel.h new file mode 100644 index 0000000..d90c197 --- /dev/null +++ b/src/model/packetmodel.h @@ -0,0 +1,20 @@ +#ifndef PACKETMODEL_H +#define PACKETMODEL_H + +#include +#include +#include + +#include "packetelement.h" + +class PacketModel +{ +public: + PacketModel(); + const std::shared_ptr getList(); + +private: + std::shared_ptr elementList; +}; + +#endif // PACKETMODEL_H