[Ktutorial-commits] SF.net SVN: ktutorial:[302] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2011-05-06 12:44:42
|
Revision: 302
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=302&view=rev
Author: danxuliu
Date: 2011-05-06 12:44:36 +0000 (Fri, 06 May 2011)
Log Message:
-----------
Fix not providing information of a class if it is the class of a widget that was registered while it was being constructed.
By the way, I forgot to say it in the commit 300, and now it doesn't really do much sense, but I can't resist... "THIS... IS... KTUTORIAL!!!" :P
Modified Paths:
--------------
trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp
trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h
trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp
trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp 2011-05-05 14:39:15 UTC (rev 301)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp 2011-05-06 12:44:36 UTC (rev 302)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2010-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -58,8 +58,6 @@
mRegisteredMetaObjects.clear();
}
-//private:
-
void ObjectRegister::registerMetaObject(const QMetaObject* metaObject) {
if (mRegisteredMetaObjects.contains(metaObject->className())) {
return;
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h 2011-05-05 14:39:15 UTC (rev 301)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h 2011-05-06 12:44:36 UTC (rev 302)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2010-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -78,6 +78,13 @@
*/
void clear();
+ /**
+ * Registers a meta object and the meta objects of all its super classes.
+ *
+ * @param metaObject The meta object to register.
+ */
+ void registerMetaObject(const QMetaObject* metaObject);
+
private:
/**
@@ -100,13 +107,6 @@
*/
QHash<QString, const QMetaObject*> mRegisteredMetaObjects;
- /**
- * Registers a meta object and the meta objects of all its super classes.
- *
- * @param metaObject The meta object to register.
- */
- void registerMetaObject(const QMetaObject* metaObject);
-
private Q_SLOTS:
/**
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp 2011-05-05 14:39:15 UTC (rev 301)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp 2011-05-06 12:44:36 UTC (rev 302)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2010-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -45,6 +45,16 @@
return "";
}
+ //Ensure that the meta object is registered. If a widget is registered while
+ //it is being constructed (if the event spy is enabled, it will register the
+ //object when it sets its parent, as it sends a ParentChanged event) its
+ //real class will not be registered, only QWidget, as at that moment the
+ //object will not be fully constructed and the pointer to the meta object
+ //will not be set to the real class yet.
+ //This does not seem to happen with plain objects; only widgets send that
+ //ParentChanged event in their constructor.
+ mObjectRegister->registerMetaObject(object->metaObject());
+
return object->metaObject()->className();
}
Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2011-05-05 14:39:15 UTC (rev 301)
+++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2011-05-06 12:44:36 UTC (rev 302)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2010-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -42,6 +42,20 @@
//Tutorial* must be declared as a metatype to be used in qvariant_cast
Q_DECLARE_METATYPE(Tutorial*);
+class SubClassWidget: public QWidget {
+Q_OBJECT
+public:
+ SubClassWidget(QWidget* parent = 0): QWidget(parent) {
+ }
+};
+
+class SubSubClassWidget: public SubClassWidget {
+Q_OBJECT
+public:
+ SubSubClassWidget(QWidget* parent = 0): SubClassWidget(parent) {
+ }
+};
+
namespace editorsupport {
class EditorSupportTest: public QObject {
@@ -75,6 +89,8 @@
void testTestScriptedTutorial();
void testTestScriptedTutorialWithInvalidTutorial();
+ void testObjectRegisterWhenEventSpyNotifiesEventBeforeEndingConstructor();
+
private:
QStringList mEventTypes;
@@ -293,8 +309,52 @@
QCOMPARE(startedSpy.count(), 0);
}
+//Not really a unit test, but sort of an integration test for a strange bug.
+void EditorSupportTest::
+ testObjectRegisterWhenEventSpyNotifiesEventBeforeEndingConstructor() {
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ QVERIFY(bus.isConnected());
+
+ EditorSupport editorSupport;
+ QWidget mainWidget;
+
+ editorSupport.setup(&mainWidget);
+ editorSupport.enableEventSpy();
+
+ SubSubClassWidget* childWidget = new SubSubClassWidget(&mainWidget);
+
+ QCOMPARE(childWidget->metaObject()->className(),
+ "SubSubClassWidget");
+ QCOMPARE(childWidget->metaObject()->superClass()->className(),
+ "SubClassWidget");
+ QCOMPARE(childWidget->metaObject()->superClass()->superClass()->className(),
+ "QWidget");
+
+ //childWidget gets registered by a ParentChange event. However, that event
+ //is sent by QWidget constructor itself. The object is not fully
+ //constructed, so SubClassWidget and SubSubClassWidget are not registered.
+ ObjectRegister* objectRegister = editorSupport.mObjectRegister;
+ QCOMPARE(objectRegister->objectForId(1), &mainWidget);
+ QCOMPARE(objectRegister->objectForId(2), childWidget);
+ QVERIFY(objectRegister->metaObjectForClassName("QWidget"));
+ QVERIFY(!objectRegister->metaObjectForClassName("SubClassWidget"));
+ QVERIFY(!objectRegister->metaObjectForClassName("SubSubClassWidget"));
+
+ //From the outside (the caller DBus client), the only way to get an object
+ //class is asking the ObjectRegister adaptor about it. So if a class is
+ //registered after its name was returned by the ObjectRegister adaptor, when
+ //the client asks for information about that class the register will be able
+ //to provide it.
+ ObjectRegisterAdaptor* objectRegisterAdaptor =
+ objectRegister->findChild<ObjectRegisterAdaptor*>();
+
+ QCOMPARE(objectRegisterAdaptor->className(2), QString("SubSubClassWidget"));
+ QVERIFY(objectRegister->metaObjectForClassName("SubClassWidget"));
+ QVERIFY(objectRegister->metaObjectForClassName("SubSubClassWidget"));
}
+}
+
QTEST_MAIN(editorsupport::EditorSupportTest)
#include "EditorSupportTest.moc"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|