aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml27
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp5
-rw-r--r--sources/pyside6/tests/QtCore/CMakeLists.txt1
-rw-r--r--sources/pyside6/tests/QtCore/loggingcategorymacros_test.py109
4 files changed, 142 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index d2d2f9658..8c717c268 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -3192,6 +3192,33 @@
<object-type name="QLoggingCategory"/>
+ <add-function signature="qCDebug(PyObject *, const char *)">
+ <extra-includes>
+ <include file-name="qloggingcategory.h" location="global" />
+ </extra-includes>
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qloggingcategory_to_cpp">
+ qCDebug(*category, %2);
+ </inject-code>
+ </add-function>
+
+ <add-function signature="qCCritical(PyObject *, const char *)">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qloggingcategory_to_cpp">
+ qCCritical(*category, %2);
+ </inject-code>
+ </add-function>
+
+ <add-function signature="qCInfo(PyObject *, const char *)">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qloggingcategory_to_cpp">
+ qCInfo(*category, %2);
+ </inject-code>
+ </add-function>
+
+ <add-function signature="qCWarning(PyObject *, const char *)">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qloggingcategory_to_cpp">
+ qCWarning(*category, %2);
+ </inject-code>
+ </add-function>
+
<suppress-warning text="^.*enum 'Qt::Initialization' does not have a type entry.*$"/>
<suppress-warning text="^.*Enum 'QRandomGenerator::System'.*does not have a type entry.*$"/>
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index b856d910b..c6d1192ae 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -1577,3 +1577,8 @@ if (dataChar == nullptr) {
}
// @snippet qdatastream-read-bytes
+// @snippet qloggingcategory_to_cpp
+ QLoggingCategory *category{nullptr};
+ Shiboken::Conversions::pythonToCppPointer(SbkPySide6_QtCoreTypes[SBK_QLOGGINGCATEGORY_IDX],
+ pyArgs[0], &(category));
+// @snippet qloggingcategory_to_cpp
diff --git a/sources/pyside6/tests/QtCore/CMakeLists.txt b/sources/pyside6/tests/QtCore/CMakeLists.txt
index 576c429e6..59f4161cb 100644
--- a/sources/pyside6/tests/QtCore/CMakeLists.txt
+++ b/sources/pyside6/tests/QtCore/CMakeLists.txt
@@ -135,6 +135,7 @@ PYSIDE_TEST(translation_test.py)
PYSIDE_TEST(unaryoperator_test.py)
PYSIDE_TEST(unicode_test.py)
PYSIDE_TEST(versioninfo_test.py)
+PYSIDE_TEST(loggingcategorymacros_test.py)
if(X11)
PYSIDE_TEST(qhandle_test.py)
diff --git a/sources/pyside6/tests/QtCore/loggingcategorymacros_test.py b/sources/pyside6/tests/QtCore/loggingcategorymacros_test.py
new file mode 100644
index 000000000..c59bef46b
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/loggingcategorymacros_test.py
@@ -0,0 +1,109 @@
+#############################################################################
+##
+## Copyright (C) 2022 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$
+##
+#############################################################################
+
+"""Tests for category logging macros qCDebug, qCInfo, qCWarning, qCCritical"""
+
+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(False)
+
+from PySide6.QtCore import (QLoggingCategory, QtMsgType, qCDebug, qCWarning, qCInfo,
+ qCCritical, qInstallMessageHandler)
+
+param = None
+
+def handler(msgt, ctx, msg):
+ global param
+ param = ctx.category + ": " + msg.strip()
+
+
+class TestQLoggingCategory(unittest.TestCase):
+ def setUp(self) -> None:
+ super().setUp()
+ self.defaultCategory = QLoggingCategory("default")
+ self.debugCategory = QLoggingCategory("debug.log", QtMsgType.QtDebugMsg)
+ self.infoCategory = QLoggingCategory("info.log", QtMsgType.QtInfoMsg)
+ self.warningCategory = QLoggingCategory("warning.log", QtMsgType.QtWarningMsg)
+ self.criticalCategory = QLoggingCategory("critical.log", QtMsgType.QtCriticalMsg)
+ qInstallMessageHandler(handler)
+ self.no_devices = 2
+
+ def test_qCDebug(self):
+ qCDebug(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCDebug(self.debugCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+
+ # not updated because category is Info which is above Debug
+ # nothing will be printed here
+ qCDebug(self.infoCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+
+ def test_qCInfo(self):
+ qCInfo(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCInfo(self.debugCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+ qCInfo(self.infoCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "info.log: devices: 2")
+
+ # not updated because category is Warning which is above Info
+ # nothing will be printed here
+ qCInfo(self.warningCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "info.log: devices: 2")
+
+ def test_qCWarning(self):
+ qCWarning(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCWarning(self.debugCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+ qCWarning(self.warningCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "warning.log: devices: 2")
+
+ # not updated because category is Critical which is above Warning
+ # nothing will be printed here
+ qCWarning(self.criticalCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "warning.log: devices: 2")
+
+
+ def test_qCritical(self):
+ qCCritical(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCCritical(self.warningCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "warning.log: devices: 2")
+ qCCritical(self.criticalCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "critical.log: devices: 2")
+
+
+if __name__ == '__main__':
+ unittest.main()