mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-22 06:33:46 +00:00
Auto Resize Visualization in SectionsWidget
This commit is contained in:
parent
a3a8daae55
commit
8f49722bf9
@ -145,9 +145,8 @@ SectionsWidget::SectionsWidget(MainWindow *main, QAction *action) :
|
|||||||
setWindowTitle(QStringLiteral("Sections"));
|
setWindowTitle(QStringLiteral("Sections"));
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
refreshDeferrer = createRefreshDeferrer([this]() {
|
sectionsRefreshDeferrer = createRefreshDeferrer([this]() { refreshSections(); });
|
||||||
drawIndicatorOnAddrDocks();
|
dockRefreshDeferrer = createRefreshDeferrer([this]() { refreshDocks(); });
|
||||||
});
|
|
||||||
|
|
||||||
initSectionsTable();
|
initSectionsTable();
|
||||||
initQuickFilter();
|
initQuickFilter();
|
||||||
@ -240,8 +239,8 @@ void SectionsWidget::initConnects()
|
|||||||
refreshSections();
|
refreshSections();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(onSectionsSeekChanged(RVA)));
|
connect(Core(), &CutterCore::seekChanged, this, &SectionsWidget::refreshDocks);
|
||||||
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(refreshSections()));
|
connect(Config(), &Configuration::colorsUpdated, this, &SectionsWidget::refreshSections);
|
||||||
connect(toggleButton, &QToolButton::clicked, this, [ = ] {
|
connect(toggleButton, &QToolButton::clicked, this, [ = ] {
|
||||||
toggleButton->hide();
|
toggleButton->hide();
|
||||||
addrDockWidget->show();
|
addrDockWidget->show();
|
||||||
@ -256,28 +255,21 @@ void SectionsWidget::initConnects()
|
|||||||
|
|
||||||
void SectionsWidget::refreshSections()
|
void SectionsWidget::refreshSections()
|
||||||
{
|
{
|
||||||
|
if (!sectionsRefreshDeferrer->attemptRefresh(nullptr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
sectionsModel->beginResetModel();
|
sectionsModel->beginResetModel();
|
||||||
sections = Core()->getAllSections();
|
sections = Core()->getAllSections();
|
||||||
sectionsModel->endResetModel();
|
sectionsModel->endResetModel();
|
||||||
qhelpers::adjustColumns(sectionsTable, SectionsModel::ColumnCount, 0);
|
qhelpers::adjustColumns(sectionsTable, SectionsModel::ColumnCount, 0);
|
||||||
rawAddrDock->updateDock();
|
refreshDocks();
|
||||||
virtualAddrDock->updateDock();
|
|
||||||
drawIndicatorOnAddrDocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SectionsWidget::onSectionsDoubleClicked(const QModelIndex &index)
|
void SectionsWidget::refreshDocks()
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
if (!dockRefreshDeferrer->attemptRefresh(nullptr)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto section = index.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>();
|
|
||||||
Core()->seek(section.vaddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SectionsWidget::onSectionsSeekChanged(RVA addr)
|
|
||||||
{
|
|
||||||
Q_UNUSED(addr);
|
|
||||||
rawAddrDock->updateDock();
|
rawAddrDock->updateDock();
|
||||||
virtualAddrDock->updateDock();
|
virtualAddrDock->updateDock();
|
||||||
drawIndicatorOnAddrDocks();
|
drawIndicatorOnAddrDocks();
|
||||||
@ -285,10 +277,6 @@ void SectionsWidget::onSectionsSeekChanged(RVA addr)
|
|||||||
|
|
||||||
void SectionsWidget::drawIndicatorOnAddrDocks()
|
void SectionsWidget::drawIndicatorOnAddrDocks()
|
||||||
{
|
{
|
||||||
if (!refreshDeferrer->attemptRefresh(nullptr)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RVA offset = Core()->getOffset();
|
RVA offset = Core()->getOffset();
|
||||||
for (int i = 0; i != virtualAddrDock->proxyModel->rowCount(); i++) {
|
for (int i = 0; i != virtualAddrDock->proxyModel->rowCount(); i++) {
|
||||||
QModelIndex idx = virtualAddrDock->proxyModel->index(i, 0);
|
QModelIndex idx = virtualAddrDock->proxyModel->index(i, 0);
|
||||||
@ -308,6 +296,21 @@ void SectionsWidget::drawIndicatorOnAddrDocks()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SectionsWidget::onSectionsDoubleClicked(const QModelIndex &index)
|
||||||
|
{
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto section = index.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>();
|
||||||
|
Core()->seek(section.vaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SectionsWidget::resizeEvent(QResizeEvent *event) {
|
||||||
|
CutterDockWidget::resizeEvent(event);
|
||||||
|
refreshDocks();
|
||||||
|
}
|
||||||
|
|
||||||
void SectionsWidget::updateToggle()
|
void SectionsWidget::updateToggle()
|
||||||
{
|
{
|
||||||
if (!virtualAddrDock->isVisible()) {
|
if (!virtualAddrDock->isVisible()) {
|
||||||
@ -328,13 +331,13 @@ AbstractAddrDock::AbstractAddrDock(SectionsModel *model, QWidget *parent) :
|
|||||||
|
|
||||||
setWidget(graphicsView);
|
setWidget(graphicsView);
|
||||||
|
|
||||||
indicatorWidth = 600;
|
|
||||||
indicatorHeight = 5;
|
indicatorHeight = 5;
|
||||||
indicatorParamPosY = 20;
|
indicatorParamPosY = 20;
|
||||||
heightThreshold = 30;
|
heightThreshold = 30;
|
||||||
heightDivisor = 1000;
|
heightDivisor = 1000;
|
||||||
rectOffset = 100;
|
rectOffset = 100;
|
||||||
rectWidth = 400;
|
rectWidthMin = 80;
|
||||||
|
rectWidthMax = 400;
|
||||||
indicatorColor = ConfigColor("gui.navbar.seek");
|
indicatorColor = ConfigColor("gui.navbar.seek");
|
||||||
textColor = ConfigColor("gui.dataoffset");
|
textColor = ConfigColor("gui.dataoffset");
|
||||||
}
|
}
|
||||||
@ -374,13 +377,24 @@ int AbstractAddrDock::getAdjustedSize(int size, int validMinSize)
|
|||||||
return heightThreshold * r;
|
return heightThreshold * r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AbstractAddrDock::getRectWidth()
|
||||||
|
{
|
||||||
|
return qBound(rectWidthMin, width() - 300, rectWidthMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
int AbstractAddrDock::getIndicatorWidth()
|
||||||
|
{
|
||||||
|
return getRectWidth() + 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractAddrDock::drawIndicator(QString name, float ratio)
|
void AbstractAddrDock::drawIndicator(QString name, float ratio)
|
||||||
{
|
{
|
||||||
RVA offset = Core()->getOffset();
|
RVA offset = Core()->getOffset();
|
||||||
float padding = addrDockScene->nameHeightMap[name] * ratio;
|
float padding = addrDockScene->nameHeightMap[name] * ratio;
|
||||||
int y = addrDockScene->namePosYMap[name] + (int)padding;
|
int y = addrDockScene->namePosYMap[name] + (int)padding;
|
||||||
QColor color = indicatorColor;
|
QColor color = indicatorColor;
|
||||||
QGraphicsRectItem *indicator = new QGraphicsRectItem(QRectF(0, y, indicatorWidth, indicatorHeight));
|
QGraphicsRectItem *indicator = new QGraphicsRectItem(QRectF(0, y, getIndicatorWidth(), indicatorHeight));
|
||||||
indicator->setBrush(QBrush(color));
|
indicator->setBrush(QBrush(color));
|
||||||
addrDockScene->addItem(indicator);
|
addrDockScene->addItem(indicator);
|
||||||
|
|
||||||
@ -388,7 +402,7 @@ void AbstractAddrDock::drawIndicator(QString name, float ratio)
|
|||||||
graphicsView->centerOn(indicator);
|
graphicsView->centerOn(indicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
addTextItem(color, QPoint(rectOffset + rectWidth, y - indicatorParamPosY), name);
|
addTextItem(color, QPoint(rectOffset + getRectWidth(), y - indicatorParamPosY), name);
|
||||||
addTextItem(color, QPoint(0, y - indicatorParamPosY), QString("0x%1").arg(offset, 0, 16));
|
addTextItem(color, QPoint(0, y - indicatorParamPosY), QString("0x%1").arg(offset, 0, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +472,8 @@ void RawAddrDock::updateDock()
|
|||||||
setFeatures(QDockWidget::DockWidgetClosable);
|
setFeatures(QDockWidget::DockWidgetClosable);
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int validMinSize = getValidMinSize();
|
int validMinSize = getValidMinSize();
|
||||||
proxyModel->sort(2, Qt::AscendingOrder);
|
int rectWidth = getRectWidth();
|
||||||
|
proxyModel->sort(SectionsModel::AddressColumn, 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);
|
||||||
auto desc = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>();
|
auto desc = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>();
|
||||||
@ -490,11 +505,13 @@ void RawAddrDock::updateDock()
|
|||||||
|
|
||||||
y += size;
|
y += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphicsView->setSceneRect(addrDockScene->itemsBoundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
int RawAddrDock::getValidMinSize()
|
int RawAddrDock::getValidMinSize()
|
||||||
{
|
{
|
||||||
proxyModel->sort(1, Qt::AscendingOrder);
|
proxyModel->sort(SectionsModel::SizeColumn, 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);
|
||||||
int size = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().size;
|
int size = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().size;
|
||||||
@ -522,7 +539,8 @@ void VirtualAddrDock::updateDock()
|
|||||||
setFeatures(QDockWidget::NoDockWidgetFeatures);
|
setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int validMinSize = getValidMinSize();
|
int validMinSize = getValidMinSize();
|
||||||
proxyModel->sort(2, Qt::AscendingOrder);
|
int rectWidth = getRectWidth();
|
||||||
|
proxyModel->sort(SectionsModel::AddressColumn, 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);
|
||||||
RVA addr = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().vaddr;
|
RVA addr = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().vaddr;
|
||||||
@ -549,11 +567,13 @@ void VirtualAddrDock::updateDock()
|
|||||||
|
|
||||||
y += size;
|
y += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphicsView->setSceneRect(addrDockScene->itemsBoundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
int VirtualAddrDock::getValidMinSize()
|
int VirtualAddrDock::getValidMinSize()
|
||||||
{
|
{
|
||||||
proxyModel->sort(1, Qt::AscendingOrder);
|
proxyModel->sort(SectionsModel::SizeColumn, 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);
|
||||||
int size = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().vsize;
|
int size = idx.data(SectionsModel::SectionDescriptionRole).value<SectionDescription>().vsize;
|
||||||
|
@ -70,8 +70,12 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refreshSections();
|
void refreshSections();
|
||||||
|
void refreshDocks();
|
||||||
|
|
||||||
void onSectionsDoubleClicked(const QModelIndex &index);
|
void onSectionsDoubleClicked(const QModelIndex &index);
|
||||||
void onSectionsSeekChanged(RVA addr);
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<SectionDescription> sections;
|
QList<SectionDescription> sections;
|
||||||
@ -82,13 +86,21 @@ private:
|
|||||||
QWidget *dockWidgetContents;
|
QWidget *dockWidgetContents;
|
||||||
QuickFilterView *quickFilterView;
|
QuickFilterView *quickFilterView;
|
||||||
|
|
||||||
RefreshDeferrer *refreshDeferrer;
|
|
||||||
|
|
||||||
QWidget *addrDockWidget;
|
QWidget *addrDockWidget;
|
||||||
RawAddrDock *rawAddrDock;
|
RawAddrDock *rawAddrDock;
|
||||||
VirtualAddrDock *virtualAddrDock;
|
VirtualAddrDock *virtualAddrDock;
|
||||||
QToolButton *toggleButton;
|
QToolButton *toggleButton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RefreshDeferrer for loading the section data
|
||||||
|
*/
|
||||||
|
RefreshDeferrer *sectionsRefreshDeferrer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RefreshDeferrer for updating the visualization docks
|
||||||
|
*/
|
||||||
|
RefreshDeferrer *dockRefreshDeferrer;
|
||||||
|
|
||||||
void initSectionsTable();
|
void initSectionsTable();
|
||||||
void initQuickFilter();
|
void initQuickFilter();
|
||||||
void initConnects();
|
void initConnects();
|
||||||
@ -110,13 +122,13 @@ public:
|
|||||||
virtual void updateDock();
|
virtual void updateDock();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int indicatorWidth;
|
|
||||||
int indicatorHeight;
|
int indicatorHeight;
|
||||||
int indicatorParamPosY;
|
int indicatorParamPosY;
|
||||||
float heightThreshold;
|
float heightThreshold;
|
||||||
float heightDivisor;
|
float heightDivisor;
|
||||||
int rectOffset;
|
int rectOffset;
|
||||||
int rectWidth;
|
int rectWidthMin;
|
||||||
|
int rectWidthMax;
|
||||||
QColor indicatorColor;
|
QColor indicatorColor;
|
||||||
QColor textColor;
|
QColor textColor;
|
||||||
AddrDockScene *addrDockScene;
|
AddrDockScene *addrDockScene;
|
||||||
@ -125,6 +137,8 @@ protected:
|
|||||||
|
|
||||||
void addTextItem(QColor color, QPoint pos, QString string);
|
void addTextItem(QColor color, QPoint pos, QString string);
|
||||||
int getAdjustedSize(int size, int validMinSize);
|
int getAdjustedSize(int size, int validMinSize);
|
||||||
|
int getRectWidth();
|
||||||
|
int getIndicatorWidth();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawIndicator(QString name, float ratio);
|
void drawIndicator(QString name, float ratio);
|
||||||
|
Loading…
Reference in New Issue
Block a user