File: clientmethodmodel.cpp

package info (click to toggle)
gammaray 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,620 kB
  • sloc: cpp: 94,712; ansic: 2,227; sh: 336; python: 164; yacc: 90; lex: 82; xml: 61; makefile: 32
file content (119 lines) | stat: -rw-r--r-- 4,284 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
  clientmethodmodel.cpp

  This file is part of GammaRay, the Qt application inspection and manipulation tool.

  SPDX-FileCopyrightText: 2016 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
  Author: Volker Krause <volker.krause@kdab.com>

  SPDX-License-Identifier: GPL-2.0-or-later

  Contact KDAB at <info@kdab.com> for commercial licensing options.
*/

#include "clientmethodmodel.h"

#include <common/metatypedeclarations.h>
#include <common/qmetaobjectvalidatorresult.h>
#include <common/tools/objectinspector/methodmodel.h>

#include <QApplication>
#include <QMetaMethod>
#include <QStyle>

using namespace GammaRay;

ClientMethodModel::ClientMethodModel(QObject *parent)
    : QIdentityProxyModel(parent)
{
}

ClientMethodModel::~ClientMethodModel() = default;

QVariant ClientMethodModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.column() == 1 && role == Qt::DisplayRole) {
        const auto methodType = index.data(ObjectMethodModelRole::MetaMethodType).value<QMetaMethod::MethodType>();
        switch (methodType) {
        case QMetaMethod::Method:
            return tr("Method");
        case QMetaMethod::Constructor:
            return tr("Constructor");
        case QMetaMethod::Slot:
            return tr("Slot");
        case QMetaMethod::Signal:
            return tr("Signal");
        default:
            return tr("Unknown");
        }
    }
    if (index.column() == 2 && role == Qt::DisplayRole) {
        const auto methodAccess = index.data(ObjectMethodModelRole::MethodAccess).value<QMetaMethod::Access>();
        switch (methodAccess) {
        case QMetaMethod::Public:
            return tr("Public");
        case QMetaMethod::Protected:
            return tr("Protected");
        case QMetaMethod::Private:
            return tr("Private");
        default:
            return tr("Unknown");
        }
    }
    if (index.column() != 1 && role == ObjectMethodModelRole::MetaMethodType)
        return index.sibling(index.row(), 1).data(ObjectMethodModelRole::MetaMethodType);
    if (role == Qt::ToolTipRole) {
        const auto idx = index.sibling(index.row(), 0);
        auto tt = idx.data(Qt::DisplayRole).toString();
        const auto tag = idx.data(ObjectMethodModelRole::MethodTag).toString();
        tt += tr("\nTag: %1").arg(tag.isEmpty() ? tr("<none>") : tag);
        const auto rev = idx.data(ObjectMethodModelRole::MethodRevision);
        if (!rev.isNull())
            tt += tr("\nRevision: %1").arg(rev.toInt());

        const auto r = index.data(ObjectMethodModelRole::MethodIssues).value<QMetaObjectValidatorResult::Results>();
        if (r != QMetaObjectValidatorResult::NoIssue) {
            QStringList l;
            if (r & QMetaObjectValidatorResult::SignalOverride)
                l.push_back(tr("overrides base class signal"));
            if (r & QMetaObjectValidatorResult::UnknownMethodParameterType)
                l.push_back(tr("uses parameter type not registered with the meta type system"));
            tt += tr("\nIssues: %1").arg(l.join(QStringLiteral(", ")));
        }
        return tt;
    }
    if (role == ObjectMethodModelRole::MethodSortRole) {
        if (index.column() == 0)
            return index.data(ObjectMethodModelRole::MethodSignature);
        return index.data(Qt::DisplayRole);
    }
    if (role == Qt::DecorationRole && index.column() == 0) {
        const auto r = index.data(ObjectMethodModelRole::MethodIssues).value<QMetaObjectValidatorResult::Results>();
        if (r != QMetaObjectValidatorResult::NoIssue)
            return qApp->style()->standardIcon(QStyle::SP_MessageBoxWarning);
    }

    return QIdentityProxyModel::data(index, role);
}

QVariant ClientMethodModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Horizontal) {
        if (role != Qt::DisplayRole)
            return QVariant();
        switch (section) {
        case 0:
            return tr("Signature");
        case 1:
            return tr("Type");
        case 2:
            return tr("Access");
        case 3:
            return tr("Class");
        }
    }
    return QIdentityProxyModel::headerData(section, orientation, role);
}