From 6feab2b639d32693ad14306529bf72194c1be355 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 10 Jun 2021 14:07:04 +0200 Subject: PySide6/QSignalSpy: Add constructor taking a signal Task-number: PYSIDE-1482 Change-Id: Ifb9061af1828e7348de3ad5407c830aeb7d4f386 Reviewed-by: Cristian Maureira-Fredes (cherry picked from commit d3388316c3ac87c19cc668d9b5bca2b988db74ca) Reviewed-by: Qt Cherry-pick Bot --- .../PySide6/QtCore/typesystem_core_common.xml | 2 + sources/pyside6/PySide6/QtTest/typesystem_test.xml | 9 ++++ sources/pyside6/PySide6/glue/qttest.cpp | 60 ++++++++++++++++++++++ sources/pyside6/tests/QtTest/qsignalspy_test.py | 5 ++ 4 files changed, 76 insertions(+) create mode 100644 sources/pyside6/PySide6/glue/qttest.cpp diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index 1a7e7b8d8..bec575e54 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -51,6 +51,8 @@ + diff --git a/sources/pyside6/PySide6/QtTest/typesystem_test.xml b/sources/pyside6/PySide6/QtTest/typesystem_test.xml index 20dcf3672..ea480bbf2 100644 --- a/sources/pyside6/PySide6/QtTest/typesystem_test.xml +++ b/sources/pyside6/PySide6/QtTest/typesystem_test.xml @@ -107,9 +107,18 @@ + + + + + + + Constructs a new QSignalSpy that listens for emissions of the signal. + + diff --git a/sources/pyside6/PySide6/glue/qttest.cpp b/sources/pyside6/PySide6/glue/qttest.cpp new file mode 100644 index 000000000..4fea0a98c --- /dev/null +++ b/sources/pyside6/PySide6/glue/qttest.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/********************************************************************* + * INJECT CODE + ********************************************************************/ + +// @snippet qsignalspy-signal +auto *signalInst = reinterpret_cast(%PYARG_1); +PyObject *emitterPyObject = PySide::Signal::getObject(signalInst); +QObject* emitter = %CONVERTTOCPP[QObject *](emitterPyObject); +QByteArray signature = PySide::Signal::getSignature(signalInst); +if (!signature.isEmpty()) + signature.prepend('2'); // SIGNAL() macro + +if (emitter == nullptr || signature.isEmpty()) { + QByteArray error = QByteArrayLiteral("Wrong parameter (") + + (%PYARG_1)->ob_type->tp_name + + QByteArrayLiteral(") passed, QSignalSpy requires a signal."); + PyErr_SetString(PyExc_ValueError, error.constData()); + return -1; +} +%0 = new QSignalSpyWrapper(emitter, signature.constData()); +// @snippet qsignalspy-signal diff --git a/sources/pyside6/tests/QtTest/qsignalspy_test.py b/sources/pyside6/tests/QtTest/qsignalspy_test.py index 4e5786ed6..aa1b65bfa 100644 --- a/sources/pyside6/tests/QtTest/qsignalspy_test.py +++ b/sources/pyside6/tests/QtTest/qsignalspy_test.py @@ -57,6 +57,11 @@ class QSignalSpyTest(UsesQApplication): self._model.item(0, 0).setText('text2') self.assertEqual(spy.count(), 1) + def testSignal(self): + spy = QSignalSpy(self._model.dataChanged) + self._model.item(0, 0).setText('text3') + self.assertEqual(spy.count(), 1) + if __name__ == '__main__': unittest.main() -- cgit v1.2.3