From a2a432a0e88380bc36fcfc60fb988ed2abfc2c29 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 28 Mar 2020 12:32:30 +1100 Subject: [PATCH] item: wrote better function for retrieving shared ptr from raw ptr Rather than every call having to access the item's parent, the item does it automatically which simplifies code everywhere. --- app/project/item/item.cpp | 16 +++++----------- app/project/item/item.h | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/project/item/item.cpp b/app/project/item/item.cpp index d694bc1e4..c8aab77f5 100644 --- a/app/project/item/item.cpp +++ b/app/project/item/item.cpp @@ -76,19 +76,13 @@ const QList &Item::children() const return children_; } -ItemPtr Item::shared_ptr_from_raw(Item *item, bool traverse) +ItemPtr Item::get_shared_ptr() const { - for (int i=0;i siblings = parent()->children(); - if (c.get() == item) { - return c; - } else if (traverse && c->CanHaveChildren()) { - ItemPtr grandchild = shared_ptr_from_raw(item); - - if (grandchild) { - return grandchild; - } + foreach (ItemPtr s, siblings) { + if (s.get() == this) { + return s; } } diff --git a/app/project/item/item.h b/app/project/item/item.h index 42cb83bf7..563e9543c 100644 --- a/app/project/item/item.h +++ b/app/project/item/item.h @@ -77,7 +77,7 @@ public: Item* child(int i) const; const QList& children() const; - ItemPtr shared_ptr_from_raw(Item* item, bool traverse = false); + ItemPtr get_shared_ptr() const; const QString& name() const; void set_name(const QString& n);