diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-09 16:08:31 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-09 16:08:31 +0100 |
commit | 2eadbbd85105ad1199c43c72f551ddd69538e994 (patch) | |
tree | 333527c3edc00c1c4739e21d17030eaaa35b3fc8 | |
parent | 1d1799da8880b19aac0dbd2975facf97138bab61 (diff) |
handle deleted nodes/automations properly
-rw-r--r-- | confui/mesh_connector.cpp | 4 | ||||
-rw-r--r-- | confui/ui_automation.cpp | 6 | ||||
-rw-r--r-- | confui/ui_automation.h | 2 | ||||
-rw-r--r-- | confui/ui_tab_automations.cpp | 14 | ||||
-rw-r--r-- | confui/ui_tab_node_overview.cpp | 14 |
5 files changed, 28 insertions, 12 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp index d32855a..56069bd 100644 --- a/confui/mesh_connector.cpp +++ b/confui/mesh_connector.cpp @@ -119,7 +119,7 @@ void CDMeshConnector::remove_link(cd_link_t link_handle) { printf("remove link[%d]\n", link_handle); if (_links[link_handle] != nullptr) free(_links[link_handle]); - _links.erase(link_handle); + _links[link_handle] = nullptr; return; } @@ -127,7 +127,7 @@ void CDMeshConnector::remove_node(cd_uid_t node_handle) { printf("remove node[%d]\n", node_handle); if (_nodes[node_handle] != nullptr) free(_nodes[node_handle]); - _nodes.erase(node_handle); + _nodes[node_handle] = nullptr; return; } diff --git a/confui/ui_automation.cpp b/confui/ui_automation.cpp index 72e2446..1c5c1f0 100644 --- a/confui/ui_automation.cpp +++ b/confui/ui_automation.cpp @@ -18,6 +18,8 @@ CDAutomationWidget::CDAutomationWidget(QWidget* parent) : QWidget(parent) { main_layout->addStretch(); main_layout->addWidget(button_remove); + connect(button_remove, &QPushButton::clicked, this, &CDAutomationWidget::remove); + update(); setLayout(main_layout); } @@ -68,3 +70,7 @@ void CDAutomationWidget::apply() { g_cd_mesh_connector->update_link(_id, _automation); } + +void CDAutomationWidget::remove() { + g_cd_mesh_connector->remove_link(_id); +} diff --git a/confui/ui_automation.h b/confui/ui_automation.h index 2c081e3..7ea4cbb 100644 --- a/confui/ui_automation.h +++ b/confui/ui_automation.h @@ -32,4 +32,6 @@ public: virtual bool conf_valid(); /** @brief apply new automation rule */ virtual void apply(); + /** @brief remove automation */ + virtual void remove(); }; diff --git a/confui/ui_tab_automations.cpp b/confui/ui_tab_automations.cpp index af02ab9..dae00ba 100644 --- a/confui/ui_tab_automations.cpp +++ b/confui/ui_tab_automations.cpp @@ -45,14 +45,18 @@ void CDAutomationsTabWidget::update() { map<cd_link_t, cd_s_automation*> links = this->mainwindow->mesh_connector->get_links(); for (pair<cd_link_t, cd_s_automation*> link : links) { - if (automation_widgets.count(link.first)) { // node is already in list - automation_widgets[link.first]->update(); - } else { - automation_widgets[link.first] = new CDAutomationWidget(this); + if (automation_widgets.count(link.first) == 0) { + automation_widgets[link.first] = new CDAutomationWidget(this); // create new automation automation_widgets[link.first]->set_automation(link.first, link.second); automation_widgets[link.first]->update(); + automations->addWidget(automation_widgets[link.first]); + } else if (link.second != nullptr) { + automation_widgets[link.first]->update(); // update existing widget + } else if (automation_widgets[link.first] != nullptr) { + automations->removeWidget(automation_widgets[link.first]); // remove removed automation + delete automation_widgets[link.first]; // free automation widget + automation_widgets[link.first] = nullptr; } - automations->addWidget(automation_widgets[link.first]); } } diff --git a/confui/ui_tab_node_overview.cpp b/confui/ui_tab_node_overview.cpp index 84f1d6e..752bade 100644 --- a/confui/ui_tab_node_overview.cpp +++ b/confui/ui_tab_node_overview.cpp @@ -20,13 +20,17 @@ void CDNodeOverviewTabWidget::update() { map<cd_uid_t, cd_s_node*> nodes = g_cd_mesh_connector->get_nodes(false); for (pair<cd_uid_t, cd_s_node*> node : nodes) { - if (node_widgets.count(node.first)) { // node is already in list - node_widgets[node.first]->update(); - } else { - node_widgets[node.first] = new CDNodeWidget(this); + if (node_widgets.count(node.first) == 0) { + node_widgets[node.first] = new CDNodeWidget(this); // create new node widget node_widgets[node.first]->set_node(node.second); node_widgets[node.first]->update(); + main_layout->addWidget(node_widgets[node.first]); + } else if (node.second != nullptr) { + node_widgets[node.first]->update(); // update existing widget + } else if (node_widgets[node.first] != nullptr) { + main_layout->removeWidget(node_widgets[node.first]); // remove removed automation + delete node_widgets[node.first]; // free automation widget + node_widgets[node.first] = nullptr; } - main_layout->addWidget(node_widgets[node.first]); } } |