Adjust size of each section in the address maps of Section Widget (#1086)

This commit is contained in:
Vanellope 2019-01-07 19:43:44 +09:00 committed by Itay Cohen
parent d919a2163b
commit 975fd77116
2 changed files with 52 additions and 13 deletions

View File

@ -320,6 +320,7 @@ AbstractAddrDock::AbstractAddrDock(SectionsModel *model, QWidget *parent) :
indicatorHeight = 5; indicatorHeight = 5;
indicatorParamPosY = 20; indicatorParamPosY = 20;
heightThreshold = 30; heightThreshold = 30;
heightDivisor = 1000;
rectOffset = 100; rectOffset = 100;
rectWidth = 400; rectWidth = 400;
indicatorColor = ConfigColor("gui.navbar.err"); indicatorColor = ConfigColor("gui.navbar.err");
@ -347,6 +348,20 @@ void AbstractAddrDock::addTextItem(QColor color, QPoint pos, QString string)
addrDockScene->addItem(text); 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) void AbstractAddrDock::drawIndicator(QString name, float ratio)
{ {
RVA offset = Core()->getOffset(); RVA offset = Core()->getOffset();
@ -429,6 +444,7 @@ void RawAddrDock::updateDock()
AbstractAddrDock::updateDock(); AbstractAddrDock::updateDock();
setFeatures(QDockWidget::DockWidgetClosable); setFeatures(QDockWidget::DockWidgetClosable);
int y = 0; int y = 0;
int validMinSize = getValidMinSize();
proxyModel->sort(2, Qt::AscendingOrder); proxyModel->sort(2, Qt::AscendingOrder);
for (int i = 0; i < proxyModel->rowCount(); i++) { for (int i = 0; i < proxyModel->rowCount(); i++) {
QModelIndex idx = proxyModel->index(i, 0); QModelIndex idx = proxyModel->index(i, 0);
@ -444,12 +460,8 @@ void RawAddrDock::updateDock()
addrDockScene->nameAddrMap[name] = addr; addrDockScene->nameAddrMap[name] = addr;
addrDockScene->nameAddrSizeMap[name] = size; addrDockScene->nameAddrSizeMap[name] = size;
if (size < heightThreshold) { size = getAdjustedSize(size, validMinSize);
size = heightThreshold;
} else {
size /= heightThreshold;
size = std::max(size, heightThreshold);
}
QGraphicsRectItem *rect = new QGraphicsRectItem(rectOffset, y, rectWidth, size); QGraphicsRectItem *rect = new QGraphicsRectItem(rectOffset, y, rectWidth, size);
rect->setBrush(QBrush(idx.data(Qt::DecorationRole).value<QColor>())); rect->setBrush(QBrush(idx.data(Qt::DecorationRole).value<QColor>()));
addrDockScene->addItem(rect); 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<SectionDescription>().size;
if (size > 0) {
return size;
}
}
return 0;
}
VirtualAddrDock::VirtualAddrDock(SectionsModel *model, QWidget *parent) : VirtualAddrDock::VirtualAddrDock(SectionsModel *model, QWidget *parent) :
AbstractAddrDock(model, parent) AbstractAddrDock(model, parent)
{ {
@ -481,6 +506,7 @@ void VirtualAddrDock::updateDock()
AbstractAddrDock::updateDock(); AbstractAddrDock::updateDock();
setFeatures(QDockWidget::NoDockWidgetFeatures); setFeatures(QDockWidget::NoDockWidgetFeatures);
int y = 0; int y = 0;
int validMinSize = getValidMinSize();
proxyModel->sort(2, Qt::AscendingOrder); proxyModel->sort(2, Qt::AscendingOrder);
for (int i = 0; i < proxyModel->rowCount(); i++) { for (int i = 0; i < proxyModel->rowCount(); i++) {
QModelIndex idx = proxyModel->index(i, 0); QModelIndex idx = proxyModel->index(i, 0);
@ -493,12 +519,8 @@ void VirtualAddrDock::updateDock()
addrDockScene->nameAddrMap[name] = addr; addrDockScene->nameAddrMap[name] = addr;
addrDockScene->nameAddrSizeMap[name] = size; addrDockScene->nameAddrSizeMap[name] = size;
if (size < heightThreshold) { size = getAdjustedSize(size, validMinSize);
size = heightThreshold;
} else {
size /= heightThreshold;
size = std::max(size, heightThreshold);
}
QGraphicsRectItem *rect = new QGraphicsRectItem(rectOffset, y, rectWidth, size); QGraphicsRectItem *rect = new QGraphicsRectItem(rectOffset, y, rectWidth, size);
rect->setBrush(QBrush(idx.data(Qt::DecorationRole).value<QColor>())); rect->setBrush(QBrush(idx.data(Qt::DecorationRole).value<QColor>()));
addrDockScene->addItem(rect); addrDockScene->addItem(rect);
@ -513,3 +535,16 @@ void VirtualAddrDock::updateDock()
y += size; 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<SectionDescription>().vsize;
if (size > 0) {
return size;
}
}
return 0;
}

View File

@ -111,7 +111,8 @@ protected:
int indicatorWidth; int indicatorWidth;
int indicatorHeight; int indicatorHeight;
int indicatorParamPosY; int indicatorParamPosY;
int heightThreshold; float heightThreshold;
float heightDivisor;
int rectOffset; int rectOffset;
int rectWidth; int rectWidth;
QColor indicatorColor; QColor indicatorColor;
@ -121,6 +122,7 @@ protected:
SectionsProxyModel *proxyModel; SectionsProxyModel *proxyModel;
void addTextItem(QColor color, QPoint pos, QString string); void addTextItem(QColor color, QPoint pos, QString string);
int getAdjustedSize(int size, int validMinSize);
private: private:
void drawIndicator(QString name, float ratio); void drawIndicator(QString name, float ratio);
@ -160,6 +162,7 @@ public:
~RawAddrDock(); ~RawAddrDock();
void updateDock() override; void updateDock() override;
int getValidMinSize();
}; };
class VirtualAddrDock : public AbstractAddrDock class VirtualAddrDock : public AbstractAddrDock
@ -171,6 +174,7 @@ public:
~VirtualAddrDock(); ~VirtualAddrDock();
void updateDock() override; void updateDock() override;
int getValidMinSize();
}; };
#endif // SECTIONSWIDGET_H #endif // SECTIONSWIDGET_H