diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-24 12:03:50 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-25 09:19:30 +0100 |
commit | 308aba2154699596e3fd0973501213423462a80b (patch) | |
tree | 1fe6fe905c3681042e2af27e025256b1593c52b7 /sources/pyside2/PySide2/glue/qtcore.cpp | |
parent | 3a2072075af39278529ff9d1201be3bcaadfb349 (diff) |
PySide2: Use int for QVariant conversion when possible
Check using the init limits in the QVariant long long conversion
and create an int if possible. This works more smoothly with
Qt and for example ensures that the correct editor is created in
item views.
Change-Id: I0ca2e5e7b91f309deaa81a25e70a5f894f43f841
Fixes: PYSIDE-1250
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2/glue/qtcore.cpp')
-rw-r--r-- | sources/pyside2/PySide2/glue/qtcore.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index b870afa55..60ddf675c 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -43,6 +43,7 @@ // @snippet include-pyside #include <pyside.h> +#include <limits> // @snippet include-pyside // @snippet pystring-check @@ -1716,8 +1717,11 @@ int i = %CONVERTTOCPP[int](%in); // @snippet conversion-pyint // @snippet conversion-qlonglong +// PYSIDE-1250: For QVariant, if the type fits into an int; use int preferably. qlonglong in = %CONVERTTOCPP[qlonglong](%in); -%out = %OUTTYPE(in); +constexpr qlonglong intMax = qint64(std::numeric_limits<int>::max()); +constexpr qlonglong intMin = qint64(std::numeric_limits<int>::min()); +%out = in >= intMin && in <= intMax ? %OUTTYPE(int(in)) : %OUTTYPE(in); // @snippet conversion-qlonglong // @snippet conversion-qstring |