summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-06-18 11:38:10 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-06-18 11:39:47 (GMT)
commit747c7a9a060267dee9622c96bf0e2a54147dacfa (patch)
tree9e787664dc5cf21d0078649dfa99626c98f8e630 /tests/auto
parent88130cb56b0b1b7332430d6045946635ca1c8c75 (diff)
downloadQt-747c7a9a060267dee9622c96bf0e2a54147dacfa.zip
Qt-747c7a9a060267dee9622c96bf0e2a54147dacfa.tar.gz
Qt-747c7a9a060267dee9622c96bf0e2a54147dacfa.tar.bz2
QItemEditorFactory: made sure the ownership is taken on the
QItemEditorCreator The creators were not deleted i nthe destructor of QItemEditorFactory and they could not be safely used for more than one type. Task-number: 228255 Reviewed-by: jasplin
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp b/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp
index 5540b38..d9a7d56 100644
--- a/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp
+++ b/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp
@@ -61,16 +61,40 @@ void tst_QItemEditorFactory::createEditor()
void tst_QItemEditorFactory::createCustomEditor()
{
- QItemEditorFactory editorFactory;
+ //we make it inherit from QObject so that we can use QPointer
+ class MyEditor : public QObject, public QStandardItemEditorCreator<QDoubleSpinBox>
+ {
+ };
- QItemEditorCreatorBase *creator = new QStandardItemEditorCreator<QDoubleSpinBox>();
- editorFactory.registerEditor(QVariant::Rect, creator);
+ QPointer<MyEditor> creator = new MyEditor;
+ QPointer<MyEditor> creator2 = new MyEditor;
- QWidget parent;
+ {
+ QItemEditorFactory editorFactory;
+
+ editorFactory.registerEditor(QVariant::Rect, creator);
+ editorFactory.registerEditor(QVariant::RectF, creator);
+
+ //creator should not be deleted as a result of calling the next line
+ editorFactory.registerEditor(QVariant::Rect, creator2);
+ QVERIFY(creator);
+
+ //this should erase creator2
+ editorFactory.registerEditor(QVariant::Rect, creator);
+ QVERIFY(creator2.isNull());
+
+
+ QWidget parent;
+
+ QWidget *w = editorFactory.createEditor(QVariant::Rect, &parent);
+ QCOMPARE(w->metaObject()->className(), "QDoubleSpinBox");
+ QCOMPARE(w->metaObject()->userProperty().type(), QVariant::Double);
+ }
- QWidget *w = editorFactory.createEditor(QVariant::Rect, &parent);
- QCOMPARE(w->metaObject()->className(), "QDoubleSpinBox");
- QCOMPARE(w->metaObject()->userProperty().type(), QVariant::Double);
+ //editorFactory has been deleted, so should be creator
+ //because editorFActory has the ownership
+ QVERIFY(creator.isNull());
+ QVERIFY(creator2.isNull());
delete creator;
}