d/control: Recommend gdb
[gammaray-debian.git] / objectmodelbase.h
blob2bf43e2cdec41a0afd368f6cfa7203bc233797b4
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());
63 } else if (role == Qt::DecorationRole && index.column() == 0) {
64 return Util::iconForObject(obj);
67 return QVariant();
70 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
72 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
73 switch (section) {
74 case 0:
75 return QObject::tr("Object");
76 case 1:
77 return QObject::tr("Type");
80 return Base::headerData(section, orientation, role);
86 #endif