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.
This commit is contained in:
itsmattkc
2020-03-28 12:32:30 +11:00
parent 4dcc672b23
commit a2a432a0e8
2 changed files with 6 additions and 12 deletions
+5 -11
View File
@@ -76,19 +76,13 @@ const QList<ItemPtr> &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<children_.size();i++) {
ItemPtr c = children_.at(i);
QList<ItemPtr> 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;
}
}
+1 -1
View File
@@ -77,7 +77,7 @@ public:
Item* child(int i) const;
const QList<ItemPtr>& 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);