diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-07 19:28:39 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-07 10:05:00 +0100 |
| commit | 2e0b8d3495d6c46c2d3afb88787fd7ca3ed1558e (patch) | |
| tree | e0e878b871b81a4e6e3bc24bf39ca135dfe91671 /src/favouritecollection.cpp | |
| parent | 19046566a62f9e616a23584ebbe045ddbc132023 (diff) | |
Added new context menus to favourite group
Diffstat (limited to 'src/favouritecollection.cpp')
| -rw-r--r-- | src/favouritecollection.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/favouritecollection.cpp b/src/favouritecollection.cpp index 29b79b7..10ea647 100644 --- a/src/favouritecollection.cpp +++ b/src/favouritecollection.cpp @@ -154,6 +154,31 @@ bool FavouriteCollection::addGroup(const QString &group_name) return internalAddGroup(group_name, group); } +bool FavouriteCollection::renameGroup(const QString &old_name, const QString &new_name) +{ + GroupNode * to_set = nullptr; + for (auto const & grp : root.children) + { + auto * g = static_cast<GroupNode*>(grp.get()); + if (g->title == old_name) + { + to_set = g; + } + if (g->title == new_name) + { + return false; + } + } + + if (to_set) + { + to_set->title = new_name; + return true; + } + + return false; +} + bool FavouriteCollection::addFavourite(const QString &group_name, const Favourite &fav) { GroupNode * group; @@ -374,6 +399,31 @@ bool FavouriteCollection::deleteGroup(const QString &group_name) return false; } +bool FavouriteCollection::deleteGroupRecursive(const QString &group_name) +{ + size_t index = 0; + for (auto it = root.children.begin(); it != root.children.end(); ++it, ++index) + { + auto & group = it->get()->as<GroupNode>(); + if (group.title == group_name) + { + // Delete group children + auto group_idx = this->index(index, 0); + beginRemoveRows(group_idx, 0, group.children.size()); + group.children.clear(); + endRemoveRows(); + + // Delete the group + beginRemoveRows(QModelIndex { }, index, index + 1); + root.children.erase(it); + endRemoveRows(); + + return true; + } + } + return false; +} + QVector<QPair<QString, Favourite const *>> FavouriteCollection::allFavourites() const { QVector<QPair<QString, Favourite const *>> identities; |
