GammaRay  2.2.0
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
metaobjectrepository.h
Go to the documentation of this file.
1 /*
2  metaobjectrepository.h
3 
4  This file is part of GammaRay, the Qt application inspection and
5  manipulation tool.
6 
7  Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8  Author: Volker Krause <volker.krause@kdab.com>
9 
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.
14 
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.
19 
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/>.
22 */
23 
28 #ifndef GAMMARAY_METAOBJECTREPOSITORY_H
29 #define GAMMARAY_METAOBJECTREPOSITORY_H
30 
31 #include "gammaray_core_export.h"
32 #include <QHash>
33 
34 class QString;
35 
36 namespace GammaRay {
37 
38 class MetaObject;
39 
46 class GAMMARAY_CORE_EXPORT MetaObjectRepository
47 {
48  public:
50 
52  static MetaObjectRepository *instance();
53 
57  void addMetaObject(MetaObject *mo);
58 
62  MetaObject *metaObject(const QString& typeName) const;
63 
67  bool hasMetaObject(const QString &typeName) const;
68 
69  protected:
71 
72  private:
73  void initBuiltInTypes();
74  void initQObjectTypes();
75  void initIOTypes();
76  void initNetworkTypes();
77  void initGuiTypes();
78  void initOpenGLTypes();
79 
80  private:
81  QHash<QString, MetaObject*> m_metaObjects;
82  bool m_initialized;
83 };
84 
85 }
87 #define MO_ADD_BASECLASS(Base) \
88  Q_ASSERT(GammaRay::MetaObjectRepository::instance()->hasMetaObject(QLatin1String(#Base))); \
89  mo->addBaseClass(GammaRay::MetaObjectRepository::instance()->metaObject(QLatin1String(#Base)));
90 
91 
95 #define MO_ADD_METAOBJECT0(Class) \
96  mo = new GammaRay::MetaObjectImpl<Class>; \
97  mo->setClassName(QLatin1String(#Class)); \
98  GammaRay::MetaObjectRepository::instance()->addMetaObject(mo);
99 
103 #define MO_ADD_METAOBJECT1(Class, Base1) \
104  mo = new GammaRay::MetaObjectImpl<Class, Base1>; \
105  mo->setClassName(QLatin1String(#Class)); \
106  MO_ADD_BASECLASS(Base1) \
107  GammaRay::MetaObjectRepository::instance()->addMetaObject(mo);
108 
112 #define MO_ADD_METAOBJECT2(Class, Base1, Base2) \
113  mo = new GammaRay::MetaObjectImpl<Class, Base1, Base2>; \
114  mo->setClassName(QLatin1String(#Class)); \
115  MO_ADD_BASECLASS(Base1) \
116  MO_ADD_BASECLASS(Base2) \
117  GammaRay::MetaObjectRepository::instance()->addMetaObject(mo);
118 
120 #define MO_ADD_PROPERTY(Class, Type, Getter, Setter) \
121  mo->addProperty(new GammaRay::MetaPropertyImpl<Class, Type>( \
122  QLatin1String(#Getter), \
123  &Class::Getter, \
124  static_cast<void (Class::*)(Type)>(&Class::Setter)) \
125  );
126 
128 #define MO_ADD_PROPERTY_CR(Class, Type, Getter, Setter) \
129  mo->addProperty(new GammaRay::MetaPropertyImpl<Class, Type, const Type&>( \
130  QLatin1String(#Getter), \
131  &Class::Getter, \
132  static_cast<void (Class::*)(const Type&)>(&Class::Setter)) \
133  );
134 
136 #define MO_ADD_PROPERTY_RO(Class, Type, Getter) \
137  mo->addProperty(new GammaRay::MetaPropertyImpl<Class, Type>( \
138  QLatin1String(#Getter), \
139  &Class::Getter));
140 
141 #endif // GAMMARAY_METAOBJECTREPOSITORY_H

Klarälvdalens Datakonsult AB (KDAB)
"The Qt Experts"
http://www.kdab.com/
GammaRay
Qt-application inspection and manipulation tool
http://www.kdab.com/kdab-products/gammaray/