Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-09-27 18:45:02 +0300
committerJulian Eisel <julian@blender.org>2021-09-27 18:49:31 +0300
commit824733ea47d13030c18faa618c1dc31a08dfa43d (patch)
tree4d2c9ee4da79e51d5f02bfd9091c9d5bcee71753 /source/blender/blenkernel/BKE_asset_catalog.hh
parent5bea5e25d52fe26b53928781ec0b1f5d4ddf5ad0 (diff)
Assets: Additions/fixes to the catalog system in preparation for the UI
* Fixes missing update of the catalog tree when adding catalogs. * Adds iterators for the catalogs, needed for UI code. * Store catalog ID in the catalog tree items, needed for UI code. * Other smaller API additions for the UI. * Improve comments and smaller cleanups. New functions are covered with unit tests. Differential Revision: https://developer.blender.org/D12618 Reviewed by: Sybren Stüvel
Diffstat (limited to 'source/blender/blenkernel/BKE_asset_catalog.hh')
-rw-r--r--source/blender/blenkernel/BKE_asset_catalog.hh46
1 files changed, 38 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh
index cf9d581b148..07373caf701 100644
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@ -86,6 +86,10 @@ class AssetCatalogService {
/** Return catalog with the given ID. Return nullptr if not found. */
AssetCatalog *find_catalog(CatalogID catalog_id);
+ /** Return first catalog with the given path. Return nullptr if not found. This is not an
+ * efficient call as it's just a linear search over the catalogs. */
+ AssetCatalog *find_catalog_by_path(const CatalogPath &path) const;
+
/** Create a catalog with some sensible auto-generated catalog ID.
* The catalog will be saved to the default catalog file.*/
AssetCatalog *create_catalog(const CatalogPath &catalog_path);
@@ -124,48 +128,74 @@ class AssetCatalogService {
void rebuild_tree();
};
+/**
+ * Representation of a catalog path in the #AssetCatalogTree.
+ */
class AssetCatalogTreeItem {
- friend class AssetCatalogService;
+ friend class AssetCatalogTree;
public:
+ /** Container for child items. Uses a #std::map to keep items ordered by their name (i.e. their
+ * last catalog component). */
using ChildMap = std::map<std::string, AssetCatalogTreeItem>;
- using ItemIterFn = FunctionRef<void(const AssetCatalogTreeItem &)>;
+ using ItemIterFn = FunctionRef<void(AssetCatalogTreeItem &)>;
- AssetCatalogTreeItem(StringRef name, const AssetCatalogTreeItem *parent = nullptr);
+ AssetCatalogTreeItem(StringRef name,
+ CatalogID catalog_id,
+ const AssetCatalogTreeItem *parent = nullptr);
+ CatalogID get_catalog_id() const;
StringRef get_name() const;
/** Return the full catalog path, defined as the name of this catalog prefixed by the full
* catalog path of its parent and a separator. */
CatalogPath catalog_path() const;
int count_parents() const;
+ bool has_children() const;
- static void foreach_item_recursive(const ChildMap &children_, const ItemIterFn callback);
+ /** Iterate over children calling \a callback for each of them, but do not recurse into their
+ * children. */
+ void foreach_child(const ItemIterFn callback);
protected:
/** Child tree items, ordered by their names. */
ChildMap children_;
/** The user visible name of this component. */
CatalogPathComponent name_;
+ CatalogID catalog_id_;
/** Pointer back to the parent item. Used to reconstruct the hierarchy from an item (e.g. to
* build a path). */
const AssetCatalogTreeItem *parent_ = nullptr;
+
+ private:
+ static void foreach_item_recursive(ChildMap &children_, ItemIterFn callback);
};
/**
* A representation of the catalog paths as tree structure. Each component of the catalog tree is
- * represented by a #AssetCatalogTreeItem.
+ * represented by an #AssetCatalogTreeItem. The last path component of an item is used as its name,
+ * which may also be shown to the user.
+ * An item can not have multiple children with the same name. That means the name uniquely
+ * identifies an item within its parent.
+ *
* There is no single root tree element, the #AssetCatalogTree instance itself represents the root.
*/
class AssetCatalogTree {
- friend class AssetCatalogService;
+ using ChildMap = AssetCatalogTreeItem::ChildMap;
+ using ItemIterFn = AssetCatalogTreeItem::ItemIterFn;
public:
- void foreach_item(const AssetCatalogTreeItem::ItemIterFn callback) const;
+ /** Ensure an item representing \a path is in the tree, adding it if necessary. */
+ void insert_item(const AssetCatalog &catalog);
+
+ void foreach_item(const AssetCatalogTreeItem::ItemIterFn callback);
+ /** Iterate over root items calling \a callback for each of them, but do not recurse into their
+ * children. */
+ void foreach_root_item(const ItemIterFn callback);
protected:
/** Child tree items, ordered by their names. */
- AssetCatalogTreeItem::ChildMap children_;
+ ChildMap root_items_;
};
/** Keeps track of which catalogs are defined in a certain file on disk.