1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
// This contains the implementation of the QQmlListPropertyWrapper type.
//
// Copyright (c) 2018 Riverbank Computing Limited <info@riverbankcomputing.com>
//
// This file is part of PyQt5.
//
// This file may be used under the terms of the GNU General Public License
// version 3.0 as published by the Free Software Foundation and appearing in
// the file LICENSE included in the packaging of this file. Please review the
// following information to ensure the GNU General Public License version 3.0
// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
//
// If you do not wish to use this file under the terms of the GPL version 3.0
// then you may purchase a commercial license. For more information contact
// info@riverbankcomputing.com.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#include <Python.h>
#include <sip.h>
#include "qpyqmllistpropertywrapper.h"
// The type object.
PyTypeObject *qpyqml_QQmlListPropertyWrapper_TypeObject;
// Forward declarations.
extern "C" {
static void QQmlListPropertyWrapper_dealloc(PyObject *self);
static Py_ssize_t QQmlListPropertyWrapper_sq_length(PyObject *self);
static PyObject *QQmlListPropertyWrapper_sq_concat(PyObject *self,
PyObject *other);
static PyObject *QQmlListPropertyWrapper_sq_repeat(PyObject *self,
Py_ssize_t count);
static PyObject *QQmlListPropertyWrapper_sq_item(PyObject *self, Py_ssize_t i);
#if PY_MAJOR_VERSION < 3
static PyObject *QQmlListPropertyWrapper_sq_slice(PyObject *self,
Py_ssize_t i1, Py_ssize_t i2);
#endif
static int QQmlListPropertyWrapper_sq_ass_item(PyObject *self, Py_ssize_t i,
PyObject *value);
#if PY_MAJOR_VERSION < 3
static int QQmlListPropertyWrapper_sq_ass_slice(PyObject *self, Py_ssize_t i1,
Py_ssize_t i2, PyObject *value);
#endif
static int QQmlListPropertyWrapper_sq_contains(PyObject *self,
PyObject *value);
static PyObject *QQmlListPropertyWrapper_sq_inplace_concat(PyObject *self,
PyObject *other);
static PyObject *QQmlListPropertyWrapper_sq_inplace_repeat(PyObject *self,
Py_ssize_t count);
}
static PyObject *get_list(PyObject *self);
#if PY_VERSION_HEX >= 0x03040000
// Define the slots.
static PyType_Slot qpyqml_QQmlListPropertyWrapper_Slots[] = {
{Py_tp_dealloc, (void *)QQmlListPropertyWrapper_dealloc},
{Py_sq_length, (void *)QQmlListPropertyWrapper_sq_length},
{Py_sq_concat, (void *)QQmlListPropertyWrapper_sq_concat},
{Py_sq_repeat, (void *)QQmlListPropertyWrapper_sq_repeat},
{Py_sq_item, (void *)QQmlListPropertyWrapper_sq_item},
{Py_sq_ass_item, (void *)QQmlListPropertyWrapper_sq_ass_item},
{Py_sq_contains, (void *)QQmlListPropertyWrapper_sq_contains},
{Py_sq_inplace_concat, (void *)QQmlListPropertyWrapper_sq_inplace_concat},
{Py_sq_inplace_repeat, (void *)QQmlListPropertyWrapper_sq_inplace_repeat},
{0, 0}
};
// Define the type.
static PyType_Spec qpyqml_QQmlListPropertyWrapper_Spec = {
"PyQt5.QtQml.QQmlListPropertyWrapper",
sizeof (qpyqml_QQmlListPropertyWrapper),
0,
Py_TPFLAGS_DEFAULT,
qpyqml_QQmlListPropertyWrapper_Slots
};
#else
// Define the sequence methods.
PySequenceMethods QQmlListPropertyWrapper_as_sequence = {
QQmlListPropertyWrapper_sq_length,
QQmlListPropertyWrapper_sq_concat,
QQmlListPropertyWrapper_sq_repeat,
QQmlListPropertyWrapper_sq_item,
#if PY_MAJOR_VERSION < 3
QQmlListPropertyWrapper_sq_slice,
#else
0,
#endif
QQmlListPropertyWrapper_sq_ass_item,
#if PY_MAJOR_VERSION < 3
QQmlListPropertyWrapper_sq_ass_slice,
#else
0,
#endif
QQmlListPropertyWrapper_sq_contains,
QQmlListPropertyWrapper_sq_inplace_concat,
QQmlListPropertyWrapper_sq_inplace_repeat,
};
// Define the type.
PyTypeObject qpyqml_QQmlListPropertyWrapper_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
#if PY_VERSION_HEX >= 0x02050000
"PyQt5.QtQml.QQmlListPropertyWrapper", /* tp_name */
#else
const_cast<char *>("PyQt5.QtQml.QQmlListPropertyWrapper"), /* tp_name */
#endif
sizeof (qpyqml_QQmlListPropertyWrapper), /* tp_basicsize */
0, /* tp_itemsize */
QQmlListPropertyWrapper_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
&QQmlListPropertyWrapper_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
0, /* tp_version_tag */
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
};
#endif
// Initialise the type and return true if there was no error.
bool qpyqml_QQmlListPropertyWrapper_init_type()
{
#if PY_VERSION_HEX >= 0x03040000
qpyqml_QQmlListPropertyWrapper_TypeObject = (PyTypeObject *)PyType_FromSpec(
&qpyqml_QQmlListPropertyWrapper_Spec);
return qpyqml_QQmlListPropertyWrapper_TypeObject;
#else
if (PyType_Ready(&qpyqml_QQmlListPropertyWrapper_Type) < 0)
return false;
qpyqml_QQmlListPropertyWrapper_TypeObject = &qpyqml_QQmlListPropertyWrapper_Type;
return true;
#endif
}
// Create the wrapper object.
PyObject *qpyqml_QQmlListPropertyWrapper_New(QQmlListProperty<QObject> *prop,
PyObject *list)
{
qpyqml_QQmlListPropertyWrapper *obj;
obj = PyObject_New(qpyqml_QQmlListPropertyWrapper,
qpyqml_QQmlListPropertyWrapper_TypeObject);
if (!obj)
return 0;
obj->qml_list_property = prop;
obj->py_list = list;
return (PyObject *)obj;
}
// The type dealloc slot.
static void QQmlListPropertyWrapper_dealloc(PyObject *self)
{
delete ((qpyqml_QQmlListPropertyWrapper *)self)->qml_list_property;
PyObject_Del(self);
}
// Return the underlying list. Return 0 and raise an exception if there wasn't
// one.
static PyObject *get_list(PyObject *self)
{
PyObject *list = ((qpyqml_QQmlListPropertyWrapper *)self)->py_list;
if (!list)
{
PyErr_SetString(PyExc_TypeError,
"there is no object bound to QQmlListProperty");
return 0;
}
// Make sure it has sequence methods.
if (!PySequence_Check(list))
{
PyErr_SetString(PyExc_TypeError,
"object bound to QQmlListProperty is not a sequence");
return 0;
}
return list;
}
// The proxy sequence methods.
static Py_ssize_t QQmlListPropertyWrapper_sq_length(PyObject *self)
{
PyObject *list = get_list(self);
if (!list)
return -1;
return PySequence_Size(list);
}
static PyObject *QQmlListPropertyWrapper_sq_concat(PyObject *self,
PyObject *other)
{
PyObject *list = get_list(self);
if (!list)
return 0;
return PySequence_Concat(list, other);
}
static PyObject *QQmlListPropertyWrapper_sq_repeat(PyObject *self,
Py_ssize_t count)
{
PyObject *list = get_list(self);
if (!list)
return 0;
return PySequence_Repeat(list, count);
}
static PyObject *QQmlListPropertyWrapper_sq_item(PyObject *self, Py_ssize_t i)
{
PyObject *list = get_list(self);
if (!list)
return 0;
return PySequence_GetItem(list, i);
}
#if PY_MAJOR_VERSION < 3
static PyObject *QQmlListPropertyWrapper_sq_slice(PyObject *self,
Py_ssize_t i1, Py_ssize_t i2)
{
PyObject *list = get_list(self);
if (!list)
return 0;
return PySequence_GetSlice(list, i1, i2);
}
#endif
static int QQmlListPropertyWrapper_sq_ass_item(PyObject *self, Py_ssize_t i,
PyObject *value)
{
PyObject *list = get_list(self);
if (!list)
return -1;
return PySequence_SetItem(list, i, value);
}
#if PY_MAJOR_VERSION < 3
static int QQmlListPropertyWrapper_sq_ass_slice(PyObject *self, Py_ssize_t i1,
Py_ssize_t i2, PyObject *value)
{
PyObject *list = get_list(self);
if (!list)
return -1;
return PySequence_SetSlice(list, i1, i2, value);
}
#endif
static int QQmlListPropertyWrapper_sq_contains(PyObject *self, PyObject *value)
{
PyObject *list = get_list(self);
if (!list)
return -1;
return PySequence_Contains(list, value);
}
static PyObject *QQmlListPropertyWrapper_sq_inplace_concat(PyObject *self,
PyObject *other)
{
PyObject *list = get_list(self);
if (!list)
return 0;
return PySequence_InPlaceConcat(list, other);
}
static PyObject *QQmlListPropertyWrapper_sq_inplace_repeat(PyObject *self,
Py_ssize_t count)
{
PyObject *list = get_list(self);
if (!list)
return 0;
return PySequence_InPlaceRepeat(list, count);
}
|