From 6389561fd75e80c69d7c83f6a87d988450a2e569 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 16 Apr 2021 10:19:17 +0200 Subject: Add a numpy overload for some functions taking lists of QPointF Add functions taking x,y data in the form of numpy-vectors (as common for matplotlib, etc) for: QPainter::drawPoints() QXYSeries::append(), QXYSeries::replace() They are added as separate functions instead of overloads since there is a restriction in that numpy arrays cause an error: FIXME Subscripted generics cannot be used with class and instance checks when passed to other type check macros. Task-number: PYSIDE-1540 Task-number: PYSIDE-1503 Change-Id: Ie1521ce19127bb0641fbdb4f7320a8707682724e Reviewed-by: Christian Tismer Reviewed-by: Cristian Maureira-Fredes --- sources/pyside6/PySide6/QtCharts/typesystem_charts.xml | 13 ++++++++++++- sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml | 8 ++++++++ sources/pyside6/PySide6/glue/qtcharts.cpp | 10 ++++++++++ sources/pyside6/PySide6/glue/qtgui.cpp | 5 +++++ sources/pyside6/tests/QtGui/qpainter_test.py | 12 ++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/sources/pyside6/PySide6/QtCharts/typesystem_charts.xml b/sources/pyside6/PySide6/QtCharts/typesystem_charts.xml index 643201f6d..6a325431b 100644 --- a/sources/pyside6/PySide6/QtCharts/typesystem_charts.xml +++ b/sources/pyside6/PySide6/QtCharts/typesystem_charts.xml @@ -266,5 +266,16 @@ - + + + + + + + + + + diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml index 3db662a8f..4a230d5df 100644 --- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml +++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml @@ -45,6 +45,7 @@ + @@ -1745,6 +1746,7 @@ + @@ -1793,6 +1795,12 @@ + + + + diff --git a/sources/pyside6/PySide6/glue/qtcharts.cpp b/sources/pyside6/PySide6/glue/qtcharts.cpp index 1828fecc0..7171f19df 100644 --- a/sources/pyside6/PySide6/glue/qtcharts.cpp +++ b/sources/pyside6/PySide6/glue/qtcharts.cpp @@ -40,3 +40,13 @@ // @snippet qchart-releaseownership Shiboken::Object::releaseOwnership(%PYARG_1); // @snippet qchart-releaseownership + +// @snippet qxyseries-appendnp-numpy-x-y +const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); +%CPPSELF.append(points); +// @snippet qxyseries-appendnp-numpy-x-y + +// @snippet qxyseries-replacenp-numpy-x-y +const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); +%CPPSELF.replace(points); +// @snippet qxyseries-replacenp-numpy-x-y diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp index c0323ad0f..28d7c468e 100644 --- a/sources/pyside6/PySide6/glue/qtgui.cpp +++ b/sources/pyside6/PySide6/glue/qtgui.cpp @@ -458,6 +458,11 @@ PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_)); PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1)); // @snippet qclipboard-text +// @snippet qpainter-drawpointsnp-numpy-x-y +const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); +%CPPSELF.drawPoints(points); +// @snippet qpainter-drawpointsnp-numpy-x-y + // @snippet qpainter-drawpolygon %CPPSELF.%FUNCTION_NAME(%1.data(), %1.size(), %2); // @snippet qpainter-drawpolygon diff --git a/sources/pyside6/tests/QtGui/qpainter_test.py b/sources/pyside6/tests/QtGui/qpainter_test.py index b05189d01..752475494 100644 --- a/sources/pyside6/tests/QtGui/qpainter_test.py +++ b/sources/pyside6/tests/QtGui/qpainter_test.py @@ -40,6 +40,13 @@ from PySide6.QtGui import QPainter, QLinearGradient, QImage from PySide6.QtCore import QLine, QLineF, QPoint, QPointF, QRect, QRectF, Qt +try: + import numpy as np + HAVE_NUMPY = True +except ModuleNotFoundError: + HAVE_NUMPY = False + + class QPainterDrawText(UsesQGuiApplication): def setUp(self): super(QPainterDrawText, self).setUp() @@ -109,6 +116,11 @@ class QPainterDrawText(UsesQGuiApplication): QPoint(20.0, 10.0), QPoint(80.0, 30.0), QPoint(90.0, 70.0)]) + if HAVE_NUMPY: + x = np.array([10.0, 20.0, 80.0, 90.0]) + y = np.array([80.0, 10.0, 30.0, 70.0]) + self.painter.drawPointsNp(x, y) + class SetBrushWithOtherArgs(UsesQGuiApplication): -- cgit v1.2.3