aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Jones <aj@dneg.com>2012-04-18 21:51:15 +0100
committerHugo Parente Lima <hugo.lima@openbossa.org>2012-04-19 00:22:44 +0200
commit6f93c2029e9f076de1be7d8f674b3c99f664d0a1 (patch)
tree22d4bc8fc297c3264b11fe2aad33583c2185ad34
parentf011ce2cb9e2b93a748874de007232ec88cc8ac1 (diff)
Add hash-function for QModelIndex and QPersistenModelIndex
Change-Id: I2725e78a1006fbee54894f202997e2e408998551 Task-number: PYSIDE-41 Reviewed-by: Hugo Parente Lima <hugo.lima@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core_common.xml4
-rw-r--r--tests/QtGui/CMakeLists.txt1
-rw-r--r--tests/QtGui/bug_PYSIDE-41.py44
3 files changed, 47 insertions, 2 deletions
diff --git a/PySide/QtCore/typesystem_core_common.xml b/PySide/QtCore/typesystem_core_common.xml
index 2e831312..5ef1466f 100644
--- a/PySide/QtCore/typesystem_core_common.xml
+++ b/PySide/QtCore/typesystem_core_common.xml
@@ -1634,7 +1634,7 @@
</inject-code>
</add-function>
</value-type>
- <value-type name="QPersistentModelIndex">
+ <value-type name="QPersistentModelIndex" hash-function="qHash">
<modify-function signature="internalPointer()const">
<inject-code class="target" position="beginning">
<insert-template name="return_internal_pointer" />
@@ -3623,7 +3623,7 @@
</modify-argument>
</modify-function>
</object-type>
- <value-type name="QModelIndex">
+ <value-type name="QModelIndex" hash-function="qHash">
<modify-function signature="internalPointer()const">
<inject-code class="target" position="beginning">
<insert-template name="return_internal_pointer" />
diff --git a/tests/QtGui/CMakeLists.txt b/tests/QtGui/CMakeLists.txt
index 9bac9130..1f88bf5f 100644
--- a/tests/QtGui/CMakeLists.txt
+++ b/tests/QtGui/CMakeLists.txt
@@ -81,6 +81,7 @@ PYSIDE_TEST(bug_1002.py)
PYSIDE_TEST(bug_1006.py)
PYSIDE_TEST(bug_1048.py)
PYSIDE_TEST(bug_1077.py)
+PYSIDE_TEST(bug_PYSIDE-41.py)
PYSIDE_TEST(customproxywidget_test.py)
PYSIDE_TEST(deepcopy_test.py)
PYSIDE_TEST(event_filter_test.py)
diff --git a/tests/QtGui/bug_PYSIDE-41.py b/tests/QtGui/bug_PYSIDE-41.py
new file mode 100644
index 00000000..0ca7d908
--- /dev/null
+++ b/tests/QtGui/bug_PYSIDE-41.py
@@ -0,0 +1,44 @@
+# TODO:
+# move this to QtCore -- QStringListModel is part of QtGui and there is no
+# simple model class appropriate for this test in QtCore.
+
+import unittest
+
+from PySide.QtCore import *
+from PySide.QtGui import *
+
+
+class TestBugPYSIDE41(unittest.TestCase):
+
+ def testIt(self):
+
+ # list of single-character strings
+ strings = list('abcdefghijklmnopqrstuvwxyz')
+
+ model = QStringListModel(strings)
+
+ # Test hashing of both QModelIndex and QPersistentModelIndex
+ indexFunctions = []
+ indexFunctions.append(model.index)
+ indexFunctions.append(lambda i: QPersistentModelIndex(model.index(i)))
+
+ for indexFunction in indexFunctions:
+
+ # If two objects compare equal, their hashes MUST also be equal. (The
+ # reverse is not a requirement.)
+ for i, _ in enumerate(strings):
+ index1 = indexFunction(i)
+ index2 = indexFunction(i)
+ self.assertEqual(index1, index2)
+ self.assertEqual(hash(index1), hash(index2))
+
+ # Adding the full set of indexes to itself is a no-op.
+ allIndexes1 = set(indexFunction(i) for i, _ in enumerate(strings))
+ allIndexes2 = set(indexFunction(i) for i, _ in enumerate(strings))
+ allIndexesCombined = allIndexes1 & allIndexes2
+ self.assertEqual(allIndexes1, allIndexesCombined)
+ self.assertEqual(allIndexes2, allIndexesCombined)
+
+
+if __name__ == '__main__':
+ unittest.main()