浏览代码

LibCore: Add CObject::remove_from_parent()

This is a convenient shorthand for:

    if (object.parent())
        object.parent()->remove_child(object);
Andreas Kling 5 年之前
父节点
当前提交
f614081b83
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      Libraries/LibCore/CObject.h

+ 6 - 0
Libraries/LibCore/CObject.h

@@ -85,6 +85,12 @@ public:
 
 
     void dispatch_event(CEvent&, CObject* stay_within = nullptr);
     void dispatch_event(CEvent&, CObject* stay_within = nullptr);
 
 
+    void remove_from_parent()
+    {
+        if (m_parent)
+            m_parent->remove_child(*this);
+    }
+
 protected:
 protected:
     explicit CObject(CObject* parent = nullptr, bool is_widget = false);
     explicit CObject(CObject* parent = nullptr, bool is_widget = false);