~ubuntu-branches/ubuntu/precise/python-qt4/precise-proposed

« back to all changes in this revision

Viewing changes to qpy/QtDeclarative/qpydeclarativelistproperty.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell, Jonathan Riddell
  • Date: 2010-11-08 16:13:33 UTC
  • mfrom: (1.5.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101108161333-0nec4wu0nz3wpf9r
Tags: 4.8.1-0ubuntu1
[ Jonathan Riddell ]
* New upstream release
* Build against python-sip-dev 4.11.2
* Remove kubuntu_02_fix-scpk-and-flag-issue.diff merged upstream
* Install __init__.py into /usr/lib/python3.2/dist-packages/PyQt4,
  fixes Python 3 support
* Add QtDeclarative to python-qt4
* Add kubuntu_03_uiparser.diff from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This is the implementation of the QPyDeclarativeListProperty class.
 
2
//
 
3
// Copyright (c) 2010 Riverbank Computing Limited <info@riverbankcomputing.com>
 
4
// 
 
5
// This file is part of PyQt.
 
6
// 
 
7
// This file may be used under the terms of the GNU General Public
 
8
// License versions 2.0 or 3.0 as published by the Free Software
 
9
// Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
 
10
// included in the packaging of this file.  Alternatively you may (at
 
11
// your option) use any later version of the GNU General Public
 
12
// License if such license has been publicly approved by Riverbank
 
13
// Computing Limited (or its successors, if any) and the KDE Free Qt
 
14
// Foundation. In addition, as a special exception, Riverbank gives you
 
15
// certain additional rights. These rights are described in the Riverbank
 
16
// GPL Exception version 1.1, which can be found in the file
 
17
// GPL_EXCEPTION.txt in this package.
 
18
// 
 
19
// Please review the following information to ensure GNU General
 
20
// Public Licensing requirements will be met:
 
21
// http://trolltech.com/products/qt/licenses/licensing/opensource/. If
 
22
// you are unsure which license is appropriate for your use, please
 
23
// review the following information:
 
24
// http://trolltech.com/products/qt/licenses/licensing/licensingoverview
 
25
// or contact the sales department at sales@riverbankcomputing.com.
 
26
// 
 
27
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
28
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
29
 
 
30
 
 
31
#include <QObject>
 
32
#include <QtDeclarative>
 
33
 
 
34
#include "sipAPIQtDeclarative.h"
 
35
 
 
36
#include "qpydeclarativelistproperty.h"
 
37
#include "qpydeclarative_listwrapper.h"
 
38
 
 
39
 
 
40
// Forward declarations.
 
41
extern "C" {
 
42
static PyObject *QPyDeclarativeListProperty_call(PyObject *, PyObject *args,
 
43
        PyObject *);
 
44
}
 
45
 
 
46
static void list_append(QDeclarativeListProperty<QObject> *p, QObject *el);
 
47
static QObject *list_at(QDeclarativeListProperty<QObject> *p, int idx);
 
48
static void list_clear(QDeclarativeListProperty<QObject> *p);
 
49
static int list_count(QDeclarativeListProperty<QObject> *p);
 
50
 
 
51
 
 
52
// The type's doc-string.
 
53
PyDoc_STRVAR(QPyDeclarativeListProperty_doc,
 
54
"QPyDeclarativeListProperty(QObject, list-of-QObject)");
 
55
 
 
56
 
 
57
// This implements the QPyDeclarativeListProperty Python type.  It is a
 
58
// sub-type of the standard string type that is callable.
 
59
PyTypeObject qpydeclarative_QPyDeclarativeListProperty_Type = {
 
60
    PyVarObject_HEAD_INIT(NULL, 0)
 
61
    SIP_TPNAME_CAST("PyQt4.QtDeclarative.QPyDeclarativeListProperty"),
 
62
    0,
 
63
    0,
 
64
    0,
 
65
    0,
 
66
    0,
 
67
    0,
 
68
    0,
 
69
    0,
 
70
    0,
 
71
    0,
 
72
    0,
 
73
    0,
 
74
    QPyDeclarativeListProperty_call,
 
75
    0,
 
76
    0,
 
77
    0,
 
78
    0,
 
79
    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|
 
80
#if PY_VERSION_HEX >= 0x03000000
 
81
        Py_TPFLAGS_UNICODE_SUBCLASS,
 
82
#elif PY_VERSION_HEX >= 0x02060000
 
83
        Py_TPFLAGS_STRING_SUBCLASS,
 
84
#else
 
85
        0,
 
86
#endif
 
87
    QPyDeclarativeListProperty_doc,
 
88
    0,
 
89
    0,
 
90
    0,
 
91
    0,
 
92
    0,
 
93
    0,
 
94
    0,
 
95
    0,
 
96
    0,
 
97
    0,
 
98
    0,
 
99
    0,
 
100
    0,
 
101
    0,
 
102
    0,
 
103
    0,
 
104
    0,
 
105
    0,
 
106
    0,
 
107
    0,
 
108
    0,
 
109
    0,
 
110
    0,
 
111
    0,
 
112
    0,
 
113
#if PY_VERSION_HEX >= 0x02060000
 
114
    0,
 
115
#endif
 
116
};
 
117
 
 
118
 
 
119
// This is a factory for the wrapped QDeclarativeListProperty<PyDelegate>.
 
120
static PyObject *QPyDeclarativeListProperty_call(PyObject *, PyObject *args,
 
121
        PyObject *)
 
122
{
 
123
    PyTypeObject *qobject_type = sipTypeAsPyTypeObject(sipType_QObject);
 
124
    PyObject *qobj_obj, *list_obj;
 
125
 
 
126
    if (!PyArg_ParseTuple(args,
 
127
#if PY_VERSION_HEX >= 0x02050000
 
128
            "O!O!:QPyDeclarativeListProperty",
 
129
#else
 
130
            const_cast<char *>("O!O!:QPyDeclarativeListProperty"),
 
131
#endif
 
132
            qobject_type, &qobj_obj, &PyList_Type, &list_obj, &PyType_Type))
 
133
        return 0;
 
134
 
 
135
    // Get the C++ QObject.
 
136
    int iserr = 0;
 
137
    QObject *qobj = reinterpret_cast<QObject *>(sipConvertToType(qobj_obj, sipType_QObject, 0, SIP_NOT_NONE|SIP_NO_CONVERTORS, 0, &iserr));
 
138
 
 
139
    if (iserr)
 
140
        return 0;
 
141
 
 
142
    // Get a list wrapper with the C++ QObject as its parent.
 
143
    ListWrapper *list_wrapper = ListWrapper::wrapper(list_obj, qobj);
 
144
 
 
145
    if (!list_wrapper)
 
146
        return 0;
 
147
 
 
148
    // Create the C++ QDeclarativeListProperty<QObject> with the list as the
 
149
    // data.
 
150
    QDeclarativeListProperty<QObject> *prop = new QDeclarativeListProperty<QObject>(qobj, &list_wrapper->qobject_list, list_append, list_count, list_at, list_clear);
 
151
 
 
152
    // Convert it to a Python object.
 
153
    static const sipTypeDef *mapped_type = 0;
 
154
 
 
155
    if (!mapped_type)
 
156
        mapped_type = sipFindType("QDeclarativeListProperty<QObject>");
 
157
 
 
158
    Q_ASSERT(mapped_type);
 
159
 
 
160
    // Make sure ownership is with Python.
 
161
    PyObject *prop_obj = sipConvertFromNewType(prop, mapped_type, qobj_obj);
 
162
 
 
163
    if (!prop_obj)
 
164
    {
 
165
        delete prop;
 
166
        return 0;
 
167
    }
 
168
 
 
169
    return prop_obj;
 
170
}
 
171
 
 
172
 
 
173
// Append to the list.
 
174
static void list_append(QDeclarativeListProperty<QObject> *p, QObject *el)
 
175
{
 
176
    ListWrapper::append(p->object,
 
177
            reinterpret_cast<QList<QObject *> *>(p->data), el);
 
178
}
 
179
 
 
180
 
 
181
// Get the length of the list.
 
182
static int list_count(QDeclarativeListProperty<QObject> *p)
 
183
{
 
184
    return reinterpret_cast<QList<QObject *> *>(p->data)->count();
 
185
}
 
186
 
 
187
 
 
188
// Get an item from the list.
 
189
static QObject *list_at(QDeclarativeListProperty<QObject> *p, int idx)
 
190
{
 
191
    return reinterpret_cast<QList<QObject *> *>(p->data)->at(idx);
 
192
}
 
193
 
 
194
 
 
195
// Clear the list.
 
196
static void list_clear(QDeclarativeListProperty<QObject> *p)
 
197
{
 
198
    ListWrapper::clear(p->object,
 
199
            reinterpret_cast<QList<QObject *> *>(p->data));
 
200
}