summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-01-16 18:12:02 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-17 10:41:07 +1300
commitc9499baf2225a0c0584c57b6c47eff53c40249b1 (patch)
treea838a3bd1246e5ce77caad49d5c6cdb550881956 /qt-ui
parent947010991da4b44cbbf1a2e7c63d3f6a65c41404 (diff)
downloadsubsurface-c9499baf2225a0c0584c57b6c47eff53c40249b1.tar.gz
Fix memleak of QGraphicsRectItem
We used to create a new QGraphicsRectItem everytime a Pixmap changed. Since I'm pretty sure I deleted every bit of the PictureItem before setting a new one, no leak was due, but this version is safer. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/profile/divepixmapitem.cpp33
-rw-r--r--qt-ui/profile/divepixmapitem.h2
2 files changed, 18 insertions, 17 deletions
diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp
index ce5d3c404..8aff5315d 100644
--- a/qt-ui/profile/divepixmapitem.cpp
+++ b/qt-ui/profile/divepixmapitem.cpp
@@ -45,17 +45,26 @@ void CloseButtonItem::show()
DiveButtonItem::show();
}
-DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent)
+DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent),
+ canvas(new QGraphicsRectItem(this)),
+ shadow(new QGraphicsRectItem(this))
{
setFlag(ItemIgnoresTransformations);
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
- setAcceptsHoverEvents(true);
-#else
setAcceptHoverEvents(true);
-#endif
setScale(0.2);
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
setVisible(prefs.show_pictures_in_profile);
+
+ canvas->setPen(Qt::NoPen);
+ canvas->setBrush(QColor(Qt::white));
+ canvas->setFlag(ItemStacksBehindParent);
+ canvas->setZValue(-1);
+
+ shadow->setPos(5,5);
+ shadow->setPen(Qt::NoPen);
+ shadow->setBrush(QColor(Qt::lightGray));
+ shadow->setFlag(ItemStacksBehindParent);
+ shadow->setZValue(-2);
}
void DivePictureItem::settingsChanged()
@@ -67,18 +76,8 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
{
DivePixmapItem::setPixmap(pix);
QRectF r = boundingRect();
- QGraphicsRectItem *rect = new QGraphicsRectItem(0 - 10, 0 -10, r.width() + 20, r.height() + 20, this);
- rect->setPen(Qt::NoPen);
- rect->setBrush(QColor(Qt::white));
- rect->setFlag(ItemStacksBehindParent);
- rect->setZValue(-1);
-
- QGraphicsRectItem *shadow = new QGraphicsRectItem(rect->boundingRect(), this);
- shadow->setPos(5,5);
- shadow->setPen(Qt::NoPen);
- shadow->setBrush(QColor(Qt::lightGray));
- shadow->setFlag(ItemStacksBehindParent);
- shadow->setZValue(-2);
+ canvas->setRect(0 - 10, 0 -10, r.width() + 20, r.height() + 20);
+ shadow->setRect(canvas->rect());
}
CloseButtonItem *button = NULL;
diff --git a/qt-ui/profile/divepixmapitem.h b/qt-ui/profile/divepixmapitem.h
index 963e641e8..02c1523f7 100644
--- a/qt-ui/profile/divepixmapitem.h
+++ b/qt-ui/profile/divepixmapitem.h
@@ -31,6 +31,8 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
QString fileUrl;
+ QGraphicsRectItem *canvas;
+ QGraphicsRectItem *shadow;
};
class DiveButtonItem : public DivePixmapItem {