d/control: Recommend gdb
[gammaray-debian.git] / metaobject.cpp
blobee5d7991c8dbbf93e842ce8dbc265fb124de1092
1 /*
2 metaobject.cpp
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
7 Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "metaobject.h"
26 using namespace GammaRay;
28 MetaObject::MetaObject()
32 MetaObject::~MetaObject()
34 qDeleteAll(m_properties);
37 int MetaObject::propertyCount() const
39 int count = 0;
40 foreach (MetaObject *mo, m_baseClasses) {
41 count += mo->propertyCount();
43 return count + m_properties.size();
46 MetaProperty *MetaObject::propertyAt(int index) const
48 foreach (MetaObject *mo, m_baseClasses) {
49 if (index >= mo->propertyCount()) {
50 index -= mo->propertyCount();
51 } else {
52 return mo->propertyAt(index);
55 Q_ASSERT(index >= 0 && index < m_properties.size());
56 return m_properties.at(index);
59 void MetaObject::addBaseClass(MetaObject *baseClass)
61 Q_ASSERT(baseClass);
62 m_baseClasses.push_back(baseClass);
65 void MetaObject::addProperty(MetaProperty *property)
67 Q_ASSERT(property);
68 // TODO: sort
69 property->setMetaObject(this);
70 m_properties.push_back(property);
73 QString MetaObject::className() const
75 return m_className;
78 void MetaObject::setClassName(const QString &className)
80 m_className = className;
83 void *MetaObject::castForPropertyAt(void *object, int index) const
85 for (int i = 0; i < m_baseClasses.size(); ++i) {
86 const MetaObject *base = m_baseClasses.at(i);
87 if (index >= base->propertyCount()) {
88 index -= base->propertyCount();
89 } else {
90 return base->castForPropertyAt(castToBaseClass(object, i), index);
93 return object; // our own property