From 975fd7711607381a8fe401dc011526a33d635e2c Mon Sep 17 00:00:00 2001 From: Vanellope Date: Mon, 7 Jan 2019 19:43:44 +0900 Subject: [PATCH] Adjust size of each section in the address maps of Section Widget (#1086) --- src/widgets/SectionsWidget.cpp | 59 +++++++++++++++++++++++++++------- src/widgets/SectionsWidget.h | 6 +++- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/widgets/SectionsWidget.cpp b/src/widgets/SectionsWidget.cpp index 41954c42..5461324d 100644 --- a/src/widgets/SectionsWidget.cpp +++ b/src/widgets/SectionsWidget.cpp @@ -320,6 +320,7 @@ AbstractAddrDock::AbstractAddrDock(SectionsModel *model, QWidget *parent) : indicatorHeight = 5; indicatorParamPosY = 20; heightThreshold = 30; + heightDivisor = 1000; rectOffset = 100; rectWidth = 400; indicatorColor = ConfigColor("gui.navbar.err"); @@ -347,6 +348,20 @@ void AbstractAddrDock::addTextItem(QColor color, QPoint pos, QString string) addrDockScene->addItem(text); } +int AbstractAddrDock::getAdjustedSize(int size, int validMinSize) +{ + if (size == 0) { + return size; + } + if (size == validMinSize) { + return heightThreshold; + } + float r = (float)size / (float)validMinSize; + r /= heightDivisor; + r += 1; + return heightThreshold * r; +} + void AbstractAddrDock::drawIndicator(QString name, float ratio) { RVA offset = Core()->getOffset(); @@ -429,6 +444,7 @@ void RawAddrDock::updateDock() AbstractAddrDock::updateDock(); setFeatures(QDockWidget::DockWidgetClosable); int y = 0; + int validMinSize = getValidMinSize(); proxyModel->sort(2, Qt::AscendingOrder); for (int i = 0; i < proxyModel->rowCount(); i++) { QModelIndex idx = proxyModel->index(i, 0); @@ -444,12 +460,8 @@ void RawAddrDock::updateDock() addrDockScene->nameAddrMap[name] = addr; addrDockScene->nameAddrSizeMap[name] = size; - if (size < heightThreshold) { - size = heightThreshold; - } else { - size /= heightThreshold; - size = std::max(size, heightThreshold); - } + size = getAdjustedSize(size, validMinSize); + QGraphicsRectItem *rect = new QGraphicsRectItem(rectOffset, y, rectWidth, size); rect->setBrush(QBrush(idx.data(Qt::DecorationRole).value())); addrDockScene->addItem(rect); @@ -465,6 +477,19 @@ void RawAddrDock::updateDock() } } +int RawAddrDock::getValidMinSize() +{ + proxyModel->sort(1, Qt::AscendingOrder); + for (int i = 0; i < proxyModel->rowCount(); i++) { + QModelIndex idx = proxyModel->index(i, 0); + int size = idx.data(SectionsModel::SectionDescriptionRole).value().size; + if (size > 0) { + return size; + } + } + return 0; +} + VirtualAddrDock::VirtualAddrDock(SectionsModel *model, QWidget *parent) : AbstractAddrDock(model, parent) { @@ -481,6 +506,7 @@ void VirtualAddrDock::updateDock() AbstractAddrDock::updateDock(); setFeatures(QDockWidget::NoDockWidgetFeatures); int y = 0; + int validMinSize = getValidMinSize(); proxyModel->sort(2, Qt::AscendingOrder); for (int i = 0; i < proxyModel->rowCount(); i++) { QModelIndex idx = proxyModel->index(i, 0); @@ -493,12 +519,8 @@ void VirtualAddrDock::updateDock() addrDockScene->nameAddrMap[name] = addr; addrDockScene->nameAddrSizeMap[name] = size; - if (size < heightThreshold) { - size = heightThreshold; - } else { - size /= heightThreshold; - size = std::max(size, heightThreshold); - } + size = getAdjustedSize(size, validMinSize); + QGraphicsRectItem *rect = new QGraphicsRectItem(rectOffset, y, rectWidth, size); rect->setBrush(QBrush(idx.data(Qt::DecorationRole).value())); addrDockScene->addItem(rect); @@ -513,3 +535,16 @@ void VirtualAddrDock::updateDock() y += size; } } + +int VirtualAddrDock::getValidMinSize() +{ + proxyModel->sort(1, Qt::AscendingOrder); + for (int i = 0; i < proxyModel->rowCount(); i++) { + QModelIndex idx = proxyModel->index(i, 0); + int size = idx.data(SectionsModel::SectionDescriptionRole).value().vsize; + if (size > 0) { + return size; + } + } + return 0; +} diff --git a/src/widgets/SectionsWidget.h b/src/widgets/SectionsWidget.h index d3abfd45..5049cbd6 100644 --- a/src/widgets/SectionsWidget.h +++ b/src/widgets/SectionsWidget.h @@ -111,7 +111,8 @@ protected: int indicatorWidth; int indicatorHeight; int indicatorParamPosY; - int heightThreshold; + float heightThreshold; + float heightDivisor; int rectOffset; int rectWidth; QColor indicatorColor; @@ -121,6 +122,7 @@ protected: SectionsProxyModel *proxyModel; void addTextItem(QColor color, QPoint pos, QString string); + int getAdjustedSize(int size, int validMinSize); private: void drawIndicator(QString name, float ratio); @@ -160,6 +162,7 @@ public: ~RawAddrDock(); void updateDock() override; + int getValidMinSize(); }; class VirtualAddrDock : public AbstractAddrDock @@ -171,6 +174,7 @@ public: ~VirtualAddrDock(); void updateDock() override; + int getValidMinSize(); }; #endif // SECTIONSWIDGET_H