Fix memory leak

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-06-10 13:54:17 -03:00
parent 3eac2360e7
commit 45f80afc1f
2 changed files with 16 additions and 6 deletions

View file

@ -221,10 +221,14 @@ void ProfileGraphicsView::showEvent(QShowEvent* event)
void ProfileGraphicsView::clear() void ProfileGraphicsView::clear()
{ {
scene()->clear();
resetTransform(); resetTransform();
zoomLevel = 0; zoomLevel = 0;
toolTip = 0; if(toolTip){
scene()->removeItem(toolTip);
toolTip->deleteLater();
toolTip = 0;
}
scene()->clear();
} }
void ProfileGraphicsView::refresh() void ProfileGraphicsView::refresh()
@ -291,7 +295,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
plot_temperature_profile(); plot_temperature_profile();
/* Cylinder pressure plot */ /* Cylinder pressure plot */
plot_cylinder_pressure(dive, dc); plot_cylinder_pressure(dc);
/* Text on top of all graphs.. */ /* Text on top of all graphs.. */
plot_temperature_text(); plot_temperature_text();
@ -708,7 +712,7 @@ void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin)
plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg, 0, 'f', 1).arg(unit)); //"%.2g%s" plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg, 0, 'f', 1).arg(unit)); //"%.2g%s"
} }
void ProfileGraphicsView::plot_cylinder_pressure(struct dive *dive, struct divecomputer *dc) void ProfileGraphicsView::plot_cylinder_pressure(struct divecomputer *dc)
{ {
int i; int i;
int last = -1, last_index = -1; int last = -1, last_index = -1;
@ -1366,6 +1370,12 @@ ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), back
setZValue(99); setZValue(99);
} }
ToolTipItem::~ToolTipItem()
{
clear();
}
void ToolTipItem::updateTitlePosition() void ToolTipItem::updateTitlePosition()
{ {
if (rectangle.width() < title->boundingRect().width() + SPACING*4) { if (rectangle.width() < title->boundingRect().width() + SPACING*4) {
@ -1399,7 +1409,6 @@ bool ToolTipItem::isExpanded() {
return status == EXPANDED; return status == EXPANDED;
} }
EventItem::EventItem(QGraphicsItem* parent): QGraphicsPolygonItem(parent) EventItem::EventItem(QGraphicsItem* parent): QGraphicsPolygonItem(parent)
{ {
setFlag(ItemIgnoresTransformations); setFlag(ItemIgnoresTransformations);

View file

@ -25,6 +25,7 @@ public:
enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4}; enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
explicit ToolTipItem(QGraphicsItem* parent = 0); explicit ToolTipItem(QGraphicsItem* parent = 0);
virtual ~ToolTipItem();
void collapse(); void collapse();
void expand(); void expand();
@ -83,7 +84,7 @@ private:
void plot_events(struct divecomputer *dc); void plot_events(struct divecomputer *dc);
void plot_one_event(struct event *event); void plot_one_event(struct event *event);
void plot_temperature_profile(); void plot_temperature_profile();
void plot_cylinder_pressure(struct dive *dive, struct divecomputer *dc); void plot_cylinder_pressure(struct divecomputer *dc);
void plot_temperature_text(); void plot_temperature_text();
void plot_single_temp_text(int sec, int mkelvin); void plot_single_temp_text(int sec, int mkelvin);
void plot_depth_text(); void plot_depth_text();