GammaRay  2.2.0
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
objectbroker.h
1 /*
2  objectbroker.h
3 
4  This file is part of GammaRay, the Qt application inspection and
5  manipulation tool.
6 
7  Copyright (C) 2013-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 
24 #ifndef GAMMARAY_OBJECTBROKER_H
25 #define GAMMARAY_OBJECTBROKER_H
26 
27 #include "gammaray_common_export.h"
28 
29 #include <QObject>
30 
31 class QItemSelectionModel;
32 class QAbstractItemModel;
33 
34 namespace GammaRay {
35 
37 namespace ObjectBroker {
38 
40  GAMMARAY_COMMON_EXPORT void registerObject(const QString &name, QObject *object);
41  template<class T>
42  void registerObject(QObject *object)
43  {
44  const QString interfaceName = QString::fromUtf8(qobject_interface_iid<T>());
45  registerObject(interfaceName, object);
46  }
47 
49  GAMMARAY_COMMON_EXPORT QObject* objectInternal(const QString &name, const QByteArray &type = QByteArray());
50 
59  template<class T>
60  T object(const QString &name, T = 0)
61  {
62  T ret = qobject_cast<T>(objectInternal(name, QByteArray(qobject_interface_iid<T>())));
63  Q_ASSERT(ret);
64  return ret;
65  }
66 
77  template<class T>
78  T object(T = 0)
79  {
80  const QByteArray interfaceName(qobject_interface_iid<T>());
81  T ret = qobject_cast<T>(objectInternal(QString::fromUtf8(interfaceName), interfaceName));
82  Q_ASSERT(ret);
83  return ret;
84  }
85 
86  typedef QObject*(*ClientObjectFactoryCallback)(const QString &, QObject *parent);
87 
89  GAMMARAY_COMMON_EXPORT void registerClientObjectFactoryCallbackInternal(const QByteArray &type, ClientObjectFactoryCallback callback);
90 
96  template<class T>
97  void registerClientObjectFactoryCallback(ClientObjectFactoryCallback callback, T = 0)
98  {
99  registerClientObjectFactoryCallbackInternal(QByteArray(qobject_interface_iid<T>()), callback);
100  }
101 
108  GAMMARAY_COMMON_EXPORT void registerModelInternal(const QString &name, QAbstractItemModel* model);
109 
111  GAMMARAY_COMMON_EXPORT QAbstractItemModel* model(const QString &name);
112 
113  typedef QAbstractItemModel*(*ModelFactoryCallback)(const QString &);
114 
116  GAMMARAY_COMMON_EXPORT void setModelFactoryCallback(ModelFactoryCallback callback);
117 
119  GAMMARAY_COMMON_EXPORT void registerSelectionModel(QItemSelectionModel *selectionModel);
121  GAMMARAY_COMMON_EXPORT void unregisterSelectionModel(QItemSelectionModel *selectionModel);
123  GAMMARAY_COMMON_EXPORT bool hasSelectionModel(QAbstractItemModel* model);
124 
126  GAMMARAY_COMMON_EXPORT QItemSelectionModel* selectionModel(QAbstractItemModel *model);
127 
128  typedef QItemSelectionModel*(*selectionModelFactoryCallback)(QAbstractItemModel*);
129 
131  GAMMARAY_COMMON_EXPORT void setSelectionModelFactoryCallback(selectionModelFactoryCallback callback);
132 
134  GAMMARAY_COMMON_EXPORT void clear();
135 }
136 }
137 
138 #endif // GAMMARAY_OBJECTBROKER_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/