[Ktutorial-commits] SF.net SVN: ktutorial:[358] trunk/ktutorial
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2012-08-09 15:52:12
|
Revision: 358 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=358&view=rev Author: danxuliu Date: 2012-08-09 15:52:01 +0000 (Thu, 09 Aug 2012) Log Message: ----------- Add support for null objects in the editor support module. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h trunk/ktutorial/ktutorial-library/tests/editorsupport/ObjectRegisterTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp 2012-08-09 09:40:28 UTC (rev 357) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp 2012-08-09 15:52:01 UTC (rev 358) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -35,6 +35,10 @@ } RemoteObject* RemoteObjectMapper::remoteObject(int objectId) { + if (objectId == 0) { + return 0; + } + if (mRemoteObjects.contains(objectId)) { return mRemoteObjects.value(objectId); } Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h 2012-08-09 09:40:28 UTC (rev 357) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h 2012-08-09 15:52:01 UTC (rev 358) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -54,6 +54,8 @@ * Returns the RemoteObject associated with the given object id. * The RemoteObject is destroyed when this RemoteObjectMapper is cleared or * destroyed, so consider using QPointer to store it. + * The object id 0 is a special case, and it is associated to the null + * object; a null pointer is returned in this case. * * @param objectId The id of the remote object. * @return The RemoteObject. Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp 2012-08-09 09:40:28 UTC (rev 357) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp 2012-08-09 15:52:01 UTC (rev 358) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -37,6 +37,7 @@ void testRemoteObject(); void testRemoteObjectSeveralIds(); void testRemoteObjectTwice(); + void testRemoteNullObject(); void testRemoteClass(); void testRemoteClassSeveralIds(); @@ -101,6 +102,14 @@ QCOMPARE(remoteObject1->name(), QString("The object name 42")); } +void RemoteObjectMapperTest::testRemoteNullObject() { + RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); + + RemoteObject* remoteObject = mapper.remoteObject(0); + + QVERIFY(!remoteObject); +} + void RemoteObjectMapperTest::testRemoteClass() { RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp 2012-08-09 09:40:28 UTC (rev 357) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp 2012-08-09 15:52:01 UTC (rev 358) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -27,6 +27,10 @@ } int ObjectRegister::idForObject(QObject* object) { + if (!object) { + return 0; + } + int id = mRegisteredIds.value(object); if (!id) { Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h 2012-08-09 09:40:28 UTC (rev 357) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h 2012-08-09 15:52:01 UTC (rev 358) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -29,7 +29,7 @@ * The id for an object is assigned after the first time the id is requested * for that object, and are valid until the register is cleared or the object is * destroyed (if an object is destroyed it is automatically removed from the - * register). + * register). The null object is a special case, and its id is always 0. * * When an object is registered, its QMetaObject and the QMetaObject of all its * super classes are also registered. The QMetaObject can be got using the class Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/ObjectRegisterTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/editorsupport/ObjectRegisterTest.cpp 2012-08-09 09:40:28 UTC (rev 357) +++ trunk/ktutorial/ktutorial-library/tests/editorsupport/ObjectRegisterTest.cpp 2012-08-09 15:52:01 UTC (rev 358) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -44,6 +44,7 @@ void testRegisterObject(); void testRegisterObjectSeveralObjects(); void testRegisterObjectTwice(); + void testRegisterNullObject(); void testObjectForIdWithDestroyedObject(); @@ -112,6 +113,14 @@ &QObject::staticMetaObject); } +void ObjectRegisterTest::testRegisterNullObject() { + ObjectRegister objectRegister; + + int id = objectRegister.idForObject(0); + + QCOMPARE(objectRegister.objectForId(id), (QObject*)0); +} + void ObjectRegisterTest::testObjectForIdWithDestroyedObject() { ObjectRegister objectRegister; QObject* object = new QObject(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |