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 "ClassRegisterAdaptor.h" 00021 00022 #include <QMetaClassInfo> 00023 00024 #include "ObjectRegister.h" 00025 00026 namespace ktutorial { 00027 namespace editorsupport { 00028 00029 //public: 00030 00031 ClassRegisterAdaptor::ClassRegisterAdaptor(ObjectRegister* objectRegister): 00032 QDBusAbstractAdaptor(objectRegister), 00033 mObjectRegister(objectRegister) { 00034 } 00035 00036 //public slots: 00037 00038 QString ClassRegisterAdaptor::superClass(const QString& className) const { 00039 const QMetaObject* metaObject = 00040 mObjectRegister->metaObjectForClassName(className); 00041 if (!metaObject) { 00042 return ""; 00043 } 00044 00045 if (!metaObject->superClass()) { 00046 return ""; 00047 } 00048 00049 return metaObject->superClass()->className(); 00050 } 00051 00052 QStringList ClassRegisterAdaptor::propertyList(const QString& className) const { 00053 const QMetaObject* metaObject = 00054 mObjectRegister->metaObjectForClassName(className); 00055 if (!metaObject) { 00056 return QStringList(); 00057 } 00058 00059 QStringList propertyList; 00060 for (int i=0; i<metaObject->propertyCount(); ++i) { 00061 QMetaProperty property = metaObject->property(i); 00062 if (isPropertyDefinedInClass(property, metaObject)) { 00063 propertyList.append(property.name()); 00064 } 00065 } 00066 00067 return propertyList; 00068 } 00069 00070 QStringList ClassRegisterAdaptor::signalList(const QString& className) const { 00071 const QMetaObject* metaObject = 00072 mObjectRegister->metaObjectForClassName(className); 00073 if (!metaObject) { 00074 return QStringList(); 00075 } 00076 00077 QStringList signalList; 00078 for (int i=0; i<metaObject->methodCount(); ++i) { 00079 QMetaMethod method = metaObject->method(i); 00080 if (isSignalDefinedInClass(method, metaObject)) { 00081 signalList.append(method.signature()); 00082 } 00083 } 00084 00085 return signalList; 00086 } 00087 00088 //private: 00089 00090 bool ClassRegisterAdaptor::isPropertyDefinedInClass( 00091 const QMetaProperty& metaProperty, 00092 const QMetaObject* metaObject) const { 00093 const QMetaObject* superClass = metaObject; 00094 while ((superClass = superClass->superClass())) { 00095 if (superClass->indexOfProperty(metaProperty.name()) != -1) { 00096 return false; 00097 } 00098 } 00099 00100 return true; 00101 } 00102 00103 bool ClassRegisterAdaptor::isSignalDefinedInClass(const QMetaMethod& metaMethod, 00104 const QMetaObject* metaObject) const { 00105 if (metaMethod.methodType() != QMetaMethod::Signal) { 00106 return false; 00107 } 00108 00109 const QMetaObject* superClass = metaObject; 00110 while ((superClass = superClass->superClass())) { 00111 if (superClass->indexOfSignal(metaMethod.signature()) != -1) { 00112 return false; 00113 } 00114 } 00115 00116 return true; 00117 } 00118 00119 } 00120 }