d/control: Recommend gdb
[gammaray-debian.git] / methodinvocationdialog.cpp
blob640c8ad569935ac7a057b682765b4658b43ee0e0
1 /*
2 methodinvocationdialog.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 "methodinvocationdialog.h"
25 #include "methodargumentmodel.h"
26 #include <QMessageBox>
27 #include <QPushButton>
29 using namespace GammaRay;
31 Q_DECLARE_METATYPE(Qt::ConnectionType)
33 MethodInvocationDialog::MethodInvocationDialog(QWidget *parent)
34 : QDialog(parent),
35 m_argumentModel(new MethodArgumentModel(this))
37 setAttribute(Qt::WA_DeleteOnClose);
39 ui.setupUi(this);
41 ui.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Invoke"));
42 connect(ui.buttonBox, SIGNAL(accepted()), SLOT(accept()));
43 connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
45 ui.connectionTypeComboBox->addItem(tr("Auto"), Qt::AutoConnection);
46 ui.connectionTypeComboBox->addItem(tr("Direct"), Qt::DirectConnection);
47 ui.connectionTypeComboBox->addItem(tr("Queued"), Qt::QueuedConnection);
49 ui.argumentView->setModel(m_argumentModel);
52 void MethodInvocationDialog::setMethod(QObject *object, const QMetaMethod &method)
54 m_object = object;
55 m_method = method;
56 m_argumentModel->setMethod(method);
59 void MethodInvocationDialog::accept()
61 if (!m_object) {
62 QMessageBox::warning(this,
63 tr("Invocation Failed"),
64 tr("Invalid object, probably got deleted in the meantime."));
65 QDialog::reject();
66 return;
69 const Qt::ConnectionType connectionType =
70 ui.connectionTypeComboBox->itemData(
71 ui.connectionTypeComboBox->currentIndex()).value<Qt::ConnectionType>();
72 const QVector<SafeArgument> args = m_argumentModel->arguments();
74 const bool result = m_method.invoke(
75 m_object.data(), connectionType,
76 args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
78 if (!result) {
79 QMessageBox::warning(this,
80 tr("Invocation Failed"),
81 tr("Invocation failed, possibly due to mismatching/invalid arguments."));
84 QDialog::accept();
87 #include "methodinvocationdialog.moc"