aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-27 10:32:07 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-28 16:32:03 +0200
commit0de9cda236715bf52b863ea14dc5d4fb824eae5b (patch)
tree9e753896449b519746967fd02b4a9fed26e26524 /sources
parent8e9c64ce3ead94d31178ace3e2192ea93649387e (diff)
PySide6: Fix QFlags comparison to self
The result was set to true unconditionally when self == other. Fix and rearrange the code. Fixes: PYSIDE-1696 Change-Id: I8892d0f6439186d8629c5a24347fc1ce700ecb58 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 9399408fd1e7e12215389a5bf96ae5e4ec38905b)
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/libpyside/pysideqflags.cpp13
-rw-r--r--sources/pyside2/tests/pysidetest/enum_test.py24
2 files changed, 33 insertions, 4 deletions
diff --git a/sources/pyside2/libpyside/pysideqflags.cpp b/sources/pyside2/libpyside/pysideqflags.cpp
index f587026ac..a716cacfc 100644
--- a/sources/pyside2/libpyside/pysideqflags.cpp
+++ b/sources/pyside2/libpyside/pysideqflags.cpp
@@ -81,12 +81,17 @@ extern "C" {
return NULL;
}
- long valA = PYSIDE_QFLAGS(self)->ob_value;
- long valB = getNumberValue(other);
-
if (self == other) {
- result = 1;
+ switch (op) {
+ case Py_EQ:
+ case Py_LE:
+ case Py_GE:
+ result = 1;
+ break;
+ }
} else {
+ const long valA = PYSIDE_QFLAGS(self)->ob_value;
+ const long valB = getNumberValue(other);
switch (op) {
case Py_EQ:
result = (valA == valB);
diff --git a/sources/pyside2/tests/pysidetest/enum_test.py b/sources/pyside2/tests/pysidetest/enum_test.py
index d179d6248..a9396383e 100644
--- a/sources/pyside2/tests/pysidetest/enum_test.py
+++ b/sources/pyside2/tests/pysidetest/enum_test.py
@@ -36,6 +36,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from init_paths import init_test_paths
init_test_paths(True)
+from PySide2.QtCore import Qt
from testbinding import Enum1, TestObjectWithoutNamespace
class ListConnectionTest(unittest.TestCase):
@@ -46,6 +47,29 @@ class ListConnectionTest(unittest.TestCase):
self.assertEqual(TestObjectWithoutNamespace.Enum2.Option3, 3)
self.assertEqual(TestObjectWithoutNamespace.Enum2.Option4, 4)
+ def testFlagComparisonOperators(self): # PYSIDE-1696, compare to self
+ f1 = Qt.AlignHCenter | Qt.AlignBottom
+ f2 = Qt.AlignHCenter | Qt.AlignBottom
+ self.assertTrue(f1 == f1)
+ self.assertTrue(f1 <= f1)
+ self.assertTrue(f1 >= f1)
+ self.assertFalse(f1 != f1)
+ self.assertFalse(f1 < f1)
+ self.assertFalse(f1 > f1)
+
+ self.assertTrue(f1 == f2)
+ self.assertTrue(f1 <= f2)
+ self.assertTrue(f1 >= f2)
+ self.assertFalse(f1 != f2)
+ self.assertFalse(f1 < f2)
+ self.assertFalse(f1 > f2)
+
+ self.assertTrue(Qt.AlignHCenter < Qt.AlignBottom)
+ self.assertFalse(Qt.AlignHCenter > Qt.AlignBottom)
+ self.assertFalse(Qt.AlignBottom < Qt.AlignHCenter)
+ self.assertTrue(Qt.AlignBottom > Qt.AlignHCenter)
+
+
if __name__ == '__main__':
unittest.main()