diff options
| author | Ece Cinucen <ece.cinucen@qt.io> | 2024-11-14 12:22:59 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-11-14 13:02:28 +0000 |
| commit | 649592a8cbc9c656a7b9be77f043538bf4e242d5 (patch) | |
| tree | 7d13707203d3bde6eef4b5b5f57cabcf82212bc0 /sources/pyside6 | |
| parent | fcd6d2ee101e0d5a16f60c3c8edde455d674edd5 (diff) | |
PySide: Add numpy support for QtGraphs
Added appendNp and replaceNp
Added test for appendNp and replaceNp
Added the missing file "qcharts_numpy_test.py" to QtCharts .pyproject
Pick-to: 6.8 6.8.1 6.5
Change-Id: I55aeba0fd117a8a82c3f69e18a50358936610af9
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6')
5 files changed, 71 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtGraphs/typesystem_graphs.xml b/sources/pyside6/PySide6/QtGraphs/typesystem_graphs.xml index a582ece66..0f16a39ec 100644 --- a/sources/pyside6/PySide6/QtGraphs/typesystem_graphs.xml +++ b/sources/pyside6/PySide6/QtGraphs/typesystem_graphs.xml @@ -184,6 +184,22 @@ <object-type name="QScatterSeries"/> <object-type name="QXYModelMapper" since="6.8"/> <object-type name="QXYSeries"> + <enum-type name="PointConfiguration"/> + <include file-name="pyside_numpy.h" location="global"/> + <add-function signature="appendNp(PyArrayObject *@x@, PyArrayObject *@y@)"> + <inject-code file="../glue/qtcharts.cpp" snippet="qxyseries-appendnp-numpy-x-y"/> + <inject-documentation format="target" mode="append"> + Adds the list of data points specified by two + one-dimensional, equally sized numpy arrays representing the x, y values, respectively. + </inject-documentation> + </add-function> + <add-function signature="replaceNp(PyArrayObject *@x@, PyArrayObject *@y@)"> + <inject-code file="../glue/qtcharts.cpp" snippet="qxyseries-replacenp-numpy-x-y"/> + <inject-documentation format="target" mode="append"> + Replaces the current points with the points specified by two + one-dimensional, equally sized numpy arrays representing the x, y values, respectively. + </inject-documentation> + </add-function> </object-type> <extra-includes> diff --git a/sources/pyside6/tests/QtCharts/QtCharts.pyproject b/sources/pyside6/tests/QtCharts/QtCharts.pyproject index 6f2bd66f2..a0e12e0c4 100644 --- a/sources/pyside6/tests/QtCharts/QtCharts.pyproject +++ b/sources/pyside6/tests/QtCharts/QtCharts.pyproject @@ -1,3 +1,4 @@ { - "files": ["qcharts_test.py"] + "files": ["qcharts_test.py", + "qcharts_numpy_test.py"] } diff --git a/sources/pyside6/tests/QtGraphs/CMakeLists.txt b/sources/pyside6/tests/QtGraphs/CMakeLists.txt index 2f7cb08b9..0b153a6e2 100644 --- a/sources/pyside6/tests/QtGraphs/CMakeLists.txt +++ b/sources/pyside6/tests/QtGraphs/CMakeLists.txt @@ -1 +1 @@ -# Please add some tests, here +PYSIDE_TEST(qgraphs_numpy_test.py) diff --git a/sources/pyside6/tests/QtGraphs/QtGraphs.pyproject b/sources/pyside6/tests/QtGraphs/QtGraphs.pyproject new file mode 100644 index 000000000..b15b05b6c --- /dev/null +++ b/sources/pyside6/tests/QtGraphs/QtGraphs.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["qgraphs_numpy_test.py"] +} diff --git a/sources/pyside6/tests/QtGraphs/qgraphs_numpy_test.py b/sources/pyside6/tests/QtGraphs/qgraphs_numpy_test.py new file mode 100644 index 000000000..0b3419bf2 --- /dev/null +++ b/sources/pyside6/tests/QtGraphs/qgraphs_numpy_test.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +from __future__ import annotations + +'''Test cases for QGraphs/numpy''' + +import os +import sys +import unittest +try: + import numpy as np + HAVE_NUMPY = True +except ModuleNotFoundError: + HAVE_NUMPY = False + +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 helper.usesqapplication import UsesQApplication +from PySide6.QtGraphs import QLineSeries + + +@unittest.skipUnless(HAVE_NUMPY, "requires numpy") +class QGraphsNumpyTestCase(UsesQApplication): + '''Tests related to QGraphs/numpy''' + + def test(self): + """PYSIDE-2313: Verify various types.""" + line_series = QLineSeries() + data_types = [np.short, np.ushort, np.int32, np.uint32, + np.int64, np.uint64, np.float32, np.float64] + for dt in data_types: + print("Testing ", dt) + old_size = line_series.count() + x_arr = np.array([2], dtype=dt) + y_arr = np.array([3], dtype=dt) + line_series.appendNp(x_arr, y_arr) + size = line_series.count() + self.assertEqual(size, old_size + 1) + point = line_series.points()[size - 1] + self.assertEqual(point.x(), 2) + self.assertEqual(point.y(), 3) + + +if __name__ == '__main__': + unittest.main() |
