[Bf-blender-cvs] [2d60f64960e] outliner-cpp-refactor: UI Code Quality: Convert Outliner Blender File mode to new tree buiding design

Julian Eisel noreply at git.blender.org
Mon Nov 9 00:38:27 CET 2020


Commit: 2d60f64960ed8f5b93de1d87713f7982681dd75e
Author: Julian Eisel
Date:   Sat Nov 7 20:13:37 2020 +0100
Branches: outliner-cpp-refactor
https://developer.blender.org/rB2d60f64960ed8f5b93de1d87713f7982681dd75e

UI Code Quality: Convert Outliner Blender File mode to new tree buiding design

See https://developer.blender.org/D9499.

Also:
* Add `space_outliner/tree/common.cc` for functions shared between display
  modes.
* Had to add a cast to `ListBaseWrapper` to make it work with ID lists.
* Cleanup: Remove internal `Tree` alias for `ListBase`. That was more confusing
  than helpful.

===================================================================

M	source/blender/blenlib/BLI_listbase_wrapper.hh
M	source/blender/editors/space_outliner/CMakeLists.txt
M	source/blender/editors/space_outliner/outliner_tree.c
A	source/blender/editors/space_outliner/tree/common.cc
M	source/blender/editors/space_outliner/tree/tree_view.cc
M	source/blender/editors/space_outliner/tree/tree_view.hh
A	source/blender/editors/space_outliner/tree/tree_view_libraries.cc
M	source/blender/editors/space_outliner/tree/tree_view_view_layer.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_listbase_wrapper.hh b/source/blender/blenlib/BLI_listbase_wrapper.hh
index c31694d7d9e..ed2a2b5e5ec 100644
--- a/source/blender/blenlib/BLI_listbase_wrapper.hh
+++ b/source/blender/blenlib/BLI_listbase_wrapper.hh
@@ -56,7 +56,8 @@ template<typename T> class ListBaseWrapper {
 
     Iterator &operator++()
     {
-      current_ = current_->next;
+      /* Some types store next/prev using `void *`, so cast is necessary. */
+      current_ = static_cast<T *>(current_->next);
       return *this;
     }
 
diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt
index a0577b1103d..bbcd5a32ad6 100644
--- a/source/blender/editors/space_outliner/CMakeLists.txt
+++ b/source/blender/editors/space_outliner/CMakeLists.txt
@@ -44,7 +44,9 @@ set(SRC
   outliner_tree.c
   outliner_utils.c
   space_outliner.c
+  tree/common.cc
   tree/tree_view.cc
+  tree/tree_view_libraries.cc
   tree/tree_view_view_layer.cc
 
   outliner_intern.h
diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index 991d831d6e0..67616db6b3a 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -1382,110 +1382,6 @@ static void outliner_add_seq_dup(SpaceOutliner *space_outliner,
 
 /* ----------------------------------------------- */
 
-static const char *outliner_idcode_to_plural(short idcode)
-{
-  const char *propname = BKE_idtype_idcode_to_name_plural(idcode);
-  PropertyRNA *prop = RNA_struct_type_find_property(&RNA_BlendData, propname);
-  return (prop) ? RNA_property_ui_name(prop) : "UNKNOWN";
-}
-
-static bool outliner_library_id_show(Library *lib, ID *id, short filter_id_type)
-{
-  if (id->lib != lib) {
-    return false;
-  }
-
-  if (filter_id_type == ID_GR) {
-    /* Don't show child collections of non-scene master collection,
-     * they are already shown as children. */
-    Collection *collection = (Collection *)id;
-    bool has_non_scene_parent = false;
-
-    LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) {
-      if (!(cparent->collection->flag & COLLECTION_IS_MASTER)) {
-        has_non_scene_parent = true;
-      }
-    }
-
-    if (has_non_scene_parent) {
-      return false;
-    }
-  }
-
-  return true;
-}
-
-static TreeElement *outliner_add_library_contents(Main *mainvar,
-                                                  SpaceOutliner *space_outliner,
-                                                  ListBase *lb,
-                                                  Library *lib)
-{
-  TreeElement *ten, *tenlib = NULL;
-  ListBase *lbarray[MAX_LIBARRAY];
-  int a, tot;
-  short filter_id_type = (space_outliner->filter & SO_FILTER_ID_TYPE) ?
-                             space_outliner->filter_id_type :
-                             0;
-
-  if (filter_id_type) {
-    lbarray[0] = which_libbase(mainvar, space_outliner->filter_id_type);
-    tot = 1;
-  }
-  else {
-    tot = set_listbasepointers(mainvar, lbarray);
-  }
-
-  for (a = 0; a < tot; a++) {
-    if (lbarray[a] && lbarray[a]->first) {
-      ID *id = lbarray[a]->first;
-      const bool is_library = (GS(id->name) == ID_LI) && (lib != NULL);
-
-      /* check if there's data in current lib */
-      for (; id; id = id->next) {
-        if (id->lib == lib) {
-          break;
-        }
-      }
-
-      /* We always want to create an entry for libraries, even if/when we have no more IDs from
-       * them. This invalid state is important to show to user as well.*/
-      if (id != NULL || is_library) {
-        if (!tenlib) {
-          /* Create library tree element on demand, depending if there are any data-blocks. */
-          if (lib) {
-            tenlib = outliner_add_element(space_outliner, lb, lib, NULL, 0, 0);
-          }
-          else {
-            tenlib = outliner_add_element(space_outliner, lb, mainvar, NULL, TSE_ID_BASE, 0);
-            tenlib->name = IFACE_("Current File");
-          }
-        }
-
-        /* Create data-block list parent element on demand. */
-        if (id != NULL) {
-          if (filter_id_type) {
-            ten = tenlib;
-          }
-          else {
-            ten = outliner_add_element(
-                space_outliner, &tenlib->subtree, lbarray[a], NULL, TSE_ID_BASE, 0);
-            ten->directdata = lbarray[a];
-            ten->name = outliner_idcode_to_plural(GS(id->name));
-          }
-
-          for (id = lbarray[a]->first; id; id = id->next) {
-            if (outliner_library_id_show(lib, id, filter_id_type)) {
-              outliner_add_element(space_outliner, &ten->subtree, id, ten, 0, 0);
-            }
-          }
-        }
-      }
-    }
-  }
-
-  return tenlib;
-}
-
 static void outliner_add_orphaned_datablocks(Main *mainvar, SpaceOutliner *space_outliner)
 {
   TreeElement *ten;
@@ -2328,61 +2224,13 @@ void outliner_build_tree(Main *mainvar,
                                                          &source_data);
   }
 
-  if (!BLI_listbase_is_empty(&space_outliner->tree)) {
-    /* Skip. */
+  if (space_outliner->runtime->tree_view) {
+    /* Skip if there's a tree view that's responsible for adding all elements. */
   }
   /* options */
   else if (space_outliner->outlinevis == SO_LIBRARIES) {
-    Library *lib;
-
-    /* current file first - mainvar provides tselem with unique pointer - not used */
-    ten = outliner_add_library_contents(mainvar, space_outliner, &space_outliner->tree, NULL);
-    if (ten) {
-      tselem = TREESTORE(ten);
-      if (!tselem->used) {
-        tselem->flag &= ~TSE_CLOSED;
-      }
-    }
-
-    for (lib = mainvar->libraries.first; lib; lib = lib->id.next) {
-      ten = outliner_add_library_contents(mainvar, space_outliner, &space_outliner->tree, lib);
-      /* NULL-check matters, due to filtering there may not be a new element. */
-      if (ten) {
-        lib->id.newid = (ID *)ten;
-      }
-    }
-    /* make hierarchy */
-    ten = space_outliner->tree.first;
-    if (ten != NULL) {
-      ten = ten->next; /* first one is main */
-      while (ten) {
-        TreeElement *nten = ten->next, *par;
-        tselem = TREESTORE(ten);
-        lib = (Library *)tselem->id;
-        if (lib && lib->parent) {
-          par = (TreeElement *)lib->parent->id.newid;
-          if (tselem->id->tag & LIB_TAG_INDIRECT) {
-            /* Only remove from 'first level' if lib is not also directly used. */
-            BLI_remlink(&space_outliner->tree, ten);
-            BLI_addtail(&par->subtree, ten);
-            ten->parent = par;
-          }
-          else {
-            /* Else, make a new copy of the libtree for our parent. */
-            TreeElement *dupten = outliner_add_library_contents(
-                mainvar, space_outliner, &par->subtree, lib);
-            if (dupten) {
-              dupten->parent = par;
-            }
-          }
-        }
-        ten = nten;
-      }
-    }
-    /* restore newid pointers */
-    for (lib = mainvar->libraries.first; lib; lib = lib->id.next) {
-      lib->id.newid = NULL;
-    }
+    /* Ported to new tree-view, should be built there already. */
+    BLI_assert(false);
   }
   else if (space_outliner->outlinevis == SO_SCENES) {
     Scene *sce;
diff --git a/source/blender/editors/space_outliner/tree/common.cc b/source/blender/editors/space_outliner/tree/common.cc
new file mode 100644
index 00000000000..56b5d62195e
--- /dev/null
+++ b/source/blender/editors/space_outliner/tree/common.cc
@@ -0,0 +1,41 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup spoutliner
+ *
+ * Functions and helpers shared between tree-view types or other tree related code.
+ */
+
+#include "BKE_idtype.h"
+
+#include "RNA_access.h"
+
+#include "tree_view.hh"
+
+/* -------------------------------------------------------------------- */
+/** \name ID Helpers.
+ *
+ * \{ */
+
+const char *outliner_idcode_to_plural(short idcode)
+{
+  const char *propname = BKE_idtype_idcode_to_name_plural(idcode);
+  PropertyRNA *prop = RNA_struct_type_find_property(&RNA_BlendData, propname);
+  return (prop) ? RNA_property_ui_name(prop) : "UNKNOWN";
+}
+
+/** \} */
diff --git a/source/blender/editors/space_outliner/tree/tree_view.cc b/source/blender/editors/space_outliner/tree/tree_view.cc
index 8f8e6c606be..f6c3da012f4 100644
--- a/source/blender/editors/space_outliner/tree/tree_view.cc
+++ b/source/blender/editors/space_outliner/tree/tree_view.cc
@@ -34,7 +34,10 @@ TreeView *outliner_tree_view_create(eSpaceOutliner_Mode mode, SpaceOutliner *spa
 
   switch (mode) {
     case SO_SCENES:
+      break;
     case SO_LIBRARIES:
+      tree_view = new outliner::TreeViewLibraries(*space_outliner);
+      break;
     case SO_SEQUENCE:
     case SO_DATA_API:
     case SO_ID_ORPHANS:
diff --git a/source/blender/editors/space_outliner/tree/tree_view.hh b/source/blender/editors/space_outliner/tree/tree_view.hh
index a4ce0ce6e78..cb3bb4681c8 100644
--- a/source/blender/editors/space_outliner/tree/tree_view.hh
+++ b/source/blender/editors/space_outliner/tree/tree_view.hh
@@ -36,8 +36,6 @@ namespace blender {
 namespace ed {
 namespace outliner {
 
-using Tree = ListBase;
-
 /* -------------------------------------------------------------------- */
 /* Tree-View Interface */
 
@@ -60,7 +58,7 @@ class AbstractTreeView {
    * Build a tree for this view with the Blender context data given in \a source_data and the view
    * settings in \

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list