Imported Upstream version 1.1.0
[gammaray-debian.git] / objectenummodel.cpp
blob2daecd5d7d2085ea36702ed3e09ea194c72282a3
1 /*
2 objectenummodel.cpp
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 #include "objectenummodel.h"
25 #include <qmetaobject.h>
27 using namespace GammaRay;
29 typedef MetaObjectModel<QMetaEnum,
30 &QMetaObject::enumerator,
31 &QMetaObject::enumeratorCount,
32 &QMetaObject::enumeratorOffset> SuperClass;
34 GammaRay::ObjectEnumModel::ObjectEnumModel(QObject *parent) : SuperClass(parent)
38 int ObjectEnumModel::rowCount(const QModelIndex &parent) const
40 if (!parent.isValid()) {
41 return SuperClass::rowCount(parent);
43 if (parent.parent().isValid()) {
44 return 0;
46 const QMetaEnum e = m_object.data()->metaObject()->enumerator(parent.row());
47 return e.keyCount();
50 int GammaRay::ObjectEnumModel::columnCount(const QModelIndex &parent) const
52 Q_UNUSED(parent);
53 return 3;
56 QVariant ObjectEnumModel::data(const QModelIndex &index, int role) const
58 if (!index.parent().isValid()) {
59 return SuperClass::data(index, role);
62 if (role == Qt::DisplayRole) {
63 const QMetaEnum e = m_object.data()->metaObject()->enumerator(index.parent().row());
64 if (index.column() == 0) {
65 return e.key(index.row());
67 if (index.column() == 1) {
68 return e.value(index.row());
72 return QVariant();
75 QVariant ObjectEnumModel::metaData(const QModelIndex &index,
76 const QMetaEnum &enumerator, int role) const
78 if (role == Qt::DisplayRole) {
79 if (index.column() == 0) {
80 return QString::fromLatin1(enumerator.name());
82 if (index.column() == 1) {
83 return tr("%n element(s)", "", enumerator.keyCount());
86 return QVariant();
89 QString ObjectEnumModel::columnHeader(int index) const
91 switch (index) {
92 case 0:
93 return tr("Name");
94 case 1:
95 return tr("Value");
97 return QString();
100 QModelIndex GammaRay::ObjectEnumModel::index(int row, int column, const QModelIndex &parent) const
102 if (!parent.isValid()) {
103 return SuperClass::index(row, column, parent);
105 return createIndex(row, column, parent.row());
108 QModelIndex GammaRay::ObjectEnumModel::parent(const QModelIndex &child) const
110 if (child.internalId() == -1) {
111 return SuperClass::parent(child);
113 return SuperClass::index(child.internalId(), 0, QModelIndex());