From 2af910dabc8600cc43d3540aec4b8337e91da1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Sat, 1 Nov 2014 13:08:00 +0200 Subject: [PATCH] libappfw: Added a smart pointer for owning a GuiWidget Automatically calls the correct destructor on the widget. --- .../libappfw/include/de/framework/guiwidget.h | 17 +++++++++++++++-- doomsday/libappfw/src/guiwidget.cpp | 7 +------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/doomsday/libappfw/include/de/framework/guiwidget.h b/doomsday/libappfw/include/de/framework/guiwidget.h index b09ae62754..9bd5a93fa8 100644 --- a/doomsday/libappfw/include/de/framework/guiwidget.h +++ b/doomsday/libappfw/include/de/framework/guiwidget.h @@ -189,7 +189,6 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget */ static void destroy(GuiWidget *widget); - GuiRootWidget &root(); GuiRootWidget &root() const; Widget::Children childWidgets() const; Widget *parentWidget() const; @@ -297,7 +296,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget void deinitialize(); void viewResized(); void update(); - void draw() /*final*/; + void draw() final; bool handleEvent(Event const &event); /** @@ -460,6 +459,20 @@ public slots: Q_DECLARE_OPERATORS_FOR_FLAGS(GuiWidget::Attributes) +template +struct GuiWidgetDeleter { + void operator () (WidgetType *w) { + GuiWidget::destroy(w); + } +}; + +template +class UniqueWidgetPtr : public std::unique_ptr> { +public: + UniqueWidgetPtr(WidgetType *w = nullptr) + : std::unique_ptr>(w) {} +}; + } // namespace de #endif // LIBAPPFW_GUIWIDGET_H diff --git a/doomsday/libappfw/src/guiwidget.cpp b/doomsday/libappfw/src/guiwidget.cpp index 3086a0d1c1..498348ceab 100644 --- a/doomsday/libappfw/src/guiwidget.cpp +++ b/doomsday/libappfw/src/guiwidget.cpp @@ -374,16 +374,11 @@ void GuiWidget::destroy(GuiWidget *widget) delete widget; } -GuiRootWidget &GuiWidget::root() -{ - return static_cast(Widget::root()); -} - GuiRootWidget &GuiWidget::root() const { return static_cast(Widget::root()); } - + Widget::Children GuiWidget::childWidgets() const { return Widget::children();