Excluded empty peripherals from Insight registers pane

This commit is contained in:
Nav
2025-02-22 21:56:05 +00:00
parent 577142feb1
commit 7bbd856c35
5 changed files with 62 additions and 9 deletions

View File

@@ -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;

View File

@@ -28,6 +28,8 @@ namespace Widgets
Targets::TargetRegisterDescriptors& flattenedRegisterDescriptors
);
[[nodiscard]] bool isEmpty() const;
bool isExpanded() const {
return this->expanded;
}

View File

@@ -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<const RegisterGroupItem*>(childItem);
if (subgroupItem != nullptr) {
if (!subgroupItem->isEmpty()) {
return false;
}
continue;
}
const auto* registerItem = dynamic_cast<const RegisterItem*>(childItem);
if (registerItem != nullptr) {
return false;
}
}
return true;
}
void RegisterGroupItem::setExpanded(bool expanded) {
if (expanded == this->expanded) {
return;

View File

@@ -37,6 +37,8 @@ namespace Widgets
QGraphicsItem* parent
);
[[nodiscard]] bool isEmpty() const;
[[nodiscard]] bool isExpanded() const {
return this->expanded;
}

View File

@@ -88,13 +88,18 @@ namespace Widgets
});
for (const auto& [peripheralKey, peripheralDescriptor] : this->targetDescriptor.peripheralDescriptorsByKey) {
this->peripheralItems.emplace_back(
new PeripheralItem{
auto* peripheralItem = new PeripheralItem{
peripheralDescriptor,
this->flattenedRegisterItemsByRegisterId,
this->flattenedRegisterDescriptors
};
if (peripheralItem->isEmpty()) {
delete peripheralItem;
continue;
}
);
this->peripheralItems.emplace_back(peripheralItem);
}
this->registerListView = new ListView{