diff --git a/Software/PC_Application/Device/device.cpp b/Software/PC_Application/Device/device.cpp index 8460f3f..8771568 100644 --- a/Software/PC_Application/Device/device.cpp +++ b/Software/PC_Application/Device/device.cpp @@ -150,6 +150,7 @@ static constexpr Protocol::DeviceStatusV1 defaultStatusV1 = { Device::Device(QString serial) { info = defaultInfo; + status = {}; m_handle = nullptr; infoValid = false; diff --git a/Software/PC_Application/appwindow.cpp b/Software/PC_Application/appwindow.cpp index ad6adf5..ca3cf41 100644 --- a/Software/PC_Application/appwindow.cpp +++ b/Software/PC_Application/appwindow.cpp @@ -281,13 +281,13 @@ void AppWindow::closeEvent(QCloseEvent *event) for(auto m : Mode::getModes()) { m->shutdown(); } - delete device; QSettings settings; settings.setValue("geometry", saveGeometry()); // deactivate currently used mode (stores mode state in settings) if(Mode::getActiveMode()) { Mode::getActiveMode()->deactivate(); } + delete device; pref.store(); QMainWindow::closeEvent(event); } diff --git a/Software/PC_Application/scpi.cpp b/Software/PC_Application/scpi.cpp index 5e5e730..1c52f18 100644 --- a/Software/PC_Application/scpi.cpp +++ b/Software/PC_Application/scpi.cpp @@ -96,6 +96,22 @@ void SCPI::input(QString line) } } +SCPINode::~SCPINode() +{ + if(parent) { + parent->remove(this); + } + while(commands.size() > 0) { + delete commands.front(); + commands.erase(commands.begin()); + } + while(subnodes.size() > 0) { + auto node = subnodes.front(); + remove(node); + delete node; + } +} + bool SCPINode::add(SCPINode *node) { if(nameCollision(node->name)) { @@ -103,6 +119,7 @@ bool SCPINode::add(SCPINode *node) return false; } subnodes.push_back(node); + node->parent = this; return true; } @@ -111,6 +128,7 @@ bool SCPINode::remove(SCPINode *node) auto it = std::find(subnodes.begin(), subnodes.end(), node); if(it != subnodes.end()) { subnodes.erase(it); + node->parent = nullptr; return true; } else { return false; diff --git a/Software/PC_Application/scpi.h b/Software/PC_Application/scpi.h index 97ab8b3..8ba7e00 100644 --- a/Software/PC_Application/scpi.h +++ b/Software/PC_Application/scpi.h @@ -16,8 +16,8 @@ public: QString execute(QStringList params); QString query(QStringList params); QString name() {return _name;} - bool queryable() { return fn_query != nullptr;}; - bool executable() { return fn_cmd != nullptr;}; + bool queryable() { return fn_query != nullptr;} + bool executable() { return fn_cmd != nullptr;} private: const QString _name; std::function fn_cmd; @@ -28,7 +28,8 @@ class SCPINode { friend class SCPI; public: SCPINode(QString name) : - name(name){} + name(name), parent(nullptr){} + ~SCPINode(); bool add(SCPINode *node); bool remove(SCPINode *node); @@ -41,6 +42,7 @@ private: const QString name; std::vector subnodes; std::vector commands; + SCPINode *parent; }; class SCPI : public QObject, public SCPINode