summaryrefslogtreecommitdiffstats
path: root/profile-widget/divepixmapitem.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-05-16 22:50:24 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-17 07:22:04 -0700
commitf54268e527764dac4893ad68703a7fa67c2d1ecb (patch)
treecaf7c70f76036e3cf1984772f2157ca7fa3616b8 /profile-widget/divepixmapitem.cpp
parentafe88435094fbb1aa179baab5e2e16249258851a (diff)
downloadsubsurface-f54268e527764dac4893ad68703a7fa67c2d1ecb.tar.gz
Dive pictures: Fix crash on picture delete
The recent simplification of the close button code introduced a crash: Deletion of pictures caused an invalid memory access, because the CloseButtonItem was deleted with the parent DivePicture item. For some (not fully understood!) reason, a reference to this button was stored in the depths of Qt. Empirically, it was found out that removing the first line of the pair QGraphicsItem::mousePressEvent(event); emit clicked(); fixed the crash. It seemed therefore prudent to remove the whole questionable signal/slot mechanism and directly call the removePicture() function of the parent. Thus, the intermediate DiveButtonItem class became unnecessary and was removed, leading to a shallower class hierarchy. Unfortunately, CloseButtonItem must still be derived from QObject owing to the Q_PROPERTY machinery, which is in turn needed for animation. To make this compile on mobile, the conditional compilation of removePicture() (#ifndef SUBSURFACE_MOBILE) was removed. After all, if DivePixmapItem is used, there are pictures, so removePicture() should be functional. Conditional compilation should concern the whole class, not only this function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/divepixmapitem.cpp')
-rw-r--r--profile-widget/divepixmapitem.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/profile-widget/divepixmapitem.cpp b/profile-widget/divepixmapitem.cpp
index 08525fe34..0d1051dad 100644
--- a/profile-widget/divepixmapitem.cpp
+++ b/profile-widget/divepixmapitem.cpp
@@ -16,31 +16,26 @@ DivePixmapItem::DivePixmapItem(QGraphicsItem *parent) : QGraphicsPixmapItem(pare
{
}
-DiveButtonItem::DiveButtonItem(QGraphicsItem *parent): DivePixmapItem(parent)
-{
-}
-
-void DiveButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{
- QGraphicsItem::mousePressEvent(event);
- emit clicked();
-}
-
-CloseButtonItem::CloseButtonItem(QGraphicsItem *parent): DiveButtonItem(parent)
+CloseButtonItem::CloseButtonItem(QGraphicsItem *parent): DivePixmapItem(parent)
{
static QPixmap p = QPixmap(":list-remove-icon");
setPixmap(p);
setFlag(ItemIgnoresTransformations);
}
+void CloseButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ qgraphicsitem_cast<DivePictureItem*>(parentItem())->removePicture();
+}
+
void CloseButtonItem::hide()
{
- DiveButtonItem::hide();
+ DivePixmapItem::hide();
}
void CloseButtonItem::show()
{
- DiveButtonItem::show();
+ DivePixmapItem::show();
}
DivePictureItem::DivePictureItem(QGraphicsItem *parent): DivePixmapItem(parent),
@@ -96,7 +91,6 @@ void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
button->setOpacity(0);
button->show();
Animations::show(button);
- connect(button, SIGNAL(clicked()), this, SLOT(removePicture()));
}
void DivePictureItem::setFileUrl(const QString &s)
@@ -119,9 +113,9 @@ void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
-#ifndef SUBSURFACE_MOBILE
void DivePictureItem::removePicture()
{
+#ifndef SUBSURFACE_MOBILE
DivePictureModel::instance()->removePicture(fileUrl, true);
-}
#endif
+}