diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-22 00:41:01 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-22 00:41:01 +0200 |
commit | f614081b832b2923821410b69117b5450fd83b5a (patch) | |
tree | eb6a25bde8771b6a715c1bbd80882c6576a365e9 | |
parent | d6abfbdc5a7838fdc8e20e43a5146968a8dbcd81 (diff) | |
download | serenity-f614081b832b2923821410b69117b5450fd83b5a.zip |
LibCore: Add CObject::remove_from_parent()
This is a convenient shorthand for:
if (object.parent())
object.parent()->remove_child(object);
-rw-r--r-- | Libraries/LibCore/CObject.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibCore/CObject.h b/Libraries/LibCore/CObject.h index dd036ef666..7a5ce63785 100644 --- a/Libraries/LibCore/CObject.h +++ b/Libraries/LibCore/CObject.h @@ -85,6 +85,12 @@ public: void dispatch_event(CEvent&, CObject* stay_within = nullptr); + void remove_from_parent() + { + if (m_parent) + m_parent->remove_child(*this); + } + protected: explicit CObject(CObject* parent = nullptr, bool is_widget = false); |