forked from KDAB/GammaRay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
propertywidget.cpp
205 lines (173 loc) · 7.33 KB
/
propertywidget.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
propertywidget.cpp
This file is part of GammaRay, the Qt application inspection and
manipulation tool.
Copyright (C) 2010-2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Volker Krause <volker.krause@kdab.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "propertywidget.h"
#include "objectstaticpropertymodel.h"
#include "objectdynamicpropertymodel.h"
#include "objectclassinfomodel.h"
#include "objectmethodmodel.h"
#include "objectenummodel.h"
#include "metapropertymodel.h"
#include "connectionmodel.h"
#include "connectionfilterproxymodel.h"
#include "probe.h"
#include "methodinvocationdialog.h"
#include "multisignalmapper.h"
#include "proxydetacher.h"
#include "kde/krecursivefilterproxymodel.h"
#include <QDebug>
#include <QStandardItemModel>
#include <QtCore/QTime>
#include <qmenu.h>
using namespace GammaRay;
PropertyWidget::PropertyWidget(QWidget *parent)
: QWidget(parent),
m_staticPropertyModel(new ObjectStaticPropertyModel(this)),
m_dynamicPropertyModel(new ObjectDynamicPropertyModel(this)),
m_classInfoModel(new ObjectClassInfoModel(this)),
m_methodModel(new ObjectMethodModel(this)),
m_inboundConnectionModel(new ConnectionFilterProxyModel(this)),
m_outboundConnectionModel(new ConnectionFilterProxyModel(this)),
m_enumModel(new ObjectEnumModel(this)),
m_signalMapper(0),
m_methodLogModel(new QStandardItemModel(this)),
m_metaPropertyModel(new MetaPropertyModel(this))
{
ui.setupUi(this);
QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
proxy->setDynamicSortFilter(true);
proxy->setSourceModel(m_staticPropertyModel);
ui.staticPropertyView->setModel(proxy);
ui.staticPropertyView->sortByColumn(0, Qt::AscendingOrder);
ui.staticPropertyView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
ui.staticPropertySearchLine->setProxy(proxy);
proxy = new QSortFilterProxyModel(this);
proxy->setDynamicSortFilter(true);
proxy->setSourceModel(m_dynamicPropertyModel);
ui.dynamicPropertyView->setModel(proxy);
ui.dynamicPropertyView->sortByColumn(0, Qt::AscendingOrder);
ui.dynamicPropertyView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
ui.dynamicPropertySearchLine->setProxy(proxy);
proxy = new QSortFilterProxyModel(this);
proxy->setDynamicSortFilter(true);
proxy->setSourceModel(m_methodModel);
ui.methodView->setModel(proxy);
ui.methodView->sortByColumn(0, Qt::AscendingOrder);
ui.methodView->header()->setResizeMode(QHeaderView::ResizeToContents);
ui.methodSearchLine->setProxy(proxy);
connect(ui.methodView, SIGNAL(doubleClicked(QModelIndex)),
SLOT(methodActivated(QModelIndex)));
connect(ui.methodView, SIGNAL(customContextMenuRequested(QPoint)),
SLOT(methodConextMenu(QPoint)));
ui.methodLog->setModel(m_methodLogModel);
proxy = new QSortFilterProxyModel(this);
proxy->setDynamicSortFilter(true);
proxy->setSourceModel(m_classInfoModel);
ui.classInfoView->setModel(proxy);
ui.classInfoView->sortByColumn(0, Qt::AscendingOrder);
ui.classInfoView->header()->setResizeMode(QHeaderView::ResizeToContents);
ui.classInfoSearchLine->setProxy(proxy);
new ProxyDetacher(ui.inboundConnectionView, m_inboundConnectionModel,
Probe::instance()->connectionModel());
ui.inboundConnectionView->setModel(m_inboundConnectionModel);
ui.inboundConnectionView->sortByColumn(0, Qt::AscendingOrder);
ui.inboundConnectionSearchLine->setProxy(m_inboundConnectionModel);
new ProxyDetacher(ui.outboundConnectionView, m_outboundConnectionModel,
Probe::instance()->connectionModel());
ui.outboundConnectionView->setModel(m_outboundConnectionModel);
ui.outboundConnectionView->sortByColumn(0, Qt::AscendingOrder);
ui.outboundConnectionSearchLine->setProxy(m_outboundConnectionModel);
proxy = new KRecursiveFilterProxyModel(this);
proxy->setDynamicSortFilter(true);
proxy->setSourceModel(m_enumModel);
ui.enumView->setModel(proxy);
ui.enumView->sortByColumn(0, Qt::AscendingOrder);
ui.enumView->header()->setResizeMode(QHeaderView::ResizeToContents);
ui.enumSearchLine->setProxy(proxy);
ui.metaPropertyView->setModel(m_metaPropertyModel);
}
void GammaRay::PropertyWidget::setObject(QObject *object)
{
m_object = object;
m_staticPropertyModel->setObject(object);
m_dynamicPropertyModel->setObject(object);
m_classInfoModel->setObject(object);
m_methodModel->setObject(object);
m_inboundConnectionModel->filterReceiver(object);
m_outboundConnectionModel->filterSender(object);
m_enumModel->setObject(object);
delete m_signalMapper;
m_signalMapper = new MultiSignalMapper(this);
connect(m_signalMapper, SIGNAL(signalEmitted(QObject*,int)), SLOT(signalEmitted(QObject*,int)));
m_methodLogModel->clear();
m_metaPropertyModel->setObject(object);
setQObjectTabsVisible(true);
}
void PropertyWidget::setObject(void *object, const QString &className)
{
setObject(0);
m_metaPropertyModel->setObject(object, className);
setQObjectTabsVisible(false);
}
void GammaRay::PropertyWidget::methodActivated(const QModelIndex &index)
{
const QMetaMethod method = index.data(ObjectMethodModel::MetaMethodRole).value<QMetaMethod>();
if (method.methodType() == QMetaMethod::Slot) {
MethodInvocationDialog *dlg = new MethodInvocationDialog(this);
dlg->setMethod(m_object.data(), method);
dlg->show();
// TODO: return value should go into ui->methodLog
} else if (method.methodType() == QMetaMethod::Signal) {
m_signalMapper->connectToSignal(m_object, method);
}
}
void PropertyWidget::signalEmitted(QObject *sender, int signalIndex)
{
Q_ASSERT(m_object == sender);
m_methodLogModel->appendRow(
new QStandardItem(tr("%1: Signal %2 emitted").
arg(QTime::currentTime().toString("HH:mm:ss.zzz")).
arg(sender->metaObject()->method(signalIndex).signature())));
}
void PropertyWidget::methodConextMenu(const QPoint &pos)
{
const QModelIndex index = ui.methodView->indexAt(pos);
if (!index.isValid()) {
return;
}
const QMetaMethod method = index.data(ObjectMethodModel::MetaMethodRole).value<QMetaMethod>();
QMenu contextMenu;
if (method.methodType() == QMetaMethod::Slot) {
contextMenu.addAction(tr("Invoke"));
} else if (method.methodType() == QMetaMethod::Signal) {
contextMenu.addAction(tr("Connect to"));
}
if (contextMenu.exec(ui.methodView->viewport()->mapToGlobal(pos))) {
methodActivated(index);
}
}
void PropertyWidget::setQObjectTabsVisible(bool visible)
{
// TODO: this should actually hide instead of disable...
for (int i = 0; i < ui.tabWidget->count(); ++i) {
if (ui.tabWidget->widget(i) != ui.metaPropertyTab)
ui.tabWidget->setTabEnabled(i, visible);
}
if (!visible)
ui.tabWidget->setCurrentWidget(ui.metaPropertyTab);
}
#include "propertywidget.moc"