aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6')
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml21
-rw-r--r--sources/pyside6/PySide6/templates/core_common.xml53
-rw-r--r--sources/pyside6/tests/pysidetest/CMakeLists.txt2
-rw-r--r--sources/pyside6/tests/pysidetest/container_test.py73
-rw-r--r--sources/pyside6/tests/pysidetest/containertest.cpp62
-rw-r--r--sources/pyside6/tests/pysidetest/containertest.h51
-rw-r--r--sources/pyside6/tests/pysidetest/pysidetest_global.h1
-rw-r--r--sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml2
8 files changed, 263 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index e0683ab51..4e2036471 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -472,6 +472,23 @@
</target-to-native>
</conversion-rule>
</container-type>
+
+ <container-type name="QMultiHash" type="multi-hash">
+ <include file-name="QMultiHash" location="global"/>
+ <!-- Include to make enum flags work. -->
+ <include file-name="pysideqflags.h" location="global"/>
+ <conversion-rule>
+ <native-to-target>
+ <insert-template name="cppmultihash_to_pymap_conversion"/>
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PyDict">
+ <insert-template name="pydict_to_cppmultimap_conversion"/>
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
+ </container-type>
+
<container-type name="QMap" type="map">
<include file-name="QMap" location="global"/>
<conversion-rule>
@@ -489,11 +506,11 @@
<include file-name="QMultiMap" location="global"/>
<conversion-rule>
<native-to-target>
- <insert-template name="cppmap_to_pymap_conversion"/>
+ <insert-template name="cppmultimap_to_pymap_conversion"/>
</native-to-target>
<target-to-native>
<add-conversion type="PyDict">
- <insert-template name="pydict_to_cppmap_conversion"/>
+ <insert-template name="pydict_to_cppmultimap_conversion"/>
</add-conversion>
</target-to-native>
</conversion-rule>
diff --git a/sources/pyside6/PySide6/templates/core_common.xml b/sources/pyside6/PySide6/templates/core_common.xml
index db63e431d..e8fbb083b 100644
--- a/sources/pyside6/PySide6/templates/core_common.xml
+++ b/sources/pyside6/PySide6/templates/core_common.xml
@@ -348,6 +348,59 @@
}
</template>
+ <template name="cppmultimap_to_pymap_conversion">
+ PyObject *%out = PyDict_New();
+ for (auto it = %in.cbegin(), end = %in.cend(); it != end; ) {
+ const auto &amp;key = it.key();
+ PyObject *pyKey = %CONVERTTOPYTHON[%INTYPE_0](key);
+ %INTYPE::const_iterator keyEnd = %in.upperBound(key);
+ const auto count = Py_ssize_t(std::distance(it, keyEnd));
+ PyObject *pyValues = PyList_New(count);
+ Py_ssize_t idx = 0;
+ for ( ; it != keyEnd; ++it, ++idx) {
+ const auto &amp;cppItem = it.value();
+ PyList_SET_ITEM(pyValues, idx, %CONVERTTOPYTHON[%INTYPE_1](cppItem));
+ }
+ PyDict_SetItem(%out, pyKey, pyValues);
+ Py_DECREF(pyKey);
+ }
+ return %out;
+ </template>
+
+ <template name="cppmultihash_to_pymap_conversion">
+ PyObject *%out = PyDict_New();
+ for (auto kit = %in.keyBegin(), end = %in.keyEnd(); kit != end; ++kit) {
+ const auto &amp;key = *kit;
+ PyObject *pyKey = %CONVERTTOPYTHON[%INTYPE_0](key);
+ auto range = %in.equal_range(key);
+ const auto count = Py_ssize_t(std::distance(range.first, range.second));
+ PyObject *pyValues = PyList_New(count);
+ Py_ssize_t idx = 0;
+ for (auto it = range.first; it != range.second; ++it, ++idx) {
+ const auto &amp;cppItem = it.value();
+ PyList_SET_ITEM(pyValues, idx, %CONVERTTOPYTHON[%INTYPE_1](cppItem));
+ }
+ PyDict_SetItem(%out, pyKey, pyValues);
+ Py_DECREF(pyKey);
+ }
+ return %out;
+ </template>
+
+ <template name="pydict_to_cppmultimap_conversion">
+ PyObject *key;
+ PyObject *values;
+ Py_ssize_t pos = 0;
+ while (PyDict_Next(%in, &amp;pos, &amp;key, &amp;values)) {
+ %OUTTYPE_0 cppKey = %CONVERTTOCPP[%OUTTYPE_0](key);
+ const Py_ssize_t size = PySequence_Size(values);
+ for (Py_ssize_t i = 0; i &lt; size; ++i) {
+ Shiboken::AutoDecRef value(PySequence_GetItem(values, i));
+ %OUTTYPE_1 cppValue = %CONVERTTOCPP[%OUTTYPE_1](value);
+ %out.insert(cppKey, cppValue);
+ }
+ }
+ </template>
+
<template name="pydatetime_importandcheck_function">
static bool PyDateTime_ImportAndCheck(PyObject *pyIn)
{
diff --git a/sources/pyside6/tests/pysidetest/CMakeLists.txt b/sources/pyside6/tests/pysidetest/CMakeLists.txt
index c27080d38..7717fc8c6 100644
--- a/sources/pyside6/tests/pysidetest/CMakeLists.txt
+++ b/sources/pyside6/tests/pysidetest/CMakeLists.txt
@@ -17,6 +17,7 @@ add_definitions(-DRXX_ALLOCATOR_INIT_0)
find_package(Qt${QT_MAJOR_VERSION}Widgets)
set(pysidetest_SRC
+containertest.cpp
flagstest.cpp
testobject.cpp
testview.cpp
@@ -24,6 +25,7 @@ hiddenobject.cpp
)
set(testbinding_SRC
+${CMAKE_CURRENT_BINARY_DIR}/testbinding/containertest_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/flagsnamespace_classforenum_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/testobject_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/intvalue_wrapper.cpp
diff --git a/sources/pyside6/tests/pysidetest/container_test.py b/sources/pyside6/tests/pysidetest/container_test.py
new file mode 100644
index 000000000..14feb4465
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/container_test.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+#############################################################################
+##
+## Copyright (C) 2021 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(True)
+
+from testbinding import ContainerTest
+
+
+EXPECTED_DICT = {1: ["v1"], 2: ["v2_1", "v2_2"],
+ 3: ["v3"],
+ 4: ["v4_1", "v4_2"]}
+
+
+def sort_values(m):
+ """Sort value lists in dicts since passing through a QMultiMap changes the order"""
+ result = {}
+ for key, values in m.items():
+ result[key] = sorted(values)
+ return result
+
+
+class ContainerTestTest(unittest.TestCase):
+
+ def testMultiMap(self):
+ m1 = ContainerTest.createMultiMap()
+ self.assertEqual(sort_values(m1), EXPECTED_DICT)
+ m2 = ContainerTest.passThroughMultiMap(m1)
+ self.assertEqual(sort_values(m2), EXPECTED_DICT)
+
+ def testMultiHash(self):
+ m1 = ContainerTest.createMultiHash()
+ self.assertEqual(sort_values(m1), EXPECTED_DICT)
+ m2 = ContainerTest.passThroughMultiHash(m1)
+ self.assertEqual(sort_values(m2), EXPECTED_DICT)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/sources/pyside6/tests/pysidetest/containertest.cpp b/sources/pyside6/tests/pysidetest/containertest.cpp
new file mode 100644
index 000000000..ccb90b12f
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/containertest.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "containertest.h"
+
+ContainerTest::ContainerTest() = default;
+
+QMultiMap<int, QString> ContainerTest::createMultiMap()
+{
+ static const QMultiMap<int, QString>
+ result{{1, u"v1"_qs},
+ {2, u"v2_1"_qs}, {2, u"v2_2"_qs},
+ {3, u"v3"_qs},
+ {4, u"v4_1"_qs}, {4, u"v4_2"_qs}};
+ return result;
+}
+
+QMultiMap<int, QString> ContainerTest::passThroughMultiMap(const QMultiMap<int, QString> &in)
+{
+ return in;
+}
+
+QMultiHash<int, QString> ContainerTest::createMultiHash()
+{
+ static const QMultiHash<int, QString>
+ result{{1, u"v1"_qs},
+ {2, u"v2_1"_qs}, {2, u"v2_2"_qs},
+ {3, u"v3"_qs},
+ {4, u"v4_1"_qs}, {4, u"v4_2"_qs}};
+ return result;
+
+}
+
+QMultiHash<int, QString> ContainerTest::passThroughMultiHash(const QMultiHash<int, QString> &in)
+{
+ return in;
+}
diff --git a/sources/pyside6/tests/pysidetest/containertest.h b/sources/pyside6/tests/pysidetest/containertest.h
new file mode 100644
index 000000000..3405b6722
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/containertest.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include "pysidetest_macros.h"
+
+#include <QtCore/QObject>
+#include <QtCore/QMap>
+#include <QtCore/QMultiMap>
+#include <QtCore/QMultiHash>
+#include <QtCore/QString>
+
+class PYSIDETEST_API ContainerTest
+{
+public:
+ ContainerTest();
+
+ static QMultiMap<int, QString> createMultiMap();
+
+ static QMultiMap<int, QString> passThroughMultiMap(const QMultiMap<int, QString> &in);
+
+ static QMultiHash<int, QString> createMultiHash();
+
+ static QMultiHash<int, QString> passThroughMultiHash(const QMultiHash<int, QString> &in);
+};
diff --git a/sources/pyside6/tests/pysidetest/pysidetest_global.h b/sources/pyside6/tests/pysidetest/pysidetest_global.h
index 6f9b187ba..61dee53d9 100644
--- a/sources/pyside6/tests/pysidetest/pysidetest_global.h
+++ b/sources/pyside6/tests/pysidetest/pysidetest_global.h
@@ -30,6 +30,7 @@
#define PYSIDETEST_GLOBAL_H
// PySide global.h file
+#include "containertest.h"
#include "testobject.h"
#include "testview.h"
#include "flagstest.h"
diff --git a/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml b/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml
index c959e7fd3..2736f8319 100644
--- a/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml
+++ b/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml
@@ -35,6 +35,8 @@
qRegisterMetaType&lt;PySideCPP2::PySideLong>("PySideLong");
</inject-code>
+ <object-type name="ContainerTest"/>
+
<namespace-type name="PySideCPP">
<object-type name="TestObjectWithNamespace"/>
<object-type name="TestObject2WithNamespace">