44 #include <qgraphicsitem.h> |
44 #include <qgraphicsitem.h> |
45 #include <qgraphicsscene.h> |
45 #include <qgraphicsscene.h> |
46 #include <qgraphicssceneevent.h> |
46 #include <qgraphicssceneevent.h> |
47 #include <qgraphicsview.h> |
47 #include <qgraphicsview.h> |
48 #include <qstyleoption.h> |
48 #include <qstyleoption.h> |
|
49 #include <private/qobject_p.h> |
49 #include "../../shared/util.h" |
50 #include "../../shared/util.h" |
50 |
51 |
51 class tst_QGraphicsObject : public QObject { |
52 class tst_QGraphicsObject : public QObject { |
52 Q_OBJECT |
53 Q_OBJECT |
53 |
54 |
247 object.setProperty("visible", true); |
249 object.setProperty("visible", true); |
248 QCOMPARE(spy.count(), 2); |
250 QCOMPARE(spy.count(), 2); |
249 QVERIFY(object.property("visible") == true); |
251 QVERIFY(object.property("visible") == true); |
250 } |
252 } |
251 |
253 |
|
254 class DeleteTester : public QGraphicsObject |
|
255 { |
|
256 public: |
|
257 DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = 0) |
|
258 : QGraphicsObject(parent), wasDeleted(w), parentWasDeleted(pw) |
|
259 { } |
|
260 |
|
261 ~DeleteTester() |
|
262 { |
|
263 *wasDeleted = QObjectPrivate::get(this)->wasDeleted; |
|
264 if (QGraphicsItem *p = parentItem()) { |
|
265 if (QGraphicsObject *o = p->toGraphicsObject()) |
|
266 *parentWasDeleted = QObjectPrivate::get(o)->wasDeleted; |
|
267 } |
|
268 } |
|
269 |
|
270 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0) |
|
271 { } |
|
272 QRectF boundingRect() const |
|
273 { return QRectF(); } |
|
274 |
|
275 bool *wasDeleted; |
|
276 bool *parentWasDeleted; |
|
277 }; |
|
278 |
|
279 void tst_QGraphicsObject::deleted() |
|
280 { |
|
281 bool item1_parentWasDeleted = false; |
|
282 bool item1_wasDeleted = false; |
|
283 bool item2_parentWasDeleted = false; |
|
284 bool item2_wasDeleted = false; |
|
285 DeleteTester *item1 = new DeleteTester(&item1_wasDeleted, &item1_parentWasDeleted); |
|
286 DeleteTester *item2 = new DeleteTester(&item2_wasDeleted, &item2_parentWasDeleted, item1); |
|
287 delete item1; |
|
288 |
|
289 QVERIFY(!item1_wasDeleted); // destructor not called yet |
|
290 QVERIFY(!item1_parentWasDeleted); // no parent |
|
291 QVERIFY(!item2_wasDeleted); // destructor not called yet |
|
292 QVERIFY(item2_parentWasDeleted); |
|
293 } |
252 |
294 |
253 QTEST_MAIN(tst_QGraphicsObject) |
295 QTEST_MAIN(tst_QGraphicsObject) |
254 #include "tst_qgraphicsobject.moc" |
296 #include "tst_qgraphicsobject.moc" |
255 |
297 |