1
/*****************************************************************
2
* Unipro UGENE - Integrated Bioinformatics Suite
3
* Copyright (C) 2008 Unipro, Russia (http://ugene.unipro.ru)
6
* This source code is distributed under the terms of the
7
* GNU General Public License. See the files COPYING and LICENSE
9
*****************************************************************/
11
#include <QtScript/QScriptEngine>
12
#include <QtScript/QScriptContext>
13
#include <QtScript/QScriptValue>
14
#include <QtCore/QStringList>
15
#include <QtCore/QDebug>
16
#include <qmetaobject.h>
18
#include <qcompleter.h>
20
#include <qabstractitemmodel.h>
21
#include <qabstractitemview.h>
22
#include <qbytearray.h>
23
#include <qcompleter.h>
24
#include <qcoreevent.h>
28
#include <qstringlist.h>
31
#include "qtscriptshell_QCompleter.h"
33
static const char * const qtscript_QCompleter_function_names[] = {
54
static const char * const qtscript_QCompleter_function_signatures[] = {
55
"QAbstractItemModel model, QObject parent\nQObject parent\nList completions, QObject parent"
67
, "QAbstractItemModel c"
68
, "QAbstractItemView popup"
75
static QScriptValue qtscript_QCompleter_throw_ambiguity_error_helper(
76
QScriptContext *context, const char *functionName, const char *signatures)
78
QStringList lines = QString::fromLatin1(signatures).split(QLatin1Char('\n'));
79
QStringList fullSignatures;
80
for (int i = 0; i < lines.size(); ++i)
81
fullSignatures.append(QString::fromLatin1("%0(%1)").arg(functionName).arg(lines.at(i)));
82
return context->throwError(QString::fromLatin1("QFile::%0(): could not find a function match; candidates are:\n%1")
83
.arg(functionName).arg(fullSignatures.join(QLatin1String("\n"))));
86
Q_DECLARE_METATYPE(QCompleter*)
87
Q_DECLARE_METATYPE(QtScriptShell_QCompleter*)
88
Q_DECLARE_METATYPE(QCompleter::ModelSorting)
89
Q_DECLARE_METATYPE(QCompleter::CompletionMode)
90
Q_DECLARE_METATYPE(QAbstractItemModel*)
91
Q_DECLARE_METATYPE(QModelIndex)
92
Q_DECLARE_METATYPE(QAbstractItemView*)
94
static QScriptValue qtscript_create_enum_class_helper(
95
QScriptEngine *engine,
96
QScriptEngine::FunctionSignature construct,
97
QScriptEngine::FunctionSignature valueOf,
98
QScriptEngine::FunctionSignature toString)
100
QScriptValue proto = engine->newObject();
101
proto.setProperty(QString::fromLatin1("valueOf"),
102
engine->newFunction(valueOf), QScriptValue::SkipInEnumeration);
103
proto.setProperty(QString::fromLatin1("toString"),
104
engine->newFunction(toString), QScriptValue::SkipInEnumeration);
105
return engine->newFunction(construct, proto, 1);
109
// QCompleter::ModelSorting
112
static const QCompleter::ModelSorting qtscript_QCompleter_ModelSorting_values[] = {
113
QCompleter::UnsortedModel
114
, QCompleter::CaseSensitivelySortedModel
115
, QCompleter::CaseInsensitivelySortedModel
118
static const char * const qtscript_QCompleter_ModelSorting_keys[] = {
120
, "CaseSensitivelySortedModel"
121
, "CaseInsensitivelySortedModel"
124
static QString qtscript_QCompleter_ModelSorting_toStringHelper(QCompleter::ModelSorting value)
126
if ((value >= QCompleter::UnsortedModel) && (value <= QCompleter::CaseInsensitivelySortedModel))
127
return qtscript_QCompleter_ModelSorting_keys[static_cast<int>(value)];
131
static QScriptValue qtscript_QCompleter_ModelSorting_toScriptValue(QScriptEngine *engine, const QCompleter::ModelSorting &value)
133
QScriptValue clazz = engine->globalObject().property(QString::fromLatin1("QCompleter"));
134
return clazz.property(qtscript_QCompleter_ModelSorting_toStringHelper(value));
137
static void qtscript_QCompleter_ModelSorting_fromScriptValue(const QScriptValue &value, QCompleter::ModelSorting &out)
139
out = qvariant_cast<QCompleter::ModelSorting>(value.toVariant());
142
static QScriptValue qtscript_construct_QCompleter_ModelSorting(QScriptContext *context, QScriptEngine *engine)
144
int arg = context->argument(0).toInt32();
145
if ((arg >= QCompleter::UnsortedModel) && (arg <= QCompleter::CaseInsensitivelySortedModel))
146
return qScriptValueFromValue(engine, static_cast<QCompleter::ModelSorting>(arg));
147
return context->throwError(QString::fromLatin1("ModelSorting(): invalid enum value (%0)").arg(arg));
150
static QScriptValue qtscript_QCompleter_ModelSorting_valueOf(QScriptContext *context, QScriptEngine *engine)
152
QCompleter::ModelSorting value = qscriptvalue_cast<QCompleter::ModelSorting>(context->thisObject());
153
return QScriptValue(engine, static_cast<int>(value));
156
static QScriptValue qtscript_QCompleter_ModelSorting_toString(QScriptContext *context, QScriptEngine *engine)
158
QCompleter::ModelSorting value = qscriptvalue_cast<QCompleter::ModelSorting>(context->thisObject());
159
return QScriptValue(engine, qtscript_QCompleter_ModelSorting_toStringHelper(value));
162
static QScriptValue qtscript_create_QCompleter_ModelSorting_class(QScriptEngine *engine, QScriptValue &clazz)
164
QScriptValue ctor = qtscript_create_enum_class_helper(
165
engine, qtscript_construct_QCompleter_ModelSorting,
166
qtscript_QCompleter_ModelSorting_valueOf, qtscript_QCompleter_ModelSorting_toString);
167
qScriptRegisterMetaType<QCompleter::ModelSorting>(engine, qtscript_QCompleter_ModelSorting_toScriptValue,
168
qtscript_QCompleter_ModelSorting_fromScriptValue, ctor.property(QString::fromLatin1("prototype")));
169
for (int i = 0; i < 3; ++i) {
170
clazz.setProperty(QString::fromLatin1(qtscript_QCompleter_ModelSorting_keys[i]),
171
engine->newVariant(qVariantFromValue(qtscript_QCompleter_ModelSorting_values[i])),
172
QScriptValue::ReadOnly | QScriptValue::Undeletable);
178
// QCompleter::CompletionMode
181
static const QCompleter::CompletionMode qtscript_QCompleter_CompletionMode_values[] = {
182
QCompleter::PopupCompletion
183
, QCompleter::UnfilteredPopupCompletion
184
, QCompleter::InlineCompletion
187
static const char * const qtscript_QCompleter_CompletionMode_keys[] = {
189
, "UnfilteredPopupCompletion"
193
static QString qtscript_QCompleter_CompletionMode_toStringHelper(QCompleter::CompletionMode value)
195
if ((value >= QCompleter::PopupCompletion) && (value <= QCompleter::InlineCompletion))
196
return qtscript_QCompleter_CompletionMode_keys[static_cast<int>(value)];
200
static QScriptValue qtscript_QCompleter_CompletionMode_toScriptValue(QScriptEngine *engine, const QCompleter::CompletionMode &value)
202
QScriptValue clazz = engine->globalObject().property(QString::fromLatin1("QCompleter"));
203
return clazz.property(qtscript_QCompleter_CompletionMode_toStringHelper(value));
206
static void qtscript_QCompleter_CompletionMode_fromScriptValue(const QScriptValue &value, QCompleter::CompletionMode &out)
208
out = qvariant_cast<QCompleter::CompletionMode>(value.toVariant());
211
static QScriptValue qtscript_construct_QCompleter_CompletionMode(QScriptContext *context, QScriptEngine *engine)
213
int arg = context->argument(0).toInt32();
214
if ((arg >= QCompleter::PopupCompletion) && (arg <= QCompleter::InlineCompletion))
215
return qScriptValueFromValue(engine, static_cast<QCompleter::CompletionMode>(arg));
216
return context->throwError(QString::fromLatin1("CompletionMode(): invalid enum value (%0)").arg(arg));
219
static QScriptValue qtscript_QCompleter_CompletionMode_valueOf(QScriptContext *context, QScriptEngine *engine)
221
QCompleter::CompletionMode value = qscriptvalue_cast<QCompleter::CompletionMode>(context->thisObject());
222
return QScriptValue(engine, static_cast<int>(value));
225
static QScriptValue qtscript_QCompleter_CompletionMode_toString(QScriptContext *context, QScriptEngine *engine)
227
QCompleter::CompletionMode value = qscriptvalue_cast<QCompleter::CompletionMode>(context->thisObject());
228
return QScriptValue(engine, qtscript_QCompleter_CompletionMode_toStringHelper(value));
231
static QScriptValue qtscript_create_QCompleter_CompletionMode_class(QScriptEngine *engine, QScriptValue &clazz)
233
QScriptValue ctor = qtscript_create_enum_class_helper(
234
engine, qtscript_construct_QCompleter_CompletionMode,
235
qtscript_QCompleter_CompletionMode_valueOf, qtscript_QCompleter_CompletionMode_toString);
236
qScriptRegisterMetaType<QCompleter::CompletionMode>(engine, qtscript_QCompleter_CompletionMode_toScriptValue,
237
qtscript_QCompleter_CompletionMode_fromScriptValue, ctor.property(QString::fromLatin1("prototype")));
238
for (int i = 0; i < 3; ++i) {
239
clazz.setProperty(QString::fromLatin1(qtscript_QCompleter_CompletionMode_keys[i]),
240
engine->newVariant(qVariantFromValue(qtscript_QCompleter_CompletionMode_values[i])),
241
QScriptValue::ReadOnly | QScriptValue::Undeletable);
250
static QScriptValue qtscript_QCompleter_prototype_call(QScriptContext *context, QScriptEngine *)
252
#if QT_VERSION > 0x040400
253
Q_ASSERT(context->callee().isFunction());
254
uint _id = context->callee().data().toUInt32();
257
if (context->callee().isFunction())
258
_id = context->callee().data().toUInt32();
260
_id = 0xBABE0000 + 14;
262
Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
264
QCompleter* _q_self = qscriptvalue_cast<QCompleter*>(context->thisObject());
266
return context->throwError(QScriptContext::TypeError,
267
QString::fromLatin1("QCompleter.%0(): this object is not a QCompleter")
268
.arg(qtscript_QCompleter_function_names[_id+1]));
273
if (context->argumentCount() == 0) {
274
int _q_result = _q_self->completionCount();
275
return QScriptValue(context->engine(), _q_result);
280
if (context->argumentCount() == 0) {
281
QAbstractItemModel* _q_result = _q_self->completionModel();
282
return qScriptValueFromValue(context->engine(), _q_result);
287
if (context->argumentCount() == 0) {
288
QString _q_result = _q_self->currentCompletion();
289
return QScriptValue(context->engine(), _q_result);
294
if (context->argumentCount() == 0) {
295
QModelIndex _q_result = _q_self->currentIndex();
296
return qScriptValueFromValue(context->engine(), _q_result);
301
if (context->argumentCount() == 0) {
302
int _q_result = _q_self->currentRow();
303
return QScriptValue(context->engine(), _q_result);
308
if (context->argumentCount() == 0) {
309
QAbstractItemModel* _q_result = _q_self->model();
310
return qScriptValueFromValue(context->engine(), _q_result);
315
if (context->argumentCount() == 1) {
316
QModelIndex _q_arg0 = qscriptvalue_cast<QModelIndex>(context->argument(0));
317
QString _q_result = _q_self->pathFromIndex(_q_arg0);
318
return QScriptValue(context->engine(), _q_result);
323
if (context->argumentCount() == 0) {
324
QAbstractItemView* _q_result = _q_self->popup();
325
return qScriptValueFromValue(context->engine(), _q_result);
330
if (context->argumentCount() == 1) {
331
int _q_arg0 = context->argument(0).toInt32();
332
bool _q_result = _q_self->setCurrentRow(_q_arg0);
333
return QScriptValue(context->engine(), _q_result);
338
if (context->argumentCount() == 1) {
339
QAbstractItemModel* _q_arg0 = qscriptvalue_cast<QAbstractItemModel*>(context->argument(0));
340
_q_self->setModel(_q_arg0);
341
return context->engine()->undefinedValue();
346
if (context->argumentCount() == 1) {
347
QAbstractItemView* _q_arg0 = qscriptvalue_cast<QAbstractItemView*>(context->argument(0));
348
_q_self->setPopup(_q_arg0);
349
return context->engine()->undefinedValue();
354
if (context->argumentCount() == 1) {
355
QWidget* _q_arg0 = qscriptvalue_cast<QWidget*>(context->argument(0));
356
_q_self->setWidget(_q_arg0);
357
return context->engine()->undefinedValue();
362
if (context->argumentCount() == 1) {
363
QString _q_arg0 = context->argument(0).toString();
364
QStringList _q_result = _q_self->splitPath(_q_arg0);
365
return qScriptValueFromSequence(context->engine(), _q_result);
370
if (context->argumentCount() == 0) {
371
QWidget* _q_result = _q_self->widget();
372
return qScriptValueFromValue(context->engine(), _q_result);
377
QString result = QString::fromLatin1("QCompleter");
378
return QScriptValue(context->engine(), result);
384
return qtscript_QCompleter_throw_ambiguity_error_helper(context,
385
qtscript_QCompleter_function_names[_id+1],
386
qtscript_QCompleter_function_signatures[_id+1]);
389
static QScriptValue qtscript_QCompleter_static_call(QScriptContext *context, QScriptEngine *)
391
uint _id = context->callee().data().toUInt32();
392
Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
396
if (context->thisObject().strictlyEquals(context->engine()->globalObject())) {
397
return context->throwError(QString::fromLatin1("QCompleter(): Did you forget to construct with 'new'?"));
399
if (context->argumentCount() == 0) {
400
QtScriptShell_QCompleter* _q_cpp_result = new QtScriptShell_QCompleter();
401
QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QCompleter*)_q_cpp_result, QScriptEngine::AutoOwnership);
402
_q_cpp_result->__qtscript_self = _q_result;
404
} else if (context->argumentCount() == 1) {
405
if (qscriptvalue_cast<QAbstractItemModel*>(context->argument(0))) {
406
QAbstractItemModel* _q_arg0 = qscriptvalue_cast<QAbstractItemModel*>(context->argument(0));
407
QtScriptShell_QCompleter* _q_cpp_result = new QtScriptShell_QCompleter(_q_arg0);
408
QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QCompleter*)_q_cpp_result, QScriptEngine::AutoOwnership);
409
_q_cpp_result->__qtscript_self = _q_result;
411
} else if (context->argument(0).isQObject()) {
412
QObject* _q_arg0 = context->argument(0).toQObject();
413
QtScriptShell_QCompleter* _q_cpp_result = new QtScriptShell_QCompleter(_q_arg0);
414
QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QCompleter*)_q_cpp_result, QScriptEngine::AutoOwnership);
415
_q_cpp_result->__qtscript_self = _q_result;
417
} else if (context->argument(0).isArray()) {
419
qScriptValueToSequence(context->argument(0), _q_arg0);
420
QtScriptShell_QCompleter* _q_cpp_result = new QtScriptShell_QCompleter(_q_arg0);
421
QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QCompleter*)_q_cpp_result, QScriptEngine::AutoOwnership);
422
_q_cpp_result->__qtscript_self = _q_result;
425
} else if (context->argumentCount() == 2) {
426
if (qscriptvalue_cast<QAbstractItemModel*>(context->argument(0))
427
&& context->argument(1).isQObject()) {
428
QAbstractItemModel* _q_arg0 = qscriptvalue_cast<QAbstractItemModel*>(context->argument(0));
429
QObject* _q_arg1 = context->argument(1).toQObject();
430
QtScriptShell_QCompleter* _q_cpp_result = new QtScriptShell_QCompleter(_q_arg0, _q_arg1);
431
QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QCompleter*)_q_cpp_result, QScriptEngine::AutoOwnership);
432
_q_cpp_result->__qtscript_self = _q_result;
434
} else if (context->argument(0).isArray()
435
&& context->argument(1).isQObject()) {
437
qScriptValueToSequence(context->argument(0), _q_arg0);
438
QObject* _q_arg1 = context->argument(1).toQObject();
439
QtScriptShell_QCompleter* _q_cpp_result = new QtScriptShell_QCompleter(_q_arg0, _q_arg1);
440
QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QCompleter*)_q_cpp_result, QScriptEngine::AutoOwnership);
441
_q_cpp_result->__qtscript_self = _q_result;
450
return qtscript_QCompleter_throw_ambiguity_error_helper(context,
451
qtscript_QCompleter_function_names[_id],
452
qtscript_QCompleter_function_signatures[_id]);
455
static QScriptValue qtscript_QCompleter_toScriptValue(QScriptEngine *engine, QCompleter* const &in)
457
return engine->newQObject(in, QScriptEngine::QtOwnership, QScriptEngine::PreferExistingWrapperObject);
460
static void qtscript_QCompleter_fromScriptValue(const QScriptValue &value, QCompleter* &out)
462
out = qobject_cast<QCompleter*>(value.toQObject());
465
QScriptValue qtscript_create_QCompleter_class(QScriptEngine *engine)
467
static const int function_lengths[] = {
487
engine->setDefaultPrototype(qMetaTypeId<QCompleter*>(), QScriptValue());
488
QScriptValue proto = engine->newVariant(qVariantFromValue((QCompleter*)0));
489
proto.setPrototype(engine->defaultPrototype(qMetaTypeId<QObject*>()));
490
for (int i = 0; i < 15; ++i) {
491
QScriptValue fun = engine->newFunction(qtscript_QCompleter_prototype_call, function_lengths[i+1]);
492
fun.setData(QScriptValue(engine, uint(0xBABE0000 + i)));
493
proto.setProperty(QString::fromLatin1(qtscript_QCompleter_function_names[i+1]),
494
fun, QScriptValue::SkipInEnumeration);
497
qScriptRegisterMetaType<QCompleter*>(engine, qtscript_QCompleter_toScriptValue,
498
qtscript_QCompleter_fromScriptValue, proto);
500
QScriptValue ctor = engine->newFunction(qtscript_QCompleter_static_call, proto, function_lengths[0]);
501
ctor.setData(QScriptValue(engine, uint(0xBABE0000 + 0)));
503
ctor.setProperty(QString::fromLatin1("ModelSorting"),
504
qtscript_create_QCompleter_ModelSorting_class(engine, ctor));
505
ctor.setProperty(QString::fromLatin1("CompletionMode"),
506
qtscript_create_QCompleter_CompletionMode_class(engine, ctor));