Find QtWebKit headers
[gammaray-debian.git] / objectmodelbase.h
bloba6aee7fe3b4d0a34f01f30479aaa2b781d884c17
1 /*
2 objectmodelbase.h
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
7 Copyright (C) 2010-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 #ifndef GAMMARAY_OBJECTMODELBASE_H
25 #define GAMMARAY_OBJECTMODELBASE_H
27 #include "util.h"
28 #include "objectmodel.h"
30 #include <QObject>
31 #include <QModelIndex>
33 namespace GammaRay {
35 template<typename Base>
36 class ObjectModelBase : public Base
38 public:
39 explicit ObjectModelBase<Base>(QObject *parent) : Base(parent) {}
41 int columnCount(const QModelIndex &parent = QModelIndex()) const
43 Q_UNUSED(parent);
44 return 2;
47 QVariant dataForObject(QObject *obj, const QModelIndex &index, int role) const
49 if (role == Qt::DisplayRole) {
50 if (index.column() == 0) {
51 return obj->objectName().isEmpty() ? Util::addressToString(obj) : obj->objectName();
52 } else if (index.column() == 1) {
53 return obj->metaObject()->className();
55 } else if (role == ObjectModel::ObjectRole) {
56 return QVariant::fromValue(obj);
57 } else if (role == Qt::ToolTipRole) {
58 return QString("Object name: %1\nParent: %2 (Address: %3)\nNumber of children: %4").
59 arg(obj->objectName().isEmpty() ? "<Not set>" : obj->objectName()).
60 arg(obj->parent() ? obj->parent()->metaObject()->className() : "<No parent>").
61 arg(Util::addressToString(obj->parent())).
62 arg(obj->children().size());
65 return QVariant();
68 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
70 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
71 switch (section) {
72 case 0:
73 return QObject::tr("Object");
74 case 1:
75 return QObject::tr("Type");
78 return Base::headerData(section, orientation, role);
84 #endif