diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-02 13:48:40 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-10 11:19:16 +0100 |
| commit | 077b30d72614f8d2176335f03e3a8568ccbcedc6 (patch) | |
| tree | 787cb5eaa7ef976879eb2002e435376d34842135 /sources/pyside6/PySide6/glue/qtwidgets.cpp | |
| parent | 6b2637544902cf9a11384b167f03bf2b4b7d7417 (diff) | |
PySide6: Brush up the injected code snippets and templates
- Use qsizetype (or equivalent Py_ssize_t) for containers
- Introduce some auto
- Use constData() for QByteArray
- Use Qt 5 connection syntax
- Use nullptr
Change-Id: Ie9134a4f756219d6e5c5710ab64c09a236febd4d
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/glue/qtwidgets.cpp')
| -rw-r--r-- | sources/pyside6/PySide6/glue/qtwidgets.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/sources/pyside6/PySide6/glue/qtwidgets.cpp b/sources/pyside6/PySide6/glue/qtwidgets.cpp index 4f9baadf1..d3e95e3cb 100644 --- a/sources/pyside6/PySide6/glue/qtwidgets.cpp +++ b/sources/pyside6/PySide6/glue/qtwidgets.cpp @@ -68,7 +68,7 @@ if (%0) { // @snippet qgraphicsitem-scene-return-parenting // @snippet qgraphicsitem-isblockedbymodalpanel -QGraphicsItem *item_ = NULL; +QGraphicsItem *item_ = nullptr; %RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(&item_); %PYARG_0 = PyTuple_New(2); PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_)); @@ -153,7 +153,7 @@ for (auto *act : actions) { if (auto wrapper = bm.retrieveWrapper(act)) { auto pyObj = reinterpret_cast<PyObject *>(wrapper); Py_INCREF(pyObj); - Shiboken::Object::setParent(NULL, pyObj); + Shiboken::Object::setParent(nullptr, pyObj); Shiboken::Object::invalidate(pyObj); Py_DECREF(pyObj); } @@ -190,7 +190,7 @@ addActionWithPyObject(QMenuBar *self, const QString &text, PyObject *callback) const auto &actions = %CPPSELF.actions(); for (auto *act : actions) { Shiboken::AutoDecRef pyAct(%CONVERTTOPYTHON[QAction *](act)); - Shiboken::Object::setParent(NULL, pyAct); + Shiboken::Object::setParent(nullptr, pyAct); Shiboken::Object::invalidate(pyAct); } // @snippet qmenubar-clear @@ -245,7 +245,7 @@ inline void addLayoutOwnership(QLayout *layout, QWidget *widget) //Transfer parent to layout widget if (pw && lw && pw != lw) - Shiboken::Object::setParent(0, pyChild); + Shiboken::Object::setParent(nullptr, pyChild); if (!lw && !pw) { //keep the reference while the layout is orphan @@ -272,7 +272,7 @@ inline void addLayoutOwnership(QLayout *layout, QLayout *other) return; } - for (int i=0, i_max=other->count(); i < i_max; i++) { + for (int i = 0, i_max = other->count(); i < i_max; ++i) { QLayoutItem *item = other->itemAt(i); if (PyErr_Occurred() || !item) return; @@ -303,19 +303,17 @@ inline void addLayoutOwnership(QLayout *layout, QLayoutItem *item) static void removeWidgetFromLayout(QLayout *layout, QWidget *widget) { - QWidget *parent = widget->parentWidget(); - - if (!parent) { + if (QWidget *parent = widget->parentWidget()) { + //give the ownership to parent + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](parent)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](widget)); + Shiboken::Object::setParent(pyParent, pyChild); + } else { //remove reference on layout Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](layout)); Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](widget)); Shiboken::Object::removeReference(reinterpret_cast<SbkObject *>(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild); - } else { - //give the ownership to parent - Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](parent)); - Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](widget)); - Shiboken::Object::setParent(pyParent, pyChild); } } @@ -339,7 +337,7 @@ inline void removeLayoutOwnership(QLayout *layout, QWidget *widget) if (!widget) return; - for (int i=0, i_max=layout->count(); i < i_max; i++) { + for (int i = 0, i_max = layout->count(); i < i_max; ++i) { QLayoutItem *item = layout->itemAt(i); if (PyErr_Occurred() || !item) return; @@ -442,7 +440,7 @@ for (int i = 0, count = %CPPSELF.count(); i < count; ++i) { if (auto wrapper = bm.retrieveWrapper(item)) { auto pyObj = reinterpret_cast<PyObject *>(wrapper); Py_INCREF(pyObj); - Shiboken::Object::setParent(NULL, pyObj); + Shiboken::Object::setParent(nullptr, pyObj); Shiboken::Object::invalidate(pyObj); Py_DECREF(pyObj); } @@ -616,7 +614,7 @@ const auto &toolButtonChildren = %CPPSELF.findChildren<QToolButton *>(); for (auto *child : toolButtonChildren) { if (bm.hasWrapper(child)) { PyObject *pyChild = %CONVERTTOPYTHON[QToolButton *](child); - Shiboken::Object::setParent(0, pyChild); + Shiboken::Object::setParent(nullptr, pyChild); lst << pyChild; } } @@ -625,12 +623,12 @@ for (auto *child : toolButtonChildren) { const auto &actions = %CPPSELF.actions(); for (auto *act : actions) { Shiboken::AutoDecRef pyAct(%CONVERTTOPYTHON[QAction *](act)); - Shiboken::Object::setParent(NULL, pyAct); + Shiboken::Object::setParent(nullptr, pyAct); Shiboken::Object::invalidate(pyAct); } %CPPSELF.clear(); -for (auto *obj : lst) { +for (auto *obj : qAsConst(lst)) { Shiboken::Object::invalidate(reinterpret_cast<SbkObject *>(obj)); Py_XDECREF(obj); } |
