summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsobject
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-10-28 09:42:14 +0100
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-10-28 09:56:11 +0100
commit08e5bae295204ac0cadc1dda6c7a01599f66a2bb (patch)
tree5295f92e3d03ab4ed7761a7f81c581121af811f0 /tests/auto/qgraphicsobject
parentdf0001a3d62938c713b351c7e59228b803ec5670 (diff)
Let QGraphicsItem set QObjectPrivate::wasDeleted when appropriate.
This change allows children of QGraphicsObject-derived classes to check if the parent is being deleted by checking the private flag wasDeleted. Reverts 37b16d5cbb4e7bc534f690ebf50434d228b5ecfc, p4 change 9681, to allow QGraphicsItem to set QObjectPrivate's wasDeleted member before entering QObjectPrivate's destructor. The original code was in there to let the user know, via the console output, that QObject was double-deleted (e.g., when placing QObject on the stack, and also giving it a parent, so that if the parent is deleted first, bang). Reviewed-by: Aaron Kennedy Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'tests/auto/qgraphicsobject')
-rw-r--r--tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp b/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
index a9fd55a564..194665d675 100644
--- a/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
+++ b/tests/auto/qgraphicsobject/tst_qgraphicsobject.cpp
@@ -46,6 +46,7 @@
#include <qgraphicssceneevent.h>
#include <qgraphicsview.h>
#include <qstyleoption.h>
+#include <private/qobject_p.h>
#include "../../shared/util.h"
class tst_QGraphicsObject : public QObject {
@@ -65,6 +66,7 @@ private slots:
void opacity();
void enabled();
void visible();
+ void deleted();
};
@@ -249,6 +251,46 @@ void tst_QGraphicsObject::visible()
QVERIFY(object.property("visible") == true);
}
+class DeleteTester : public QGraphicsObject
+{
+public:
+ DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = 0)
+ : QGraphicsObject(parent), wasDeleted(w), parentWasDeleted(pw)
+ { }
+
+ ~DeleteTester()
+ {
+ *wasDeleted = QObjectPrivate::get(this)->wasDeleted;
+ if (QGraphicsItem *p = parentItem()) {
+ if (QGraphicsObject *o = p->toGraphicsObject())
+ *parentWasDeleted = QObjectPrivate::get(o)->wasDeleted;
+ }
+ }
+
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0)
+ { }
+ QRectF boundingRect() const
+ { return QRectF(); }
+
+ bool *wasDeleted;
+ bool *parentWasDeleted;
+};
+
+void tst_QGraphicsObject::deleted()
+{
+ bool item1_parentWasDeleted = false;
+ bool item1_wasDeleted = false;
+ bool item2_parentWasDeleted = false;
+ bool item2_wasDeleted = false;
+ DeleteTester *item1 = new DeleteTester(&item1_wasDeleted, &item1_parentWasDeleted);
+ DeleteTester *item2 = new DeleteTester(&item2_wasDeleted, &item2_parentWasDeleted, item1);
+ delete item1;
+
+ QVERIFY(!item1_wasDeleted); // destructor not called yet
+ QVERIFY(!item1_parentWasDeleted); // no parent
+ QVERIFY(!item2_wasDeleted); // destructor not called yet
+ QVERIFY(item2_parentWasDeleted);
+}
QTEST_MAIN(tst_QGraphicsObject)
#include "tst_qgraphicsobject.moc"