Cleanup: Small C++ changes to two tree view uses

- Use `this->` to access class methods.
- Follow style guide for class definition order.
- Avoid unnecessary namespace redefinition.
- Make data struct local to node interface file.
This commit is contained in:
Hans Goudey
2023-09-01 23:00:27 -04:00
parent da0c7ca0c2
commit 840769d855
3 changed files with 27 additions and 33 deletions

View File

@@ -35,6 +35,8 @@ namespace blender::ui::light_linking {
namespace {
class CollectionDropTarget : public DropTargetInterface {
Collection &collection_;
public:
CollectionDropTarget(Collection &collection) : collection_(collection) {}
@@ -84,12 +86,14 @@ class CollectionDropTarget : public DropTargetInterface {
return true;
}
private:
Collection &collection_;
};
class CollectionViewItem : public BasicTreeViewItem {
Collection &collection_;
ID *id_ = nullptr;
CollectionLightLinking &collection_light_linking_;
public:
CollectionViewItem(Collection &collection,
ID &id,
@@ -185,14 +189,11 @@ class CollectionViewItem : public BasicTreeViewItem {
uiItemO(&row, "", ICON_X, "OBJECT_OT_light_linking_unlink_from_collection");
}
Collection &collection_;
ID *id_{nullptr};
CollectionLightLinking &collection_light_linking_;
};
class CollectionView : public AbstractTreeView {
Collection &collection_;
public:
explicit CollectionView(Collection &collection) : collection_(collection) {}
@@ -217,17 +218,12 @@ class CollectionView : public AbstractTreeView {
{
return std::make_unique<CollectionDropTarget>(collection_);
}
private:
Collection &collection_;
};
} // namespace
} // namespace blender::ui::light_linking
namespace ui = blender::ui;
void uiTemplateLightLinkingCollection(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
if (!ptr->data) {
@@ -265,11 +261,11 @@ void uiTemplateLightLinkingCollection(uiLayout *layout, PointerRNA *ptr, const c
uiBlock *block = uiLayoutGetBlock(layout);
ui::AbstractTreeView *tree_view = UI_block_add_view(
blender::ui::AbstractTreeView *tree_view = UI_block_add_view(
*block,
"Light Linking Collection Tree View",
std::make_unique<blender::ui::light_linking::CollectionView>(*collection));
tree_view->set_min_rows(3);
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
blender::ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
}

View File

@@ -32,6 +32,10 @@ namespace node_interface = blender::bke::node_interface;
namespace blender::ui::nodes {
struct wmDragNodeTreeInterface {
bNodeTreeInterfaceItem *item;
};
namespace {
class NodeTreeInterfaceView;
@@ -114,7 +118,7 @@ class NodeSocketViewItem : public BasicTreeViewItem {
uiItemL(input_socket_layout, "", ICON_BLANK1);
}
add_label(row);
this->add_label(row);
uiLayout *output_socket_layout = uiLayoutRow(&row, true);
if (socket_.flag & NODE_INTERFACE_SOCKET_OUTPUT) {
@@ -180,7 +184,7 @@ class NodePanelViewItem : public BasicTreeViewItem {
void build_row(uiLayout &row) override
{
add_label(row);
this->add_label(row);
uiLayout *sub = uiLayoutRow(&row, true);
uiLayoutSetPropDecorate(sub, false);
@@ -241,7 +245,7 @@ class NodeTreeInterfaceView : public AbstractTreeView {
void build_tree() override
{
/* Draw root items */
add_items_for_panel_recursive(interface_.root_panel, *this);
this->add_items_for_panel_recursive(interface_.root_panel, *this);
}
protected:
@@ -275,25 +279,25 @@ class NodeTreeInterfaceView : public AbstractTreeView {
std::unique_ptr<AbstractViewItemDragController> NodeSocketViewItem::create_drag_controller() const
{
return std::make_unique<NodeTreeInterfaceDragController>(
static_cast<NodeTreeInterfaceView &>(get_tree_view()), socket_.item);
static_cast<NodeTreeInterfaceView &>(this->get_tree_view()), socket_.item);
}
std::unique_ptr<TreeViewItemDropTarget> NodeSocketViewItem::create_drop_target()
{
return std::make_unique<NodeSocketDropTarget>(
static_cast<NodeTreeInterfaceView &>(get_tree_view()), socket_);
static_cast<NodeTreeInterfaceView &>(this->get_tree_view()), socket_);
}
std::unique_ptr<AbstractViewItemDragController> NodePanelViewItem::create_drag_controller() const
{
return std::make_unique<NodeTreeInterfaceDragController>(
static_cast<NodeTreeInterfaceView &>(get_tree_view()), panel_.item);
static_cast<NodeTreeInterfaceView &>(this->get_tree_view()), panel_.item);
}
std::unique_ptr<TreeViewItemDropTarget> NodePanelViewItem::create_drop_target()
{
return std::make_unique<NodePanelDropTarget>(
static_cast<NodeTreeInterfaceView &>(get_tree_view()), panel_);
static_cast<NodeTreeInterfaceView &>(this->get_tree_view()), panel_);
}
NodeTreeInterfaceDragController::NodeTreeInterfaceDragController(NodeTreeInterfaceView &view,
@@ -358,10 +362,10 @@ bool NodeSocketDropTarget::on_drop(bContext *C, const DragInfo &drag_info) const
bNodeTreeInterfaceItem *drag_item = drag_data->item;
BLI_assert(drag_item != nullptr);
bNodeTree &nodetree = get_view<NodeTreeInterfaceView>().nodetree();
bNodeTreeInterface &interface = get_view<NodeTreeInterfaceView>().interface();
bNodeTree &nodetree = this->get_view<NodeTreeInterfaceView>().nodetree();
bNodeTreeInterface &interface = this->get_view<NodeTreeInterfaceView>().interface();
bNodeTreeInterfacePanel *parent = interface.find_item_parent(socket_.item);
bNodeTreeInterfacePanel *parent = interface.find_item_parent(socket_.item, true);
int index = -1;
/* Insert into same panel as the target. */
@@ -492,8 +496,6 @@ wmDragNodeTreeInterface *NodePanelDropTarget::get_drag_node_tree_declaration(
} // namespace blender::ui::nodes
namespace ui = blender::ui;
void uiTemplateNodeTreeInterface(uiLayout *layout, PointerRNA *ptr)
{
if (!ptr->data) {
@@ -507,11 +509,11 @@ void uiTemplateNodeTreeInterface(uiLayout *layout, PointerRNA *ptr)
uiBlock *block = uiLayoutGetBlock(layout);
ui::AbstractTreeView *tree_view = UI_block_add_view(
blender::ui::AbstractTreeView *tree_view = UI_block_add_view(
*block,
"Node Tree Declaration Tree View",
std::make_unique<blender::ui::nodes::NodeTreeInterfaceView>(nodetree, interface));
tree_view->set_min_rows(3);
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
blender::ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
}

View File

@@ -1111,10 +1111,6 @@ struct wmDragAssetCatalog {
bUUID drag_catalog_id;
};
typedef struct wmDragNodeTreeInterface {
struct bNodeTreeInterfaceItem *item;
} wmDragNodeTreeInterface;
/**
* For some specific cases we support dragging multiple assets (#WM_DRAG_ASSET_LIST). There is no
* proper support for dragging multiple items in the `wmDrag`/`wmDrop` API yet, so this is really