From 7fa68288536b1086bef2948b3bebd394ed739c83 Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Mon, 13 May 2024 22:47:33 +0200 Subject: [PATCH] add `[Expand]` / `[Collapse]` text for expandable structs and expand/collapse on click --- src/QtHelpers/TreeViewMemoryFields.cpp | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/QtHelpers/TreeViewMemoryFields.cpp b/src/QtHelpers/TreeViewMemoryFields.cpp index 6e01fda..dfb6645 100644 --- a/src/QtHelpers/TreeViewMemoryFields.cpp +++ b/src/QtHelpers/TreeViewMemoryFields.cpp @@ -1861,21 +1861,28 @@ void S2Plugin::TreeViewMemoryFields::updateRow(int row, std::optional } case MemoryFieldType::EntitySubclass: { - // can't be a pointer, nothing to do here + // can't be a pointer + if (isExpanded(itemField->index())) + itemValue->setData("[Collapse]", Qt::DisplayRole); + else + itemValue->setData("[Expand]", Qt::DisplayRole); + if (shouldUpdateChildren) { for (int x = 0; x < itemField->rowCount(); ++x) - { updateRow(x, newAddr, newAddrComparison, itemField); - } } break; } case MemoryFieldType::DefaultStructType: { + if (isExpanded(itemField->index())) + itemValue->setData("[Collapse]", Qt::DisplayRole); + else + itemValue->setData("[Expand]", Qt::DisplayRole); + if (isPointer) { - itemValue->setData(itemValueHex->data(Qt::DisplayRole), Qt::DisplayRole); if (comparisonActive) { itemComparisonValue->setData(itemComparisonValueHex->data(Qt::DisplayRole), Qt::DisplayRole); @@ -1893,6 +1900,11 @@ void S2Plugin::TreeViewMemoryFields::updateRow(int row, std::optional } case MemoryFieldType::Dummy: { + if (isExpanded(itemField->index())) + itemValue->setData("[Collapse]", Qt::DisplayRole); + else + itemValue->setData("[Expand]", Qt::DisplayRole); + if (shouldUpdateChildren) { for (int x = 0; x < itemField->rowCount(); ++x) @@ -2214,12 +2226,19 @@ void S2Plugin::TreeViewMemoryFields::cellClicked(const QModelIndex& index) break; } case MemoryFieldType::DefaultStructType: + case MemoryFieldType::EntitySubclass: + case MemoryFieldType::Dummy: { - bool isPointer = getDataFrom(index, gsColField, gsRoleIsPointer).toBool(); - if (isPointer) + auto fieldIndex = index.sibling(index.row(), gsColField); + if (isExpanded(fieldIndex)) + collapse(fieldIndex); + else + expand(index.sibling(index.row(), gsColField)); + + break; } case MemoryFieldType::UTF16Char: - { + { auto offset = clickedItem->data(gsRoleMemoryAddress).toULongLong(); if (offset != 0) { @@ -2249,7 +2268,7 @@ void S2Plugin::TreeViewMemoryFields::cellClicked(const QModelIndex& index) { auto offset = clickedItem->data(gsRoleMemoryAddress).toULongLong(); if (offset != 0) - { + { auto fieldName = getDataFrom(index, gsColField, gsRoleUID).toString(); auto s = QString::fromStdString(ReadConstString(offset)); // [Known Issue]: Now way to safely determinate allowed lenght, so we just allow as much characters as there is already @@ -2257,7 +2276,7 @@ void S2Plugin::TreeViewMemoryFields::cellClicked(const QModelIndex& index) dialog->exec(); } break; - } + } case MemoryFieldType::UTF8StringFixedSize: { auto offset = clickedItem->data(gsRoleMemoryAddress).toULongLong();