From cd89c506cf45b6de221f89388fb146efca96599c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 3 Dec 2022 15:06:09 +0100 Subject: add update function to node component --- confui/ui_node.cpp | 55 +++++++++++++++++++++++++++------------------ confui/ui_node.h | 15 +++++++++++++ confui/ui_node_overview.cpp | 4 ++-- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/confui/ui_node.cpp b/confui/ui_node.cpp index 38c189e..3621083 100644 --- a/confui/ui_node.cpp +++ b/confui/ui_node.cpp @@ -1,38 +1,49 @@ -#include -#include -#include -#include -#include -#include - #include "ui_node.h" CDNodeWidget::~CDNodeWidget() { } CDNodeWidget::CDNodeWidget(cd_s_node* node, QWidget *parent) : QWidget(parent) { - _node = node; - QHBoxLayout* main_layout = new QHBoxLayout; - QHBoxLayout* float_left = new QHBoxLayout; - QHBoxLayout* float_right = new QHBoxLayout; + set_node(node); + + main_layout = new QHBoxLayout; + float_left = new QHBoxLayout; + float_right = new QHBoxLayout; + switch_on_off = new QCheckBox; + button_add_remove = new QPushButton; + label_node_address = new QLabel; + label_node_name = new QLabel; - QString node_name = QString::fromLocal8Bit(_node->name, _node->name_len); - QString node_address = QString::fromStdString(cd_node_mac_string(_node->address)); - node_address.prepend("("); - node_address.append(")"); - QLabel* label_node_name = new QLabel(node_name, this); - QLabel* label_node_address = new QLabel(node_address, this); float_left->addWidget(label_node_name); float_left->addWidget(label_node_address); - float_left->addStretch(); - float_right->addStretch(); - QCheckBox* switch_on_off = new QCheckBox("on", this); - switch_on_off->setCheckable(_node->provisioned); - QPushButton* button_add_remove = new QPushButton(_node->provisioned ? "Remove from network" : "Join network", this); + float_right->addStretch(); float_right->addWidget(switch_on_off); float_right->addWidget(button_add_remove); main_layout->addLayout(float_left); main_layout->addLayout(float_right); + + update(); setLayout(main_layout); } + +void CDNodeWidget::set_node(cd_s_node* node) { + _node = node; +} + +void CDNodeWidget::update() { + QString node_name = QString::fromLocal8Bit(_node->name, _node->name_len); + label_node_name->setText(node_name); + + QString node_address = QString::fromStdString(cd_node_mac_string(_node->address)); + node_address.prepend("("); + node_address.append(")"); + label_node_address->setText(node_address); + + switch_on_off->setText("on"); + switch_on_off->setVisible(_node->provisioned); + switch_on_off->setCheckable(_node->provisioned); + switch_on_off->setChecked(_node->light_on); + + button_add_remove->setText(_node->provisioned ? "Remove from network" : "Join network"); +} diff --git a/confui/ui_node.h b/confui/ui_node.h index c37f373..f5fdbbd 100644 --- a/confui/ui_node.h +++ b/confui/ui_node.h @@ -1,6 +1,11 @@ #pragma once #include +#include +#include +#include +#include +#include #include "mesh_connector.h" @@ -10,7 +15,17 @@ class CDNodeWidget : public QWidget { private: cd_s_node* _node; + QHBoxLayout* main_layout; + QHBoxLayout* float_left; + QHBoxLayout* float_right; + QLabel* label_node_name; + QLabel* label_node_address; + QCheckBox* switch_on_off; + QPushButton* button_add_remove; + public: CDNodeWidget(cd_s_node* node, QWidget *parent = nullptr); virtual ~CDNodeWidget(); + virtual void update(); + virtual void set_node(cd_s_node* node); }; diff --git a/confui/ui_node_overview.cpp b/confui/ui_node_overview.cpp index 3e63ddd..466e5b2 100644 --- a/confui/ui_node_overview.cpp +++ b/confui/ui_node_overview.cpp @@ -16,8 +16,8 @@ CDNodeOverviewWidget::CDNodeOverviewWidget(CDMainWindow* main_window) : QWidget( .address = { 0x00, 0xff, 0x21, 0x69, 0xf2, 0x31 }, .name_len = strlen(n_name), .name = n_name, - .light_on = false, - .provisioned = false, + .light_on = true, + .provisioned = true, }; CDNodeWidget* nd_w = new CDNodeWidget(&n, this); -- cgit v1.2.3