~ubuntu-branches/ubuntu/karmic/ugene/karmic

« back to all changes in this revision

Viewing changes to src/libs_3rdparty/qtbindings_gui/src/qtscript_QItemDelegate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ivan Efremov
  • Date: 2009-01-26 19:17:51 UTC
  • Revision ID: james.westby@ubuntu.com-20090126191751-9kqqevd3yf4o098r
Tags: upstream-1.3.2+repack
ImportĀ upstreamĀ versionĀ 1.3.2+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
* Unipro UGENE - Integrated Bioinformatics Suite
 
3
* Copyright (C) 2008 Unipro, Russia (http://ugene.unipro.ru)
 
4
* All Rights Reserved
 
5
 
6
*     This source code is distributed under the terms of the
 
7
*     GNU General Public License. See the files COPYING and LICENSE
 
8
*     for details.
 
9
*****************************************************************/
 
10
 
 
11
#include <QtScript/QScriptEngine>
 
12
#include <QtScript/QScriptContext>
 
13
#include <QtScript/QScriptValue>
 
14
#include <QtCore/QStringList>
 
15
#include <QtCore/QDebug>
 
16
#include <qmetaobject.h>
 
17
 
 
18
#include <qitemdelegate.h>
 
19
#include <QVariant>
 
20
#include <qabstractitemmodel.h>
 
21
#include <qabstractitemview.h>
 
22
#include <qbytearray.h>
 
23
#include <qcoreevent.h>
 
24
#include <qevent.h>
 
25
#include <qfont.h>
 
26
#include <qitemdelegate.h>
 
27
#include <qitemeditorfactory.h>
 
28
#include <qlist.h>
 
29
#include <qobject.h>
 
30
#include <qpainter.h>
 
31
#include <qpixmap.h>
 
32
#include <qrect.h>
 
33
#include <qsize.h>
 
34
#include <qstyleoption.h>
 
35
#include <qwidget.h>
 
36
 
 
37
#include "qtscriptshell_QItemDelegate.h"
 
38
 
 
39
static const char * const qtscript_QItemDelegate_function_names[] = {
 
40
    "QItemDelegate"
 
41
    // static
 
42
    // prototype
 
43
    , "itemEditorFactory"
 
44
    , "setItemEditorFactory"
 
45
    , "toString"
 
46
};
 
47
 
 
48
static const char * const qtscript_QItemDelegate_function_signatures[] = {
 
49
    "QObject parent"
 
50
    // static
 
51
    // prototype
 
52
    , ""
 
53
    , "QItemEditorFactory factory"
 
54
""
 
55
};
 
56
 
 
57
static QScriptValue qtscript_QItemDelegate_throw_ambiguity_error_helper(
 
58
    QScriptContext *context, const char *functionName, const char *signatures)
 
59
{
 
60
    QStringList lines = QString::fromLatin1(signatures).split(QLatin1Char('\n'));
 
61
    QStringList fullSignatures;
 
62
    for (int i = 0; i < lines.size(); ++i)
 
63
        fullSignatures.append(QString::fromLatin1("%0(%1)").arg(functionName).arg(lines.at(i)));
 
64
    return context->throwError(QString::fromLatin1("QFile::%0(): could not find a function match; candidates are:\n%1")
 
65
        .arg(functionName).arg(fullSignatures.join(QLatin1String("\n"))));
 
66
}
 
67
 
 
68
Q_DECLARE_METATYPE(QItemDelegate*)
 
69
Q_DECLARE_METATYPE(QtScriptShell_QItemDelegate*)
 
70
Q_DECLARE_METATYPE(QItemEditorFactory*)
 
71
Q_DECLARE_METATYPE(QAbstractItemDelegate*)
 
72
 
 
73
//
 
74
// QItemDelegate
 
75
//
 
76
 
 
77
static QScriptValue qtscript_QItemDelegate_prototype_call(QScriptContext *context, QScriptEngine *)
 
78
{
 
79
#if QT_VERSION > 0x040400
 
80
    Q_ASSERT(context->callee().isFunction());
 
81
    uint _id = context->callee().data().toUInt32();
 
82
#else
 
83
    uint _id;
 
84
    if (context->callee().isFunction())
 
85
        _id = context->callee().data().toUInt32();
 
86
    else
 
87
        _id = 0xBABE0000 + 2;
 
88
#endif
 
89
    Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
 
90
    _id &= 0x0000FFFF;
 
91
    QItemDelegate* _q_self = qscriptvalue_cast<QItemDelegate*>(context->thisObject());
 
92
    if (!_q_self) {
 
93
        return context->throwError(QScriptContext::TypeError,
 
94
            QString::fromLatin1("QItemDelegate.%0(): this object is not a QItemDelegate")
 
95
            .arg(qtscript_QItemDelegate_function_names[_id+1]));
 
96
    }
 
97
 
 
98
    switch (_id) {
 
99
    case 0:
 
100
    if (context->argumentCount() == 0) {
 
101
        QItemEditorFactory* _q_result = _q_self->itemEditorFactory();
 
102
        return qScriptValueFromValue(context->engine(), _q_result);
 
103
    }
 
104
    break;
 
105
 
 
106
    case 1:
 
107
    if (context->argumentCount() == 1) {
 
108
        QItemEditorFactory* _q_arg0 = qscriptvalue_cast<QItemEditorFactory*>(context->argument(0));
 
109
        _q_self->setItemEditorFactory(_q_arg0);
 
110
        return context->engine()->undefinedValue();
 
111
    }
 
112
    break;
 
113
 
 
114
    case 2: {
 
115
    QString result = QString::fromLatin1("QItemDelegate");
 
116
    return QScriptValue(context->engine(), result);
 
117
    }
 
118
 
 
119
    default:
 
120
    Q_ASSERT(false);
 
121
    }
 
122
    return qtscript_QItemDelegate_throw_ambiguity_error_helper(context,
 
123
        qtscript_QItemDelegate_function_names[_id+1],
 
124
        qtscript_QItemDelegate_function_signatures[_id+1]);
 
125
}
 
126
 
 
127
static QScriptValue qtscript_QItemDelegate_static_call(QScriptContext *context, QScriptEngine *)
 
128
{
 
129
    uint _id = context->callee().data().toUInt32();
 
130
    Q_ASSERT((_id & 0xFFFF0000) == 0xBABE0000);
 
131
    _id &= 0x0000FFFF;
 
132
    switch (_id) {
 
133
    case 0:
 
134
    if (context->thisObject().strictlyEquals(context->engine()->globalObject())) {
 
135
        return context->throwError(QString::fromLatin1("QItemDelegate(): Did you forget to construct with 'new'?"));
 
136
    }
 
137
    if (context->argumentCount() == 0) {
 
138
        QtScriptShell_QItemDelegate* _q_cpp_result = new QtScriptShell_QItemDelegate();
 
139
        QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QItemDelegate*)_q_cpp_result, QScriptEngine::AutoOwnership);
 
140
        _q_cpp_result->__qtscript_self = _q_result;
 
141
        return _q_result;
 
142
    } else if (context->argumentCount() == 1) {
 
143
        QObject* _q_arg0 = context->argument(0).toQObject();
 
144
        QtScriptShell_QItemDelegate* _q_cpp_result = new QtScriptShell_QItemDelegate(_q_arg0);
 
145
        QScriptValue _q_result = context->engine()->newQObject(context->thisObject(), (QItemDelegate*)_q_cpp_result, QScriptEngine::AutoOwnership);
 
146
        _q_cpp_result->__qtscript_self = _q_result;
 
147
        return _q_result;
 
148
    }
 
149
    break;
 
150
 
 
151
    default:
 
152
    Q_ASSERT(false);
 
153
    }
 
154
    return qtscript_QItemDelegate_throw_ambiguity_error_helper(context,
 
155
        qtscript_QItemDelegate_function_names[_id],
 
156
        qtscript_QItemDelegate_function_signatures[_id]);
 
157
}
 
158
 
 
159
static QScriptValue qtscript_QItemDelegate_toScriptValue(QScriptEngine *engine, QItemDelegate* const &in)
 
160
{
 
161
    return engine->newQObject(in, QScriptEngine::QtOwnership, QScriptEngine::PreferExistingWrapperObject);
 
162
}
 
163
 
 
164
static void qtscript_QItemDelegate_fromScriptValue(const QScriptValue &value, QItemDelegate* &out)
 
165
{
 
166
    out = qobject_cast<QItemDelegate*>(value.toQObject());
 
167
}
 
168
 
 
169
QScriptValue qtscript_create_QItemDelegate_class(QScriptEngine *engine)
 
170
{
 
171
    static const int function_lengths[] = {
 
172
        1
 
173
        // static
 
174
        // prototype
 
175
        , 0
 
176
        , 1
 
177
        , 0
 
178
    };
 
179
    engine->setDefaultPrototype(qMetaTypeId<QItemDelegate*>(), QScriptValue());
 
180
    QScriptValue proto = engine->newVariant(qVariantFromValue((QItemDelegate*)0));
 
181
    proto.setPrototype(engine->defaultPrototype(qMetaTypeId<QAbstractItemDelegate*>()));
 
182
    for (int i = 0; i < 3; ++i) {
 
183
        QScriptValue fun = engine->newFunction(qtscript_QItemDelegate_prototype_call, function_lengths[i+1]);
 
184
        fun.setData(QScriptValue(engine, uint(0xBABE0000 + i)));
 
185
        proto.setProperty(QString::fromLatin1(qtscript_QItemDelegate_function_names[i+1]),
 
186
            fun, QScriptValue::SkipInEnumeration);
 
187
    }
 
188
 
 
189
    qScriptRegisterMetaType<QItemDelegate*>(engine, qtscript_QItemDelegate_toScriptValue, 
 
190
        qtscript_QItemDelegate_fromScriptValue, proto);
 
191
 
 
192
    QScriptValue ctor = engine->newFunction(qtscript_QItemDelegate_static_call, proto, function_lengths[0]);
 
193
    ctor.setData(QScriptValue(engine, uint(0xBABE0000 + 0)));
 
194
 
 
195
    return ctor;
 
196
}