From 130b0de6466bcba23752e19900cfd795ec0664fe Mon Sep 17 00:00:00 2001 From: Nicolas Elie <40382614+n-elie@users.noreply.github.com> Date: Mon, 6 Sep 2021 20:48:17 +0200 Subject: [PATCH] Python Bindings: Fix findParent that was not working as expected (#349) --- sip/ads_globals.sip | 276 ++++++++++++++++++++++---------------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/sip/ads_globals.sip b/sip/ads_globals.sip index 7bbce94..91df1c7 100644 --- a/sip/ads_globals.sip +++ b/sip/ads_globals.sip @@ -1,138 +1,138 @@ -%Import QtWidgets/QtWidgetsmod.sip - -%If (Qt_5_0_0 -) - -%ModuleHeaderCode -PyObject *qtads_FindParent(PyObject* type, const QWidget *child); -%End - -%ModuleCode -PyObject *qtads_FindParent(PyObject* type, const QWidget *w) -{ - // Check that the types checking was successful. - if (!type) - return 0; - - QWidget* parentWidget = w->parentWidget(); - - while (parentWidget) - { - PyObject *ParentImpl = sipConvertFromType(parentWidget, sipType_QObject, 0); - if (!ParentImpl) - { - return 0; - } - - if (PyType_IsSubtype((PyTypeObject *)type, Py_TYPE(ParentImpl))) - return ParentImpl; - - Py_DECREF(ParentImpl); - - parentWidget = parentWidget->parentWidget(); - } - - Py_INCREF(Py_None); - return Py_None; -} -%End - -namespace ads -{ - %TypeHeaderCode - #include - %End - - enum DockWidgetArea - { - NoDockWidgetArea, - LeftDockWidgetArea, - RightDockWidgetArea, - TopDockWidgetArea, - BottomDockWidgetArea, - CenterDockWidgetArea, - - InvalidDockWidgetArea, - OuterDockAreas, - AllDockAreas - }; - typedef QFlags DockWidgetAreas; - - - enum TitleBarButton - { - TitleBarButtonTabsMenu, - TitleBarButtonUndock, - TitleBarButtonClose - }; - - enum eDragState - { - DraggingInactive, - DraggingMousePressed, - DraggingTab, - DraggingFloatingWidget - }; - - enum eIcon - { - TabCloseIcon, - DockAreaMenuIcon, - DockAreaUndockIcon, - DockAreaCloseIcon, - - IconCount, - }; - - enum eBitwiseOperator - { - BitwiseAnd, - BitwiseOr - }; - - namespace internal - { - void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To); - void hideEmptyParentSplitters(ads::CDockSplitter* FirstParentSplitter); - - class CDockInsertParam - { - %TypeHeaderCode - #include - %End - - public: - Qt::Orientation orientation() const; - bool append() const; - int insertOffset() const; - }; - ads::internal::CDockInsertParam dockAreaInsertParameters(ads::DockWidgetArea Area); - - SIP_PYOBJECT findParent(SIP_PYTYPE type, const QWidget *w) const /TypeHint="QObject"/; - %MethodCode - sipRes = qtads_FindParent(a0, a1); - - if (!sipRes) - { - sipIsErr = 1; - } - %End - - QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity); - - QPoint globalPositionOf(QMouseEvent* ev); - - void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap, ads::eIcon CustomIconId); - - enum eRepolishChildOptions - { - RepolishIgnoreChildren, - RepolishDirectChildren, - RepolishChildrenRecursively - }; - - void repolishStyle(QWidget* w, ads::internal::eRepolishChildOptions Options = ads::internal::RepolishIgnoreChildren); - }; - -}; - -%End +%Import QtWidgets/QtWidgetsmod.sip + +%If (Qt_5_0_0 -) + +%ModuleHeaderCode +PyObject *qtads_FindParent(PyObject* type, const QWidget *child); +%End + +%ModuleCode +PyObject *qtads_FindParent(PyObject* type, const QWidget *w) +{ + // Check that the types checking was successful. + if (!type) + return 0; + + QWidget* parentWidget = w->parentWidget(); + + while (parentWidget) + { + PyObject *ParentImpl = sipConvertFromType(parentWidget, sipType_QObject, 0); + if (!ParentImpl) + { + return 0; + } + + if (PyObject_IsInstance(ParentImpl, type)) + return ParentImpl; + + Py_DECREF(ParentImpl); + + parentWidget = parentWidget->parentWidget(); + } + + Py_INCREF(Py_None); + return Py_None; +} +%End + +namespace ads +{ + %TypeHeaderCode + #include + %End + + enum DockWidgetArea + { + NoDockWidgetArea, + LeftDockWidgetArea, + RightDockWidgetArea, + TopDockWidgetArea, + BottomDockWidgetArea, + CenterDockWidgetArea, + + InvalidDockWidgetArea, + OuterDockAreas, + AllDockAreas + }; + typedef QFlags DockWidgetAreas; + + + enum TitleBarButton + { + TitleBarButtonTabsMenu, + TitleBarButtonUndock, + TitleBarButtonClose + }; + + enum eDragState + { + DraggingInactive, + DraggingMousePressed, + DraggingTab, + DraggingFloatingWidget + }; + + enum eIcon + { + TabCloseIcon, + DockAreaMenuIcon, + DockAreaUndockIcon, + DockAreaCloseIcon, + + IconCount, + }; + + enum eBitwiseOperator + { + BitwiseAnd, + BitwiseOr + }; + + namespace internal + { + void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To); + void hideEmptyParentSplitters(ads::CDockSplitter* FirstParentSplitter); + + class CDockInsertParam + { + %TypeHeaderCode + #include + %End + + public: + Qt::Orientation orientation() const; + bool append() const; + int insertOffset() const; + }; + ads::internal::CDockInsertParam dockAreaInsertParameters(ads::DockWidgetArea Area); + + SIP_PYOBJECT findParent(SIP_PYTYPE type, const QWidget *w) const /TypeHint="QObject"/; + %MethodCode + sipRes = qtads_FindParent(a0, a1); + + if (!sipRes) + { + sipIsErr = 1; + } + %End + + QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity); + + QPoint globalPositionOf(QMouseEvent* ev); + + void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap, ads::eIcon CustomIconId); + + enum eRepolishChildOptions + { + RepolishIgnoreChildren, + RepolishDirectChildren, + RepolishChildrenRecursively + }; + + void repolishStyle(QWidget* w, ads::internal::eRepolishChildOptions Options = ads::internal::RepolishIgnoreChildren); + }; + +}; + +%End