Improved the performance of resizing the hex viewer widget, by only recalculating the byte item positions when absolutely necessary.

This commit is contained in:
Nav
2021-10-30 14:47:58 +01:00
parent cc83f39524
commit 66879df349

View File

@@ -66,9 +66,6 @@ void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buff
}
void ByteItemGraphicsScene::adjustByteWidgets() {
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByColumnIndex;
const auto margins = QMargins(10, 10, 10, 10);
const auto width = std::max(600, static_cast<int>(this->parent->width()));
@@ -81,6 +78,21 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
std::ceil(static_cast<double>(this->byteWidgetsByAddress.size()) / static_cast<double>(rowCapacity))
);
this->setSceneRect(
0,
0,
width,
(rowCount * byteWidgetHeight) + margins.top() + margins.bottom()
);
// Don't bother recalculating the byte item positions if the number of rows have not changed.
if (rowCount == this->byteWidgetsByRowIndex.size()) {
return;
}
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByRowIndex;
std::map<std::size_t, std::vector<ByteItem*>> byteWidgetsByColumnIndex;
for (auto& [address, byteWidget] : this->byteWidgetsByAddress) {
const auto rowIndex = static_cast<std::size_t>(
std::ceil(static_cast<double>(byteWidget->byteIndex + 1) / static_cast<double>(rowCapacity)) - 1
@@ -104,11 +116,6 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
byteWidget->update();
}
const auto minHeight = (rowCount * byteWidgetHeight) + margins.top() + margins.bottom();
// this->setMinimumHeight(minHeight);
this->setSceneRect(0, 0, width, minHeight);
// this->parent->setMinimumHeight(minHeight);
this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex);
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);