GammaRay  2.4.0
objectmodelbase.h
Go to the documentation of this file.
1 /*
2  objectmodelbase.h
3 
4  This file is part of GammaRay, the Qt application inspection and
5  manipulation tool.
6 
7  Copyright (C) 2010-2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8  Author: Volker Krause <volker.krause@kdab.com>
9 
10  Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11  accordance with GammaRay Commercial License Agreement provided with the Software.
12 
13  Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 
15  This program is free software; you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 2 of the License, or
18  (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
38 #ifndef GAMMARAY_OBJECTMODELBASE_H
39 #define GAMMARAY_OBJECTMODELBASE_H
40 
41 #include "util.h"
42 #include <common/objectmodel.h>
43 
44 #include <QModelIndex>
45 #include <QObject>
46 
47 namespace GammaRay {
48 
52 template<typename Base>
53 class ObjectModelBase : public Base
54 {
55  public:
60  explicit ObjectModelBase<Base>(QObject *parent) : Base(parent)
61  {
62  }
63 
70  int columnCount(const QModelIndex &parent = QModelIndex()) const
71  {
72  Q_UNUSED(parent);
73  return 2;
74  }
75 
85  QVariant dataForObject(QObject *object, const QModelIndex &index, int role) const
86  {
87  if (role == Qt::DisplayRole) {
88  if (index.column() == 0) {
89  return Util::shortDisplayString(object);
90  } else if (index.column() == 1) {
91  return object->metaObject()->className();
92  }
93  } else if (role == ObjectModel::ObjectRole) {
94  return QVariant::fromValue(object);
95  } else if (role == Qt::ToolTipRole) {
96  return Util::tooltipForObject(object);
97  } else if (role == Qt::DecorationRole && index.column() == 0) {
98  return Util::iconForObject(object);
99  }
100 
101  return QVariant();
102  }
103 
115  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
116  {
117  if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
118  switch (section) {
119  case 0:
120  return QObject::tr("Object");
121  case 1:
122  return QObject::tr("Type");
123  }
124  }
125  return Base::headerData(section, orientation, role);
126  }
127 };
128 
129 }
130 
131 #endif
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: objectmodelbase.h:70
Definition: objectmodel.h:56
QString shortDisplayString(const QObject *object)
A container for a generic Object Model derived from some Base.
Definition: objectmodelbase.h:53
QVariant dataForObject(QObject *object, const QModelIndex &index, int role) const
Definition: objectmodelbase.h:85
Definition: endpoint.h:42
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: objectmodelbase.h:115
Declares various utility methods needed when writing a GammaRay plugin.
QString tooltipForObject(const QObject *object)
Declares the public object model roles.
QVariant iconForObject(const QObject *object)

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/