mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Fix memory leak
The QPainter and the QPixmap were being created but never freed. A QPixmap and a QPainter don't need to be created by new, they can be safely created on the stack. So, create them on the stack, pass them via const-reference and use them correctly. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
633dd64d2f
commit
db4ffd0b70
2 changed files with 19 additions and 19 deletions
|
@ -19,7 +19,7 @@
|
|||
#include "display.h"
|
||||
#endif
|
||||
|
||||
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap *pixmap)
|
||||
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap)
|
||||
{
|
||||
const IconMetrics& iconMetrics = defaultIconMetrics();
|
||||
|
||||
|
@ -32,8 +32,8 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP
|
|||
iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this);
|
||||
iconItem->setPos(iconMetrics.spacing, yValue);
|
||||
} else {
|
||||
if (pixmap && !pixmap->isNull()) {
|
||||
pixmapItem = new QGraphicsPixmapItem(*pixmap, this);
|
||||
if (!pixmap.isNull()) {
|
||||
pixmapItem = new QGraphicsPixmapItem(pixmap, this);
|
||||
pixmapItem->setPos(iconMetrics.spacing, yValue);
|
||||
}
|
||||
}
|
||||
|
@ -232,8 +232,8 @@ void ToolTipItem::refresh(const QPointF &pos)
|
|||
{
|
||||
int i;
|
||||
struct plot_data *entry;
|
||||
static QPixmap *tissues = new QPixmap(16,60);
|
||||
static QPainter *painter = new QPainter(tissues);
|
||||
static QPixmap tissues(16,60);
|
||||
static QPainter painter(&tissues);
|
||||
int time = timeAxis->valueAt(pos);
|
||||
if (time == lastTime)
|
||||
return;
|
||||
|
@ -244,21 +244,21 @@ void ToolTipItem::refresh(const QPointF &pos)
|
|||
|
||||
entry = get_plot_details_new(&pInfo, time, &mb);
|
||||
if (entry) {
|
||||
tissues->fill();
|
||||
painter->setPen(QColor(0, 0, 0, 0));
|
||||
painter->setBrush(QColor(LIMENADE1));
|
||||
painter->drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2);
|
||||
painter->setBrush(QColor(SPRINGWOOD1));
|
||||
painter->drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2);
|
||||
painter->setBrush(QColor("Red"));
|
||||
painter->drawRect(0,0,16,10);
|
||||
painter->setPen(QColor(0, 0, 0, 255));
|
||||
painter->drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2);
|
||||
painter->drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2,
|
||||
tissues.fill();
|
||||
painter.setPen(QColor(0, 0, 0, 0));
|
||||
painter.setBrush(QColor(LIMENADE1));
|
||||
painter.drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2);
|
||||
painter.setBrush(QColor(SPRINGWOOD1));
|
||||
painter.drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2);
|
||||
painter.setBrush(QColor(Qt::red));
|
||||
painter.drawRect(0,0,16,10);
|
||||
painter.setPen(QColor(0, 0, 0, 255));
|
||||
painter.drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2);
|
||||
painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2,
|
||||
16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2);
|
||||
painter->setPen(QColor(0, 0, 0, 127));
|
||||
painter.setPen(QColor(0, 0, 0, 127));
|
||||
for (i=0; i<16; i++) {
|
||||
painter->drawLine(i, 60, i, 60 - entry->percentages[i] / 2);
|
||||
painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2);
|
||||
}
|
||||
addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
void collapse();
|
||||
void expand();
|
||||
void clear();
|
||||
void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap *pixmap = NULL);
|
||||
void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap &pixmap = QPixmap());
|
||||
void refresh(const QPointF &pos);
|
||||
bool isExpanded() const;
|
||||
void persistPos();
|
||||
|
|
Loading…
Reference in a new issue