mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 12:26:11 +00:00
CodeGraphic: Small memory and performance improvements (#190)
This commit is contained in:
parent
79b4aefd4e
commit
8e0deeb115
@ -43,6 +43,8 @@ GraphicsBar::GraphicsBar(MainWindow *main, QWidget *parent) :
|
|||||||
|
|
||||||
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
||||||
connect(Core(), SIGNAL(refreshAll()), this, SLOT(fetchAndPaintData()));
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(fetchAndPaintData()));
|
||||||
|
|
||||||
|
graphicsScene = new QGraphicsScene(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsBar::paintEvent(QPaintEvent *event)
|
void GraphicsBar::paintEvent(QPaintEvent *event)
|
||||||
@ -50,7 +52,11 @@ void GraphicsBar::paintEvent(QPaintEvent *event)
|
|||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
this->fillData();
|
if(previousWidth != this->codeGraphic->width())
|
||||||
|
{
|
||||||
|
this->fillData();
|
||||||
|
previousWidth = this->codeGraphic->width();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsBar::fetchAndPaintData()
|
void GraphicsBar::fetchAndPaintData()
|
||||||
@ -80,19 +86,20 @@ void GraphicsBar::fetchData()
|
|||||||
|
|
||||||
void GraphicsBar::fillData()
|
void GraphicsBar::fillData()
|
||||||
{
|
{
|
||||||
|
qDeleteAll(graphicsScene->items());
|
||||||
int from = blockMaps.first()["from"].toInt();
|
int from = blockMaps.first()["from"].toInt();
|
||||||
int to = blockMaps.first()["to"].toInt();
|
int to = blockMaps.first()["to"].toInt();
|
||||||
|
|
||||||
// Prepare the graph scene
|
// Prepare the graph scene
|
||||||
int w = this->codeGraphic->width();
|
int w = this->codeGraphic->width();
|
||||||
int h = this->codeGraphic->height();
|
int h = this->codeGraphic->height();
|
||||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
|
||||||
|
|
||||||
const QBrush bg = QBrush(QColor(74, 74, 74));
|
const QBrush bg = QBrush(QColor(74, 74, 74));
|
||||||
|
|
||||||
scene->setBackgroundBrush(bg);
|
graphicsScene->setBackgroundBrush(bg);
|
||||||
this->codeGraphic->setRenderHints(0);
|
this->codeGraphic->setRenderHints(0);
|
||||||
this->codeGraphic->setScene(scene);
|
this->codeGraphic->setScene(graphicsScene);
|
||||||
this->codeGraphic->setRenderHints(QPainter::Antialiasing);
|
this->codeGraphic->setRenderHints(QPainter::Antialiasing);
|
||||||
this->codeGraphic->setToolTip("gap");
|
this->codeGraphic->setToolTip("gap");
|
||||||
|
|
||||||
@ -131,6 +138,10 @@ void GraphicsBar::fillData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int graph_block = local_w / num;
|
int graph_block = local_w / num;
|
||||||
|
if(graph_block == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
for (auto j : mainMap["blocks"].toList())
|
for (auto j : mainMap["blocks"].toList())
|
||||||
@ -156,7 +167,7 @@ void GraphicsBar::fillData()
|
|||||||
rect->setPen(Qt::NoPen);
|
rect->setPen(Qt::NoPen);
|
||||||
rect->setBrush(QBrush(QColor(252, 249, 190)));
|
rect->setBrush(QBrush(QColor(252, 249, 190)));
|
||||||
rect->setToolTip("Data");
|
rect->setToolTip("Data");
|
||||||
scene->addItem(rect);
|
graphicsScene->addItem(rect);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -180,7 +191,7 @@ void GraphicsBar::fillData()
|
|||||||
rect->setBrush(QBrush(QColor(190, 190, 190)));
|
rect->setBrush(QBrush(QColor(190, 190, 190)));
|
||||||
}
|
}
|
||||||
rect->setToolTip(generateTooltip(section.name, map));
|
rect->setToolTip(generateTooltip(section.name, map));
|
||||||
scene->addItem(rect);
|
graphicsScene->addItem(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether this block contains the current address.
|
// Check whether this block contains the current address.
|
||||||
@ -202,7 +213,7 @@ void GraphicsBar::fillData()
|
|||||||
QGraphicsRectItem *rect = new QGraphicsRectItem(cursor_x, 0, 2, h);
|
QGraphicsRectItem *rect = new QGraphicsRectItem(cursor_x, 0, 2, h);
|
||||||
rect->setPen(Qt::NoPen);
|
rect->setPen(Qt::NoPen);
|
||||||
rect->setBrush(QBrush(QColor(255, 0, 0)));
|
rect->setBrush(QBrush(QColor(255, 0, 0)));
|
||||||
scene->addItem(rect);
|
graphicsScene->addItem(rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define GRAPHICSBAR_H
|
#define GRAPHICSBAR_H
|
||||||
|
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
#include "cutter.h"
|
#include "cutter.h"
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QGraphicsView *codeGraphic;
|
QGraphicsView *codeGraphic;
|
||||||
|
QGraphicsScene *graphicsScene;
|
||||||
MainWindow *main;
|
MainWindow *main;
|
||||||
RVA totalSectionsSize;
|
RVA totalSectionsSize;
|
||||||
QList<SectionDescription> sections;
|
QList<SectionDescription> sections;
|
||||||
@ -40,6 +42,8 @@ private:
|
|||||||
QList<struct xToAddress> xToAddress;
|
QList<struct xToAddress> xToAddress;
|
||||||
QString generateTooltip(QString section_name, QMap<QString, QVariant> map);
|
QString generateTooltip(QString section_name, QMap<QString, QVariant> map);
|
||||||
|
|
||||||
|
// Used to check whether the width changed. If yes we need to re-initialize the scene (slow)
|
||||||
|
int previousWidth;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user