Improved the performance of resizing the hex viewer widget, by only recalculating the byte item positions when absolutely necessary.
This commit is contained in:
@@ -66,9 +66,6 @@ void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buff
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ByteItemGraphicsScene::adjustByteWidgets() {
|
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 margins = QMargins(10, 10, 10, 10);
|
||||||
const auto width = std::max(600, static_cast<int>(this->parent->width()));
|
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))
|
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) {
|
for (auto& [address, byteWidget] : this->byteWidgetsByAddress) {
|
||||||
const auto rowIndex = static_cast<std::size_t>(
|
const auto rowIndex = static_cast<std::size_t>(
|
||||||
std::ceil(static_cast<double>(byteWidget->byteIndex + 1) / static_cast<double>(rowCapacity)) - 1
|
std::ceil(static_cast<double>(byteWidget->byteIndex + 1) / static_cast<double>(rowCapacity)) - 1
|
||||||
@@ -104,11 +116,6 @@ void ByteItemGraphicsScene::adjustByteWidgets() {
|
|||||||
byteWidget->update();
|
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->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex);
|
||||||
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user