From 7bbd856c35e01d31d090cd1dc53ae076dedf4971 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 22 Feb 2025 21:56:05 +0000 Subject: [PATCH] Excluded empty peripherals from Insight registers pane --- .../TargetRegistersPane/PeripheralItem.cpp | 17 +++++++++- .../TargetRegistersPane/PeripheralItem.hpp | 2 ++ .../TargetRegistersPane/RegisterGroupItem.cpp | 31 ++++++++++++++++++- .../TargetRegistersPane/RegisterGroupItem.hpp | 2 ++ .../TargetRegistersPaneWidget.cpp | 19 +++++++----- 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp index e0db9db5..7a84f147 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp @@ -31,8 +31,13 @@ namespace Widgets flattenedRegisterDescriptors, this }; - registerGroupItem->setVisible(this->expanded); + if (registerGroupItem->isEmpty()) { + delete registerGroupItem; + continue; + } + + registerGroupItem->setVisible(this->expanded); this->registerGroupItems.push_back(registerGroupItem); } @@ -49,6 +54,16 @@ namespace Widgets } } + bool PeripheralItem::isEmpty() const { + for (const auto* groupItem : this->registerGroupItems) { + if (!groupItem->isEmpty()) { + return false; + } + } + + return true; + } + void PeripheralItem::setExpanded(bool expanded) { if (expanded == this->expanded) { return; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp index 7382c5d4..2666ecd6 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp @@ -28,6 +28,8 @@ namespace Widgets Targets::TargetRegisterDescriptors& flattenedRegisterDescriptors ); + [[nodiscard]] bool isEmpty() const; + bool isExpanded() const { return this->expanded; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp index d8f6bbfe..0ece8cea 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp @@ -38,12 +38,21 @@ namespace Widgets flattenedRegisterDescriptors, this }; - subgroupItem->setVisible(this->expanded); + if (subgroupItem->isEmpty()) { + delete subgroupItem; + continue; + } + + subgroupItem->setVisible(this->expanded); this->childItems.emplace_back(subgroupItem); } for (const auto& [registerKey, registerDescriptor] : this->registerGroupDescriptor.registerDescriptorsByKey) { + if (!registerDescriptor.access.readable) { + continue; + } + auto* registerItem = new RegisterItem{registerDescriptor, this->nestedLevel + 1, this}; registerItem->setVisible(this->expanded); @@ -75,6 +84,26 @@ namespace Widgets } } + bool RegisterGroupItem::isEmpty() const { + for (const auto* childItem : this->childItems) { + const auto* subgroupItem = dynamic_cast(childItem); + if (subgroupItem != nullptr) { + if (!subgroupItem->isEmpty()) { + return false; + } + + continue; + } + + const auto* registerItem = dynamic_cast(childItem); + if (registerItem != nullptr) { + return false; + } + } + + return true; + } + void RegisterGroupItem::setExpanded(bool expanded) { if (expanded == this->expanded) { return; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp index 0b2755ba..0ab3e2ca 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp @@ -37,6 +37,8 @@ namespace Widgets QGraphicsItem* parent ); + [[nodiscard]] bool isEmpty() const; + [[nodiscard]] bool isExpanded() const { return this->expanded; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index 8af1618a..133e493a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -88,13 +88,18 @@ namespace Widgets }); for (const auto& [peripheralKey, peripheralDescriptor] : this->targetDescriptor.peripheralDescriptorsByKey) { - this->peripheralItems.emplace_back( - new PeripheralItem{ - peripheralDescriptor, - this->flattenedRegisterItemsByRegisterId, - this->flattenedRegisterDescriptors - } - ); + auto* peripheralItem = new PeripheralItem{ + peripheralDescriptor, + this->flattenedRegisterItemsByRegisterId, + this->flattenedRegisterDescriptors + }; + + if (peripheralItem->isEmpty()) { + delete peripheralItem; + continue; + } + + this->peripheralItems.emplace_back(peripheralItem); } this->registerListView = new ListView{