summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2019-01-07 12:46:13 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2019-01-08 11:47:47 +0000
commitc8970b29d76415d41fa383cbe5eb77eefb191fa1 (patch)
tree3cadb0b721f8bd9778a07589fe693bc6e0a00210
parent1bd279b01d06eba0abbbb5fea0c12a6de2600cdd (diff)
[reg] Remove createIndex method that uses PyObject*
Even though we have support for Void*, having to import it as an additional class to be able to call a separate function, is adding too much complexity so something that should be easy to do, like creating an index for an itemmodel. The regression is a change that replaced the way of doing: QAbstractItemModel.createIndex(0, 0, PyObject*) to QAbstractItemModel.createIndex(0, 0, VoidPtr(PyObject*)) which is not really intuitive, and is generating other issues. Included modification in the registries too. Change-Id: Ie6112c6baeb4fc3b22fc78e7edeb66aa4a17c22b Fixes: PYSIDE-883 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml36
-rw-r--r--sources/pyside2/PySide2/templates/core_common.xml7
-rw-r--r--sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py12
-rw-r--r--sources/pyside2/tests/registry/exists_darwin_5_12_0_ci.py4
-rw-r--r--sources/pyside2/tests/registry/exists_opensuse423_5_12_0_ci.py4
-rw-r--r--sources/pyside2/tests/registry/exists_redhatenterpriselinuxworkstation74_5_12_0_ci.py4
-rw-r--r--sources/pyside2/tests/registry/exists_win32_5_12_0_ci.py4
7 files changed, 56 insertions, 15 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index c70049d8..7531b33b 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -1210,6 +1210,11 @@
</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&amp;()const">
<modify-argument index="return">
<parent index="this" action="add"/>
@@ -1460,12 +1465,38 @@
<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" file="../glue/qtcore.cpp" snippet="qabstractitemmodel-createindex"/>
+ <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" file="../glue/qtcore.cpp" snippet="qabstractitemmodel"/>
<modify-function signature="mimeData(QModelIndexList)const">
<modify-argument index="return">
@@ -2774,6 +2805,11 @@
</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/templates/core_common.xml b/sources/pyside2/PySide2/templates/core_common.xml
index 0fe19273..4f715ee1 100644
--- a/sources/pyside2/PySide2/templates/core_common.xml
+++ b/sources/pyside2/PySide2/templates/core_common.xml
@@ -260,6 +260,13 @@
%PYARG_0 = Shiboken::String::fromCString(qPrintable(format));
</template>
+ <template name="return_internal_pointer">
+ %PYARG_0 = reinterpret_cast&lt;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/qmodelindex_internalpointer_test.py b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py
index a67bb380..770600ea 100644
--- a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py
+++ b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py
@@ -33,7 +33,6 @@
import sys
import unittest
from PySide2.QtCore import *
-from PySide2.support import VoidPtr
class MyModel (QAbstractListModel):
pass
@@ -51,21 +50,20 @@ class TestQModelIndexInternalPointer(unittest.TestCase):
def testInternalPointer(self):
#Test QAbstractListModel.createIndex and
- #QModelIndex.internalPointer
+ #QModelIndex.internalPointer with regular Python objects
obj = QObject()
- obj_ptr = VoidPtr(obj)
- idx = self.model.createIndex(0, 0, obj)
+ idx = self.model.createIndex(0, 0, "Hello")
i = idx.internalPointer()
- self.assertEqual(int(obj_ptr), int(i))
+ self.assertEqual(i, "Hello")
def testReferenceCounting(self):
#Test reference counting when retrieving data with
#QModelIndex.internalPointer
- o = QObject()
+ o = [1, 2, 3]
o_refcnt = sys.getrefcount(o)
idx = self.model.createIndex(0, 0, o)
ptr = idx.internalPointer()
- self.assertEqual(sys.getrefcount(o), o_refcnt)
+ self.assertEqual(sys.getrefcount(o), o_refcnt + 1)
def testIndexForDefaultDataArg(self):
diff --git a/sources/pyside2/tests/registry/exists_darwin_5_12_0_ci.py b/sources/pyside2/tests/registry/exists_darwin_5_12_0_ci.py
index a2b6aa14..7a070abf 100644
--- a/sources/pyside2/tests/registry/exists_darwin_5_12_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_darwin_5_12_0_ci.py
@@ -157,7 +157,7 @@ if "PySide2.QtCore" in sys.modules:
"QAbstractItemModel.changePersistentIndexList": ('typing.List[int]', 'typing.List[int]'),
"QAbstractItemModel.checkIndex": ('PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QAbstractItemModel.CheckIndexOptions'),
"QAbstractItemModel.columnCount": ('PySide2.QtCore.QModelIndex',),
- "QAbstractItemModel.createIndex": ('int', 'int', 'int'),
+ "QAbstractItemModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object')],
"QAbstractItemModel.data": ('PySide2.QtCore.QModelIndex', 'int'),
"QAbstractItemModel.decodeData": ('int', 'int', 'PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QDataStream'),
"QAbstractItemModel.dropMimeData": ('PySide2.QtCore.QMimeData', 'PySide2.QtCore.Qt.DropAction', 'int', 'int', 'PySide2.QtCore.QModelIndex'),
@@ -15202,7 +15202,7 @@ if "PySide2.QtHelp" in sys.modules:
"QHelpEngineCore.unregisterDocumentation": ('str',),
# class PySide2.QtHelp.QHelpIndexModel:
- "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('str',)],
+ "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object'), ('str',)],
"QHelpIndexModel.filter": ('str', 'str'),
"QHelpIndexModel.isCreatingIndex": (),
"QHelpIndexModel.linksForKeyword": ('str',),
diff --git a/sources/pyside2/tests/registry/exists_opensuse423_5_12_0_ci.py b/sources/pyside2/tests/registry/exists_opensuse423_5_12_0_ci.py
index 5cb8a230..6caa0947 100644
--- a/sources/pyside2/tests/registry/exists_opensuse423_5_12_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_opensuse423_5_12_0_ci.py
@@ -157,7 +157,7 @@ if "PySide2.QtCore" in sys.modules:
"QAbstractItemModel.changePersistentIndexList": ('typing.List[int]', 'typing.List[int]'),
"QAbstractItemModel.checkIndex": ('PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QAbstractItemModel.CheckIndexOptions'),
"QAbstractItemModel.columnCount": ('PySide2.QtCore.QModelIndex',),
- "QAbstractItemModel.createIndex": ('int', 'int', 'int'),
+ "QAbstractItemModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object')],
"QAbstractItemModel.data": ('PySide2.QtCore.QModelIndex', 'int'),
"QAbstractItemModel.decodeData": ('int', 'int', 'PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QDataStream'),
"QAbstractItemModel.dropMimeData": ('PySide2.QtCore.QMimeData', 'PySide2.QtCore.Qt.DropAction', 'int', 'int', 'PySide2.QtCore.QModelIndex'),
@@ -15213,7 +15213,7 @@ if "PySide2.QtHelp" in sys.modules:
"QHelpEngineCore.unregisterDocumentation": ('str',),
# class PySide2.QtHelp.QHelpIndexModel:
- "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('str',)],
+ "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object'), ('str',)],
"QHelpIndexModel.filter": ('str', 'str'),
"QHelpIndexModel.isCreatingIndex": (),
"QHelpIndexModel.linksForKeyword": ('str',),
diff --git a/sources/pyside2/tests/registry/exists_redhatenterpriselinuxworkstation74_5_12_0_ci.py b/sources/pyside2/tests/registry/exists_redhatenterpriselinuxworkstation74_5_12_0_ci.py
index 969ac36c..c7b58c3f 100644
--- a/sources/pyside2/tests/registry/exists_redhatenterpriselinuxworkstation74_5_12_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_redhatenterpriselinuxworkstation74_5_12_0_ci.py
@@ -157,7 +157,7 @@ if "PySide2.QtCore" in sys.modules:
"QAbstractItemModel.changePersistentIndexList": ('typing.List[int]', 'typing.List[int]'),
"QAbstractItemModel.checkIndex": ('PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QAbstractItemModel.CheckIndexOptions'),
"QAbstractItemModel.columnCount": ('PySide2.QtCore.QModelIndex',),
- "QAbstractItemModel.createIndex": ('int', 'int', 'int'),
+ "QAbstractItemModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object')],
"QAbstractItemModel.data": ('PySide2.QtCore.QModelIndex', 'int'),
"QAbstractItemModel.decodeData": ('int', 'int', 'PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QDataStream'),
"QAbstractItemModel.dropMimeData": ('PySide2.QtCore.QMimeData', 'PySide2.QtCore.Qt.DropAction', 'int', 'int', 'PySide2.QtCore.QModelIndex'),
@@ -15213,7 +15213,7 @@ if "PySide2.QtHelp" in sys.modules:
"QHelpEngineCore.unregisterDocumentation": ('str',),
# class PySide2.QtHelp.QHelpIndexModel:
- "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('str',)],
+ "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object'), ('str',)],
"QHelpIndexModel.filter": ('str', 'str'),
"QHelpIndexModel.isCreatingIndex": (),
"QHelpIndexModel.linksForKeyword": ('str',),
diff --git a/sources/pyside2/tests/registry/exists_win32_5_12_0_ci.py b/sources/pyside2/tests/registry/exists_win32_5_12_0_ci.py
index 189e5c74..0a3f587f 100644
--- a/sources/pyside2/tests/registry/exists_win32_5_12_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_win32_5_12_0_ci.py
@@ -159,7 +159,7 @@ if "PySide2.QtCore" in sys.modules:
"QAbstractItemModel.changePersistentIndexList": ('typing.List', 'typing.List'),
"QAbstractItemModel.checkIndex": ('PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QAbstractItemModel.CheckIndexOptions'),
"QAbstractItemModel.columnCount": ('PySide2.QtCore.QModelIndex',),
- "QAbstractItemModel.createIndex": ('int', 'int', 'int'),
+ "QAbstractItemModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object')],
"QAbstractItemModel.data": ('PySide2.QtCore.QModelIndex', 'int'),
"QAbstractItemModel.decodeData": ('int', 'int', 'PySide2.QtCore.QModelIndex', 'PySide2.QtCore.QDataStream'),
"QAbstractItemModel.dropMimeData": ('PySide2.QtCore.QMimeData', 'PySide2.QtCore.Qt.DropAction', 'int', 'int', 'PySide2.QtCore.QModelIndex'),
@@ -15335,7 +15335,7 @@ if "PySide2.QtHelp" in sys.modules:
"QHelpEngineCore.unregisterDocumentation": ('str',),
# class PySide2.QtHelp.QHelpIndexModel:
- "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('str',)],
+ "QHelpIndexModel.createIndex": [('int', 'int', 'int'), ('int', 'int', 'object'), ('str',)],
"QHelpIndexModel.filter": ('str', 'str'),
"QHelpIndexModel.isCreatingIndex": (),
"QHelpIndexModel.linksForKeyword": ('str',),