diff options
author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2018-11-08 14:51:00 +0100 |
---|---|---|
committer | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2018-11-13 12:34:28 +0000 |
commit | 9f52793a68e9b7879331fe8399ff9709a5d5c558 (patch) | |
tree | 53f4d6f22aa404b4319ef139c87cb82b071fbb6d | |
parent | 7f8abfc78d6ed861bcc5f41bef224e5c732d2ba9 (diff) |
Remove createIndex method that uses PyObject*
We have a proper `void*` treatment, so the extra
function does not seems to be necessary.
The injected code used for the interalPointer method was
also removed since is better to leave on shiboken hands
the conversion between void* and python types.
A couple of test were adapted since wrongly used ModelIndex
with Python objects.
Change-Id: I082637c7d1dd1bb0f50a3c453513e5d722f4b783
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
4 files changed, 13 insertions, 55 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index cff7e0af0..3b5d9f520 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -1827,11 +1827,6 @@ </add-function> </value-type> <value-type name="QPersistentModelIndex" hash-function="qHash"> - <modify-function signature="internalPointer()const"> - <inject-code class="target" position="beginning"> - <insert-template name="return_internal_pointer" /> - </inject-code> - </modify-function> <modify-function signature="operator const QModelIndex&()const"> <modify-argument index="return"> <parent index="this" action="add"/> @@ -2101,36 +2096,12 @@ <object-type name="QAbstractItemModel"> <enum-type name="CheckIndexOption" flags="CheckIndexOptions" since="5.11"/> <enum-type name="LayoutChangeHint" /> - <!-- This function was replaced by a added function --> - <modify-function signature="createIndex(int,int,void*)const" remove="all"/> <!-- This function is the same as createIndex(int, int, int)const --> <modify-function signature="createIndex(int,int,quintptr)const"> <modify-argument index="3"> <replace-default-expression with="0" /> </modify-argument> </modify-function> - <add-function signature="createIndex(int,int,PyObject*)const" return-type="QModelIndex"> - <modify-argument index="1"> - <rename to="row"/> - </modify-argument> - <modify-argument index="2"> - <rename to="column"/> - </modify-argument> - <modify-argument index="3"> - <rename to="ptr"/> - </modify-argument> - <inject-code class="target" position="beginning"> - %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(%1, %2, %PYARG_3); - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); - </inject-code> - <inject-documentation mode="append" format="target"> - Creates a model index for the given row and column with the internal pointer ptr. - When using a QSortFilterProxyModel, its indexes have their own internal pointer. It is not advisable to access this internal pointer outside of the model. Use the data() function instead. - This function provides a consistent interface that model subclasses must use to create model indexes. - - .. warning:: Because of some Qt/Python itegration rules, the ptr argument do not get the reference incremented during the QModelIndex life time. So it is necessary to keep the object used on ptr argument alive during the whole process. Do not destroy the object if you are not sure about that. - </inject-documentation> - </add-function> <inject-code class="target" position="end"> qRegisterMetaType<QVector<int> >("QVector<int>"); </inject-code> @@ -3890,11 +3861,6 @@ </modify-function> </object-type> <value-type name="QModelIndex" hash-function="qHash"> - <modify-function signature="internalPointer()const"> - <inject-code class="target" position="beginning"> - <insert-template name="return_internal_pointer" /> - </inject-code> - </modify-function> <modify-function signature="model()const"> <modify-argument index="return"> <define-ownership class="target" owner="default"/> diff --git a/sources/pyside2/PySide2/typesystem_templates.xml b/sources/pyside2/PySide2/typesystem_templates.xml index 1cac1a6ba..f0e4a2bf8 100644 --- a/sources/pyside2/PySide2/typesystem_templates.xml +++ b/sources/pyside2/PySide2/typesystem_templates.xml @@ -354,13 +354,6 @@ %PYARG_0 = Shiboken::String::fromCString(qPrintable(format)); </template> - <template name="return_internal_pointer"> - %PYARG_0 = reinterpret_cast<PyObject*>(%CPPSELF.%FUNCTION_NAME()); - if (!%PYARG_0) - %PYARG_0 = Py_None; - Py_INCREF(%PYARG_0); - </template> - <!-- Helpers for modifying "bool nativeEventFilter(QByteArray, void*, long *result)" to return a tuple of bool,long --> <template name="return_native_eventfilter_conversion_variables"> diff --git a/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py b/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py index 70b610c34..fd8d01c99 100644 --- a/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py +++ b/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py @@ -34,14 +34,12 @@ from PySide2.QtCore import * class MyModel (QAbstractListModel): pass -class Foo: - pass class TestQModelIndexInternalPointer(unittest.TestCase): def testInternalPointer(self): m = MyModel() - foo = Foo() + foo = QObject() idx = m.createIndex(0,0, foo) check = m.checkIndex(idx, QAbstractItemModel.CheckIndexOption.IndexIsValid | QAbstractItemModel.CheckIndexOption.DoNotUseParent diff --git a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py index 875d2075c..a67bb380a 100644 --- a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py +++ b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py @@ -33,6 +33,7 @@ import sys import unittest from PySide2.QtCore import * +from PySide2.support import VoidPtr class MyModel (QAbstractListModel): pass @@ -50,22 +51,22 @@ class TestQModelIndexInternalPointer(unittest.TestCase): def testInternalPointer(self): #Test QAbstractListModel.createIndex and - #QModelIndex.internalPointer with regular - #Python objects - idx = self.model.createIndex(0, 0, "Hello") - self.assertEqual("Hello", idx.internalPointer()) - a = [1, 2, 3] - idx = self.model.createIndex(0, 0, a) - self.assertEqual(a, idx.internalPointer()) + #QModelIndex.internalPointer + obj = QObject() + obj_ptr = VoidPtr(obj) + idx = self.model.createIndex(0, 0, obj) + i = idx.internalPointer() + self.assertEqual(int(obj_ptr), int(i)) def testReferenceCounting(self): #Test reference counting when retrieving data with #QModelIndex.internalPointer - a = [1, 2, 3] - a_refcnt = sys.getrefcount(a) - idx = self.model.createIndex(0, 0, a) + o = QObject() + o_refcnt = sys.getrefcount(o) + idx = self.model.createIndex(0, 0, o) ptr = idx.internalPointer() - self.assertEqual(sys.getrefcount(a), a_refcnt + 1) + self.assertEqual(sys.getrefcount(o), o_refcnt) + def testIndexForDefaultDataArg(self): #Test QAbstractListModel.createIndex with a default |