diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-23 07:37:33 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-23 07:37:33 +0200 |
| commit | 6fcccf20dab907aa037cd9737b6349b2cad3323f (patch) | |
| tree | 7398fcfb28840ee4a2e55110ca30eea0456ade5d | |
| parent | b10e77f3e518979c9bae492d2f7a2f03eff06af2 (diff) | |
| parent | cacfabc03198b1bcd314d4ebdb0b7e06dfe097ff (diff) | |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I478e94aa42c9f79011edf97f19a7abebb7214421
| -rw-r--r-- | sources/pyside2/PySide2/QtUiTools/glue/plugins.h | 32 | ||||
| -rw-r--r-- | sources/pyside2/doc/extras/QtCore.Property.rst | 48 | ||||
| -rw-r--r-- | sources/pyside2/plugins/customwidget.cpp | 66 | ||||
| -rw-r--r-- | sources/pyside2/plugins/customwidget.h | 44 | ||||
| -rw-r--r-- | sources/pyside2/plugins/customwidgets.cpp | 34 | ||||
| -rw-r--r-- | sources/pyside2/plugins/customwidgets.h | 22 | ||||
| -rw-r--r-- | sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp | 18 | ||||
| -rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 11 | ||||
| -rw-r--r-- | sources/shiboken2/tests/libsample/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | sources/shiboken2/tests/libsample/oddbool.cpp | 48 | ||||
| -rw-r--r-- | sources/shiboken2/tests/libsample/oddbool.h | 27 | ||||
| -rw-r--r-- | sources/shiboken2/tests/samplebinding/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | sources/shiboken2/tests/samplebinding/oddbool_test.py | 8 | ||||
| -rw-r--r-- | sources/shiboken2/tests/samplebinding/typesystem_sample.xml | 17 |
14 files changed, 214 insertions, 163 deletions
diff --git a/sources/pyside2/PySide2/QtUiTools/glue/plugins.h b/sources/pyside2/PySide2/QtUiTools/glue/plugins.h index 9bfcec6ea..402965a81 100644 --- a/sources/pyside2/PySide2/QtUiTools/glue/plugins.h +++ b/sources/pyside2/PySide2/QtUiTools/glue/plugins.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt for Python. @@ -40,26 +40,28 @@ #ifndef _PLUGIN_H_ #define _PLUGIN_H_ -#include <QPluginLoader> #include "customwidgets.h" -inline void registerCustomWidget(PyObject *obj) -{ - static PyCustomWidgets *plugin = nullptr; +#include <QtCore/qpluginloader.h> - if (plugin == 0) { - const auto &instances = QPluginLoader::staticInstances(); - for (QObject *o : instances) { - plugin = qobject_cast<PyCustomWidgets *>(o); - if (plugin) - break; - } +static inline PyCustomWidgets *findPlugin() +{ + const auto &instances = QPluginLoader::staticInstances(); + for (QObject *o : instances) { + if (auto plugin = qobject_cast<PyCustomWidgets *>(o)) + return plugin; } + return nullptr; +} - if (!plugin) - qDebug() << "Failed to load uiloader plugin."; - else +static void registerCustomWidget(PyObject *obj) +{ + static PyCustomWidgets *const plugin = findPlugin(); + + if (plugin) plugin->registerWidgetType(obj); + else + qWarning("Qt for Python: Failed to find the static QUiLoader plugin."); } #endif diff --git a/sources/pyside2/doc/extras/QtCore.Property.rst b/sources/pyside2/doc/extras/QtCore.Property.rst index 209704c46..a10c9f807 100644 --- a/sources/pyside2/doc/extras/QtCore.Property.rst +++ b/sources/pyside2/doc/extras/QtCore.Property.rst @@ -16,24 +16,24 @@ function: .. code-block:: :linenos: -from PySide2.QtCore import QObject, Property + from PySide2.QtCore import QObject, Property -class MyObject(QObject): - def __init__(self,startval=42): - QObject.__init__(self) - self.ppval = startval + class MyObject(QObject): + def __init__(self,startval=42): + QObject.__init__(self) + self.ppval = startval - def readPP(self): - return self.ppval + def readPP(self): + return self.ppval - def setPP(self,val): - self.ppval = val + def setPP(self,val): + self.ppval = val - pp = Property(int, readPP, setPP) + pp = Property(int, readPP, setPP) -obj = MyObject() -obj.pp = 47 -print(obj.pp) + obj = MyObject() + obj.pp = 47 + print(obj.pp) Properties in QML expressions ----------------------------- @@ -45,18 +45,18 @@ example illustrating how to do this: .. code-block:: :linenos: -from PySide2.QtCore import QObject, Signal, Property + from PySide2.QtCore import QObject, Signal, Property -class Person(QObject): - def __init__(self, name): - QObject.__init__(self) - self._person_name = name + class Person(QObject): + def __init__(self, name): + QObject.__init__(self) + self._person_name = name - def _name(self): - return self._person_name + def _name(self): + return self._person_name - @Signal - def name_changed(self): - pass + @Signal + def name_changed(self): + pass - name = Property(str, _name, notify=name_changed) + name = Property(str, _name, notify=name_changed) diff --git a/sources/pyside2/plugins/customwidget.cpp b/sources/pyside2/plugins/customwidget.cpp index 6a6d7a3be..3c54b02e4 100644 --- a/sources/pyside2/plugins/customwidget.cpp +++ b/sources/pyside2/plugins/customwidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt for Python. @@ -37,26 +37,15 @@ ** ****************************************************************************/ - #include "customwidget.h" +#include <QtCore/qdebug.h> - -struct PyCustomWidgetPrivate -{ - PyObject *pyObject; - bool initialized; -}; - -PyCustomWidget::PyCustomWidget(PyObject *objectType) - : m_data(new PyCustomWidgetPrivate()) +// Part of the static plugin linked to the QtUiLoader Python module, +// allowing it to create a custom widget written in Python. +PyCustomWidget::PyCustomWidget(PyObject *objectType) : + m_pyObject(objectType), + m_name(QString::fromUtf8(reinterpret_cast<PyTypeObject *>(objectType)->tp_name)) { - m_data->pyObject = objectType; - m_name = QString(reinterpret_cast<PyTypeObject *>(objectType)->tp_name); -} - -PyCustomWidget::~PyCustomWidget() -{ - delete m_data; } bool PyCustomWidget::isContainer() const @@ -66,7 +55,7 @@ bool PyCustomWidget::isContainer() const bool PyCustomWidget::isInitialized() const { - return m_data->initialized; + return m_initialized; } QIcon PyCustomWidget::icon() const @@ -106,9 +95,9 @@ QString PyCustomWidget::whatsThis() const QWidget *PyCustomWidget::createWidget(QWidget *parent) { - //Create a python instance and return cpp object - PyObject *pyParent; - bool unkowParent = false; + // Create a python instance and return cpp object + PyObject *pyParent = nullptr; + bool unknownParent = false; if (parent) { pyParent = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(parent)); if (pyParent) { @@ -116,7 +105,7 @@ QWidget *PyCustomWidget::createWidget(QWidget *parent) } else { static Shiboken::Conversions::SpecificConverter converter("QWidget*"); pyParent = converter.toPython(&parent); - unkowParent = true; + unknownParent = true; } } else { Py_INCREF(Py_None); @@ -124,25 +113,26 @@ QWidget *PyCustomWidget::createWidget(QWidget *parent) } Shiboken::AutoDecRef pyArgs(PyTuple_New(1)); - PyTuple_SET_ITEM(pyArgs, 0, pyParent); //tuple will keep pyParent reference - - //Call python constructor - auto result = reinterpret_cast<SbkObject *>(PyObject_CallObject(m_data->pyObject, pyArgs)); - - QWidget *widget = nullptr; - if (result) { - if (unkowParent) //if parent does not exists in python, transfer the ownership to cpp - Shiboken::Object::releaseOwnership(result); - else - Shiboken::Object::setParent(pyParent, reinterpret_cast<PyObject *>(result)); - - widget = reinterpret_cast<QWidget *>(Shiboken::Object::cppPointer(result, Py_TYPE(result))); + PyTuple_SET_ITEM(pyArgs, 0, pyParent); // tuple will keep pyParent reference + + // Call python constructor + auto result = reinterpret_cast<SbkObject *>(PyObject_CallObject(m_pyObject, pyArgs)); + if (!result) { + qWarning("Unable to create a Python custom widget of type \"%s\".", + qPrintable(m_name)); + PyErr_Print(); + return nullptr; } - return widget; + if (unknownParent) // if parent does not exist in python, transfer the ownership to cpp + Shiboken::Object::releaseOwnership(result); + else + Shiboken::Object::setParent(pyParent, reinterpret_cast<PyObject *>(result)); + + return reinterpret_cast<QWidget *>(Shiboken::Object::cppPointer(result, Py_TYPE(result))); } void PyCustomWidget::initialize(QDesignerFormEditorInterface *core) { - m_data->initialized = true; + m_initialized = true; } diff --git a/sources/pyside2/plugins/customwidget.h b/sources/pyside2/plugins/customwidget.h index fc7d08941..b84a967bf 100644 --- a/sources/pyside2/plugins/customwidget.h +++ b/sources/pyside2/plugins/customwidget.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt for Python. @@ -42,15 +42,9 @@ #include <shiboken.h> -#include <QtCore/QtGlobal> -#if (QT_VERSION < QT_VERSION_CHECK(5, 5, 0)) - #include <QtDesigner/QDesignerCustomWidgetInterface> -#else - #include <QtUiPlugin/QDesignerCustomWidgetInterface> -#endif +#include <QtUiPlugin/QDesignerCustomWidgetInterface> - -struct PyCustomWidgetPrivate; +#include <QtCore/qglobal.h> class PyCustomWidget: public QObject, public QDesignerCustomWidgetInterface { @@ -58,24 +52,24 @@ class PyCustomWidget: public QObject, public QDesignerCustomWidgetInterface Q_INTERFACES(QDesignerCustomWidgetInterface) public: - PyCustomWidget(PyObject* objectType); - ~PyCustomWidget(); + explicit PyCustomWidget(PyObject *objectType); - bool isContainer() const; - bool isInitialized() const; - QIcon icon() const; - QString domXml() const; - QString group() const; - QString includeFile() const; - QString name() const; - QString toolTip() const; - QString whatsThis() const; - QWidget *createWidget(QWidget *parent); - void initialize(QDesignerFormEditorInterface *core); + bool isContainer() const override; + bool isInitialized() const override; + QIcon icon() const override; + QString domXml() const override; + QString group() const override; + QString includeFile() const override; + QString name() const override; + QString toolTip() const override; + QString whatsThis() const override; + QWidget *createWidget(QWidget *parent) override; + void initialize(QDesignerFormEditorInterface *core) override; private: - PyCustomWidgetPrivate* m_data; - QString m_name; + PyObject *m_pyObject = nullptr; + const QString m_name; + bool m_initialized = false; }; -#endif +#endif // _PY_CUSTOM_WIDGET_H_ diff --git a/sources/pyside2/plugins/customwidgets.cpp b/sources/pyside2/plugins/customwidgets.cpp index e78dde206..28a2a6cf6 100644 --- a/sources/pyside2/plugins/customwidgets.cpp +++ b/sources/pyside2/plugins/customwidgets.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt for Python. @@ -37,47 +37,25 @@ ** ****************************************************************************/ -#include "customwidget.h" #include "customwidgets.h" - - -struct PyCustomWidgetPrivate -{ - PyObject *pyObject; - bool initialized; -}; - -struct PyCustomWidgetsPrivate -{ - QList<QDesignerCustomWidgetInterface *> widgets; - ~PyCustomWidgetsPrivate(); -}; - - -PyCustomWidgetsPrivate::~PyCustomWidgetsPrivate() -{ - qDeleteAll(widgets); - widgets.clear(); -} +#include "customwidget.h" PyCustomWidgets::PyCustomWidgets(QObject *parent) - : QObject(parent), m_data(new PyCustomWidgetsPrivate) + : QObject(parent) { } PyCustomWidgets::~PyCustomWidgets() { - delete m_data; + qDeleteAll(m_widgets); } void PyCustomWidgets::registerWidgetType(PyObject *widget) { - m_data->widgets.append(new PyCustomWidget(widget)); + m_widgets.append(new PyCustomWidget(widget)); } QList<QDesignerCustomWidgetInterface *> PyCustomWidgets::customWidgets() const { - return m_data->widgets; + return m_widgets; } - - diff --git a/sources/pyside2/plugins/customwidgets.h b/sources/pyside2/plugins/customwidgets.h index 5c52d1d25..aec817cdf 100644 --- a/sources/pyside2/plugins/customwidgets.h +++ b/sources/pyside2/plugins/customwidgets.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt for Python. @@ -42,16 +42,11 @@ #include <shiboken.h> -#include <QtCore/QtGlobal> -#if (QT_VERSION < QT_VERSION_CHECK(5, 5, 0)) - #include <QtDesigner/QDesignerCustomWidgetInterface> -#else - #include <QtUiPlugin/QDesignerCustomWidgetInterface> -#endif - +#include <QtUiPlugin/QDesignerCustomWidgetInterface> -struct PyCustomWidgetsPrivate; +#include <QtCore/qlist.h> +// A static plugin linked to the QtUiLoader Python module class PyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface { Q_OBJECT @@ -59,13 +54,16 @@ class PyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInt Q_PLUGIN_METADATA(IID "org.qt-project.Qt.PySide.PyCustomWidgetsInterface") public: - PyCustomWidgets(QObject *parent = 0); + explicit PyCustomWidgets(QObject *parent = nullptr); ~PyCustomWidgets(); - virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const; + + QList<QDesignerCustomWidgetInterface*> customWidgets() const override; + + // Called from added function QUiLoader::registerCustomWidget() void registerWidgetType(PyObject* widget); private: - PyCustomWidgetsPrivate* m_data; + QList<QDesignerCustomWidgetInterface *> m_widgets; }; #endif diff --git a/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp b/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp index dc4801e18..496b55aaa 100644 --- a/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp @@ -78,8 +78,6 @@ void TestReverseOperators::testReverseSumWithAmbiguity() struct B {};\n\ B operator+(const A&, const B&);\n\ B operator+(const B&, const A&);\n\ - int operator-(int, const A*);\n\ - int operator/(const A*, int);\n\ "; const char xmlCode[] = "\n\ <typesystem package=\"Foo\">\n\ @@ -89,12 +87,11 @@ void TestReverseOperators::testReverseSumWithAmbiguity() </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QEXPECT_FAIL("", "Clang: Does not compile", Abort); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); QVERIFY(classA); - QCOMPARE(classA->functions().count(), 6); + QCOMPARE(classA->functions().count(), 4); const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); QVERIFY(classB); @@ -118,19 +115,6 @@ void TestReverseOperators::testReverseSumWithAmbiguity() QVERIFY(reverseOp->isReverseOperator()); QCOMPARE(reverseOp->arguments().count(), 1); QCOMPARE(reverseOp->minimalSignature(), QLatin1String("operator+(A,B)")); - - reverseOp = classA->findFunction(QLatin1String("operator-")); - QVERIFY(reverseOp); - QCOMPARE(reverseOp->arguments().count(), 1); - QVERIFY(reverseOp->isPointerOperator()); - QVERIFY(reverseOp->isReverseOperator()); - - normalOp = classA->findFunction(QLatin1String("operator/")); - QVERIFY(normalOp); - QCOMPARE(normalOp->arguments().count(), 1); - QVERIFY(normalOp->isPointerOperator()); - QVERIFY(!normalOp->isReverseOperator()); - } diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 54af34180..069431e59 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -4557,10 +4557,17 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, const GeneratorConte QString(), func->isUserAdded()); // If the function is user added, use the inject code + bool generateOperatorCode = true; if (func->isUserAdded()) { CodeSnipList snips = func->injectedCodeSnips(); - writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode, func, func->arguments().constLast()); - } else { + if (!snips.isEmpty()) { + writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionAny, + TypeSystem::TargetLangCode, func, + func->arguments().constLast()); + generateOperatorCode = false; + } + } + if (generateOperatorCode) { s << INDENT; if (func->type()) s << func->type()->cppSignature() << " " << CPP_RETURN_VAR << " = "; diff --git a/sources/shiboken2/tests/libsample/CMakeLists.txt b/sources/shiboken2/tests/libsample/CMakeLists.txt index ae13cd9f2..06021cec4 100644 --- a/sources/shiboken2/tests/libsample/CMakeLists.txt +++ b/sources/shiboken2/tests/libsample/CMakeLists.txt @@ -20,6 +20,7 @@ modifications.cpp mapuser.cpp modified_constructor.cpp multiple_derived.cpp +oddbool.cpp objectmodel.cpp objecttype.cpp objecttypeholder.cpp diff --git a/sources/shiboken2/tests/libsample/oddbool.cpp b/sources/shiboken2/tests/libsample/oddbool.cpp new file mode 100644 index 000000000..4f491dd96 --- /dev/null +++ b/sources/shiboken2/tests/libsample/oddbool.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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$ +** +****************************************************************************/ + +#include "oddbool.h" + +ComparisonTester::ComparisonTester(int v) : m_value(v) +{ +} + +ComparisonTester& ComparisonTester::operator=(int v) +{ + m_value = v; + return *this; +} + +int ComparisonTester::compare(const ComparisonTester &rhs) const +{ + if (m_value < rhs.m_value) + return -1; + if (m_value > rhs.m_value) + return 1; + return 0; +} diff --git a/sources/shiboken2/tests/libsample/oddbool.h b/sources/shiboken2/tests/libsample/oddbool.h index 454c84157..f7d77c0b3 100644 --- a/sources/shiboken2/tests/libsample/oddbool.h +++ b/sources/shiboken2/tests/libsample/oddbool.h @@ -31,6 +31,8 @@ #include "libsamplemacros.h" +#include <type_traits> + class OddBool { @@ -80,4 +82,27 @@ private: OddBool m_oddbool; }; -#endif +class LIBSAMPLE_API ComparisonTester +{ +public: + explicit ComparisonTester(int v); + ComparisonTester &operator=(int v); + + int compare(const ComparisonTester &rhs) const; + +private: + int m_value; +}; + +// Hide the comparison operators from the clang parser (see typesystem_sample.xml:184, +// oddbool_test.py) + +inline std::enable_if<std::is_assignable<ComparisonTester, int>::value, bool>::type + operator==(const ComparisonTester &c1, const ComparisonTester &c2) +{ return c1.compare(c2) == 0; } + +inline std::enable_if<std::is_assignable<ComparisonTester, int>::value, bool>::type + operator!=(const ComparisonTester &c1, const ComparisonTester &c2) +{ return c1.compare(c2) != 0; } + +#endif // ODDBOOL_H diff --git a/sources/shiboken2/tests/samplebinding/CMakeLists.txt b/sources/shiboken2/tests/samplebinding/CMakeLists.txt index b65068dc3..5cc7092b2 100644 --- a/sources/shiboken2/tests/samplebinding/CMakeLists.txt +++ b/sources/shiboken2/tests/samplebinding/CMakeLists.txt @@ -19,6 +19,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/bytearray_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/bucket_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/classwithfunctionpointer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/collector_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/comparisontester_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/color_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/ctorconvrule_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/cvlistuser_wrapper.cpp diff --git a/sources/shiboken2/tests/samplebinding/oddbool_test.py b/sources/shiboken2/tests/samplebinding/oddbool_test.py index de1429604..5334e970c 100644 --- a/sources/shiboken2/tests/samplebinding/oddbool_test.py +++ b/sources/shiboken2/tests/samplebinding/oddbool_test.py @@ -39,7 +39,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from shiboken_paths import init_paths init_paths() -from sample import OddBoolUser +from sample import OddBoolUser, ComparisonTester class DerivedOddBoolUser (OddBoolUser): def returnMyselfVirtual(self): @@ -80,5 +80,11 @@ class OddBoolTest(unittest.TestCase): obu = OddBoolUser(cpx) self.assertFalse(obu.oddBool()) + def testOddOperators(self): + t1 = ComparisonTester(42) + t2 = ComparisonTester(42) + self.assertEqual(t1, t2) + + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml index 5754b3047..a1f8cd6d1 100644 --- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml @@ -181,6 +181,21 @@ </conversion-rule> </primitive-type> + <!-- As of Qt 6, there is a trend of hiding bool returns of comparison + operators of container classes behind some template expression using + SFINAE depending on their value's traits, like: + template <typename U = T> + friend QTypeTraits::compare_eq_result<U> operator==(const QList &l, const QList &r) + which the clang parser cannot identify. Rich comparison of classes + inheriting QList (QPolygon, QItemSelection) will then not be generated. + To work around, the operators should be added manually without + injecting code. The code should just use the standard implementation. --> + <value-type name="ComparisonTester"> + <include file-name="oddbool.h" location="global"/> + <add-function signature="operator==(const ComparisonTester&)" return-type="bool"/> + <add-function signature="operator!=(const ComparisonTester&)" return-type="bool"/> + </value-type> + <primitive-type name="PStr"> <include file-name="str.h" location="global"/> <conversion-rule> @@ -2460,6 +2475,8 @@ <suppress-warning text="visibility of function 'publicMethod' modified in class 'MDerived3'" /> <suppress-warning text="skipping function 'InjectCode::toStr', unmatched parameter type 'T const&'" /> + <suppress-warning text="^skipping function 'std::enable_if.*ComparisonTester::operator[!=]=.*ComparisonTester.*$"/> + <!-- Do not fix this warning, the generator should be able to handle this situation for Object Types. --> <suppress-warning text="Argument in position 1 of added function 'SampleNamespace::passReferenceToObjectType(ObjectType * arg__1)', has a type that is not a reference, while the argument in the corresponding position in C++ function 'SampleNamespace::passReferenceToObjectType(const ObjectType & obj, int multiplier)' is a reference." /> |
