Imported Upstream version 1.1.0
[gammaray-debian.git] / tools / scriptenginedebugger / scriptenginedebugger.cpp
blob67e0a9181eb510bc5f06c75f4af4c230d94c8cc0
1 /*
2 scriptenginedebugger.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 "scriptenginedebugger.h"
25 #include "ui_scriptenginedebugger.h"
27 #include <probeinterface.h>
28 #include <objecttypefilterproxymodel.h>
29 #include <singlecolumnobjectproxymodel.h>
31 #include <QtScript/qscriptengine.h>
32 #include <QtScriptTools/QScriptEngineDebugger>
33 #include <QDebug>
34 #include <QMainWindow>
35 #include <QtPlugin>
37 using namespace GammaRay;
39 ///NOTE: for crashes related to script engine debugger on shutdown, see:
40 /// https://bugreports.qt.nokia.com/browse/QTBUG-21548
41 /// Also it seems that we get another crash when the interrupt action
42 /// was triggered and we close the mainwindow.
44 ScriptEngineDebugger::ScriptEngineDebugger(ProbeInterface *probe, QWidget *parent)
45 : QWidget(parent), ui(new Ui::ScriptEngineDebugger), debugger(new QScriptEngineDebugger(this))
47 ui->setupUi(this);
49 ObjectTypeFilterProxyModel<QScriptEngine> *scriptEngineFilter =
50 new ObjectTypeFilterProxyModel<QScriptEngine>(this);
51 scriptEngineFilter->setSourceModel(probe->objectListModel());
52 SingleColumnObjectProxyModel *singleColumnProxy =
53 new SingleColumnObjectProxyModel(this);
54 singleColumnProxy->setSourceModel(scriptEngineFilter);
55 ui->scriptEngineComboBox->setModel(singleColumnProxy);
56 connect(ui->scriptEngineComboBox, SIGNAL(activated(int)), SLOT(scriptEngineSelected(int)));
58 ui->verticalLayout_10->addWidget(debugger->standardWindow());
60 if (ui->scriptEngineComboBox->count()) {
61 scriptEngineSelected(0);
65 ScriptEngineDebugger::~ScriptEngineDebugger()
67 debugger->detach();
70 void ScriptEngineDebugger::scriptEngineSelected(int index)
72 QObject *obj =
73 ui->scriptEngineComboBox->itemData(index, ObjectModel::ObjectRole).value<QObject*>();
74 QScriptEngine *engine = qobject_cast<QScriptEngine*>(obj);
75 if (engine) {
76 debugger->attachTo(engine);
77 // FIXME: if we'd do that, we'd get crashes on shutdown.
78 // debugger->action(QScriptEngineDebugger::InterruptAction)->trigger();
82 Q_EXPORT_PLUGIN(ScriptEngineDebuggerFactory)
84 #include "scriptenginedebugger.moc"