KTutorial
0.5.1
|
00001 /*************************************************************************** 00002 * Copyright (C) 2010 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00003 * Copyright (C) 2011 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00004 * Copyright (C) 2012 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00005 * * 00006 * This program is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 2 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * This program is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program; If not, see <http://www.gnu.org/licenses/>. * 00018 ***************************************************************************/ 00019 00020 #include "ObjectRegisterAdaptor.h" 00021 #include "ObjectRegister.h" 00022 00023 namespace ktutorial { 00024 namespace editorsupport { 00025 00026 //public: 00027 00028 ObjectRegisterAdaptor::ObjectRegisterAdaptor(ObjectRegister* objectRegister): 00029 QDBusAbstractAdaptor(objectRegister), 00030 mObjectRegister(objectRegister) { 00031 } 00032 00033 //public slots: 00034 00035 QString ObjectRegisterAdaptor::objectName(int objectId) const { 00036 QObject* object = mObjectRegister->objectForId(objectId); 00037 if (!object) { 00038 return ""; 00039 } 00040 00041 return object->objectName(); 00042 } 00043 00044 QString ObjectRegisterAdaptor::className(int objectId) const { 00045 QObject* object = mObjectRegister->objectForId(objectId); 00046 if (!object) { 00047 return ""; 00048 } 00049 00050 //Ensure that the meta object is registered. If a widget is registered while 00051 //it is being constructed (if the event spy is enabled, it will register the 00052 //object when it sets its parent, as it sends a ParentChanged event) its 00053 //real class will not be registered, only QWidget, as at that moment the 00054 //object will not be fully constructed and the pointer to the meta object 00055 //will not be set to the real class yet. 00056 //This does not seem to happen with plain objects; only widgets send that 00057 //ParentChanged event in their constructor. 00058 mObjectRegister->registerMetaObject(object->metaObject()); 00059 00060 return object->metaObject()->className(); 00061 } 00062 00063 QList<int> ObjectRegisterAdaptor::childObjectIds(int objectId) const { 00064 QObject* object = mObjectRegister->objectForId(objectId); 00065 if (!object) { 00066 return QList<int>(); 00067 } 00068 00069 QList<int> ids; 00070 foreach (QObject* childObject, object->children()) { 00071 ids.append(mObjectRegister->idForObject(childObject)); 00072 } 00073 00074 return ids; 00075 } 00076 00077 void ObjectRegisterAdaptor::clear() { 00078 mObjectRegister->clear(); 00079 } 00080 00081 } 00082 }