src/hbcore/effects/hbeffect.cpp
changeset 21 4633027730f5
parent 5 627c4a0fd0e7
child 30 80e4d18b72f5
--- a/src/hbcore/effects/hbeffect.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbcore/effects/hbeffect.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -127,6 +127,12 @@
 {
     privateDestroyed = true;
     mDisabledItems.clear();
+    // Delete all remaining animated item groups
+    HbAnimatedItemGroup *itemGroup = 0;
+    while (mAnimatedItemGroups.count()) {
+        itemGroup = mAnimatedItemGroups.first();
+        animatedItemGroupFinished(itemGroup);
+    }
 }
 
 void HbEffectPrivate::connectViewChanges()
@@ -143,6 +149,14 @@
     }
 }
 
+void HbEffectPrivate::addAnimatedItemGroup(HbAnimatedItemGroup *newGroup)
+{
+    // Let HbEffectPrivate handle the deletion of animated item group
+    connect(newGroup, SIGNAL(finished(HbAnimatedItemGroup *)),
+            this, SLOT(animatedItemGroupFinished(HbAnimatedItemGroup *)));
+    mAnimatedItemGroups.append(newGroup);
+}
+
 void HbEffectPrivate::handleWindowAdded(HbMainWindow *window)
 {
     connect(window, SIGNAL(currentViewChanged(HbView *)), SLOT(handleViewChanged(HbView *)));
@@ -191,6 +205,18 @@
     }
 }
 
+void HbEffectPrivate::animatedItemGroupFinished(HbAnimatedItemGroup *itemGroup)
+{
+    // Called when animated item group is finished - delete later and remove from register
+    if (itemGroup) {
+        int itemIndex = mAnimatedItemGroups.indexOf(itemGroup);
+        if (itemIndex >= 0) {
+            itemGroup->deleteLater();
+            itemGroup = 0;
+            mAnimatedItemGroups.removeAt(itemIndex);
+        }
+    }
+}
 
 HbAnimatedItemGroup::HbAnimatedItemGroup(
     const QList<QGraphicsItem *> &items,
@@ -207,7 +233,9 @@
     // Need information of receiver destroyed because this class gets
     // the notifications asynchronously so it must not invoke the
     // receiver if it has been destroyed meanwhile.
-    connect(mReceiver, SIGNAL(destroyed()), this, SLOT(receiverDestroyed()));
+    if (mReceiver) {
+        connect(mReceiver, SIGNAL(destroyed()), this, SLOT(receiverDestroyed()));
+    }
 }
 
 void HbAnimatedItemGroup::finished(const HbEffect::EffectStatus &status)
@@ -221,8 +249,8 @@
                 QGenericReturnArgument(),
                 Q_ARG(HbEffect::EffectStatus, status));
         }
-        // We are done, delete self.
-        deleteLater();
+        // We are done, notify owner
+        emit finished(this);
     }
 }
 
@@ -740,8 +768,8 @@
     // Connect to view changes if not done yet
     d.connectViewChanges();
 
-    // This object deletes itself when the effect has finished.
     HbAnimatedItemGroup *group = new HbAnimatedItemGroup(items, receiver, member, userData);
+    d.addAnimatedItemGroup(group);
 
     bool ret = false;