1
0
Fork 0
mirror of https://github.com/subsurface/subsurface.git synced 2025-02-19 22:16:15 +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:
Tomaz Canabrava 2015-01-14 13:02:18 -02:00 committed by Dirk Hohndel
parent 633dd64d2f
commit db4ffd0b70
2 changed files with 19 additions and 19 deletions

View file

@ -19,7 +19,7 @@
#include "display.h" #include "display.h"
#endif #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(); 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 = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this);
iconItem->setPos(iconMetrics.spacing, yValue); iconItem->setPos(iconMetrics.spacing, yValue);
} else { } else {
if (pixmap && !pixmap->isNull()) { if (!pixmap.isNull()) {
pixmapItem = new QGraphicsPixmapItem(*pixmap, this); pixmapItem = new QGraphicsPixmapItem(pixmap, this);
pixmapItem->setPos(iconMetrics.spacing, yValue); pixmapItem->setPos(iconMetrics.spacing, yValue);
} }
} }
@ -232,8 +232,8 @@ void ToolTipItem::refresh(const QPointF &pos)
{ {
int i; int i;
struct plot_data *entry; struct plot_data *entry;
static QPixmap *tissues = new QPixmap(16,60); static QPixmap tissues(16,60);
static QPainter *painter = new QPainter(tissues); static QPainter painter(&tissues);
int time = timeAxis->valueAt(pos); int time = timeAxis->valueAt(pos);
if (time == lastTime) if (time == lastTime)
return; return;
@ -244,21 +244,21 @@ void ToolTipItem::refresh(const QPointF &pos)
entry = get_plot_details_new(&pInfo, time, &mb); entry = get_plot_details_new(&pInfo, time, &mb);
if (entry) { if (entry) {
tissues->fill(); tissues.fill();
painter->setPen(QColor(0, 0, 0, 0)); painter.setPen(QColor(0, 0, 0, 0));
painter->setBrush(QColor(LIMENADE1)); painter.setBrush(QColor(LIMENADE1));
painter->drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2); painter.drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2);
painter->setBrush(QColor(SPRINGWOOD1)); painter.setBrush(QColor(SPRINGWOOD1));
painter->drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2); painter.drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2);
painter->setBrush(QColor("Red")); painter.setBrush(QColor(Qt::red));
painter->drawRect(0,0,16,10); painter.drawRect(0,0,16,10);
painter->setPen(QColor(0, 0, 0, 255)); painter.setPen(QColor(0, 0, 0, 255));
painter->drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2); 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, 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); 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++) { 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); addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues);
} }

View file

@ -34,7 +34,7 @@ public:
void collapse(); void collapse();
void expand(); void expand();
void clear(); 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); void refresh(const QPointF &pos);
bool isExpanded() const; bool isExpanded() const;
void persistPos(); void persistPos();