mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
947010991d
commit
c9499baf22
2 changed files with 18 additions and 17 deletions
|
@ -45,17 +45,26 @@ void CloseButtonItem::show()
|
||||||
DiveButtonItem::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);
|
setFlag(ItemIgnoresTransformations);
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
setAcceptsHoverEvents(true);
|
|
||||||
#else
|
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
#endif
|
|
||||||
setScale(0.2);
|
setScale(0.2);
|
||||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
|
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
|
||||||
setVisible(prefs.show_pictures_in_profile);
|
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()
|
void DivePictureItem::settingsChanged()
|
||||||
|
@ -67,18 +76,8 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
|
||||||
{
|
{
|
||||||
DivePixmapItem::setPixmap(pix);
|
DivePixmapItem::setPixmap(pix);
|
||||||
QRectF r = boundingRect();
|
QRectF r = boundingRect();
|
||||||
QGraphicsRectItem *rect = new QGraphicsRectItem(0 - 10, 0 -10, r.width() + 20, r.height() + 20, this);
|
canvas->setRect(0 - 10, 0 -10, r.width() + 20, r.height() + 20);
|
||||||
rect->setPen(Qt::NoPen);
|
shadow->setRect(canvas->rect());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseButtonItem *button = NULL;
|
CloseButtonItem *button = NULL;
|
||||||
|
|
|
@ -31,6 +31,8 @@ protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
private:
|
private:
|
||||||
QString fileUrl;
|
QString fileUrl;
|
||||||
|
QGraphicsRectItem *canvas;
|
||||||
|
QGraphicsRectItem *shadow;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiveButtonItem : public DivePixmapItem {
|
class DiveButtonItem : public DivePixmapItem {
|
||||||
|
|
Loading…
Add table
Reference in a new issue