1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "invokemethod.h"
|
---|
43 |
|
---|
44 | #include <qt_windows.h>
|
---|
45 | #include <ActiveQt/ActiveQt>
|
---|
46 |
|
---|
47 | QT_BEGIN_NAMESPACE
|
---|
48 |
|
---|
49 | InvokeMethod::InvokeMethod(QWidget *parent)
|
---|
50 | : QDialog(parent), activex(0)
|
---|
51 | {
|
---|
52 | setupUi(this);
|
---|
53 |
|
---|
54 | listParameters->setColumnCount(3);
|
---|
55 | listParameters->headerItem()->setText(0, tr("Parameter"));
|
---|
56 | listParameters->headerItem()->setText(1, tr("Type"));
|
---|
57 | listParameters->headerItem()->setText(2, tr("Value"));
|
---|
58 | }
|
---|
59 |
|
---|
60 | void InvokeMethod::setControl(QAxBase *ax)
|
---|
61 | {
|
---|
62 | activex = ax;
|
---|
63 | bool hasControl = activex && !activex->isNull();
|
---|
64 | labelMethods->setEnabled(hasControl);
|
---|
65 | comboMethods->setEnabled(hasControl);
|
---|
66 | buttonInvoke->setEnabled(hasControl);
|
---|
67 | boxParameters->setEnabled(hasControl);
|
---|
68 |
|
---|
69 | comboMethods->clear();
|
---|
70 | listParameters->clear();
|
---|
71 |
|
---|
72 | if (!hasControl) {
|
---|
73 | editValue->clear();
|
---|
74 | return;
|
---|
75 | }
|
---|
76 |
|
---|
77 | const QMetaObject *mo = activex->metaObject();
|
---|
78 | if (mo->methodCount()) {
|
---|
79 | for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
|
---|
80 | const QMetaMethod method = mo->method(i);
|
---|
81 | if (method.methodType() == QMetaMethod::Slot)
|
---|
82 | comboMethods->addItem(QString::fromLatin1(method.signature()));
|
---|
83 | }
|
---|
84 | comboMethods->model()->sort(0);
|
---|
85 |
|
---|
86 | on_comboMethods_activated(comboMethods->currentText());
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | void InvokeMethod::on_buttonInvoke_clicked()
|
---|
91 | {
|
---|
92 | if (!activex)
|
---|
93 | return;
|
---|
94 |
|
---|
95 | on_buttonSet_clicked();
|
---|
96 | QString method = comboMethods->currentText();
|
---|
97 | QList<QVariant> vars;
|
---|
98 |
|
---|
99 | int itemCount = listParameters->topLevelItemCount();
|
---|
100 | for (int i = 0; i < itemCount; ++i) {
|
---|
101 | QTreeWidgetItem *parameter = listParameters->topLevelItem(i);
|
---|
102 | vars << parameter->text(2);
|
---|
103 | }
|
---|
104 | QVariant result = activex->dynamicCall(method.toLatin1(), vars);
|
---|
105 |
|
---|
106 | int v = 0;
|
---|
107 | for (int i = 0; i < itemCount; ++i) {
|
---|
108 | QTreeWidgetItem *parameter = listParameters->topLevelItem(i);
|
---|
109 | parameter->setText(2, vars[v++].toString());
|
---|
110 | }
|
---|
111 |
|
---|
112 | QString resString = result.toString();
|
---|
113 | QString resType = QString::fromLatin1(result.typeName());
|
---|
114 | editReturn->setText(resType + QLatin1String(" ") + resString);
|
---|
115 | }
|
---|
116 |
|
---|
117 | void InvokeMethod::on_comboMethods_activated(const QString &method)
|
---|
118 | {
|
---|
119 | if (!activex)
|
---|
120 | return;
|
---|
121 | listParameters->clear();
|
---|
122 |
|
---|
123 | const QMetaObject *mo = activex->metaObject();
|
---|
124 | const QMetaMethod slot = mo->method(mo->indexOfSlot(method.toLatin1()));
|
---|
125 | QString signature = QString::fromLatin1(slot.signature());
|
---|
126 | signature = signature.mid(signature.indexOf(QLatin1Char('(')) + 1);
|
---|
127 | signature.truncate(signature.length()-1);
|
---|
128 |
|
---|
129 | QList<QByteArray> pnames = slot.parameterNames();
|
---|
130 | QList<QByteArray> ptypes = slot.parameterTypes();
|
---|
131 |
|
---|
132 | for (int p = 0; p < ptypes.count(); ++p) {
|
---|
133 | QString ptype(QString::fromLatin1(ptypes.at(p)));
|
---|
134 | if (ptype.isEmpty())
|
---|
135 | continue;
|
---|
136 | QString pname(QString::fromLatin1(pnames.at(p).constData()));
|
---|
137 | if (pname.isEmpty())
|
---|
138 | pname = QString::fromLatin1("<unnamed %1>").arg(p);
|
---|
139 | QTreeWidgetItem *item = new QTreeWidgetItem(listParameters);
|
---|
140 | item->setText(0, pname);
|
---|
141 | item->setText(1, ptype);
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (listParameters->topLevelItemCount())
|
---|
145 | listParameters->setCurrentItem(listParameters->topLevelItem(0));
|
---|
146 | editReturn->setText(QString::fromLatin1(slot.typeName()));
|
---|
147 | }
|
---|
148 |
|
---|
149 | void InvokeMethod::on_listParameters_currentItemChanged(QTreeWidgetItem *item)
|
---|
150 | {
|
---|
151 | if (!activex)
|
---|
152 | return;
|
---|
153 | editValue->setEnabled(item != 0);
|
---|
154 | buttonSet->setEnabled(item != 0);
|
---|
155 | if (!item)
|
---|
156 | return;
|
---|
157 | editValue->setText(item->text(2));
|
---|
158 | }
|
---|
159 |
|
---|
160 | void InvokeMethod::on_buttonSet_clicked()
|
---|
161 | {
|
---|
162 | if (!activex)
|
---|
163 | return;
|
---|
164 | QTreeWidgetItem *item = listParameters->currentItem();
|
---|
165 | if (!item)
|
---|
166 | return;
|
---|
167 | item->setText(2, editValue->text());
|
---|
168 | }
|
---|
169 |
|
---|
170 | QT_END_NAMESPACE
|
---|