diff --git a/app/node/graph.cpp b/app/node/graph.cpp index 6029b7063..0527b4d16 100644 --- a/app/node/graph.cpp +++ b/app/node/graph.cpp @@ -44,7 +44,7 @@ void NodeGraph::Clear() } } -qreal NodeGraph::GetNodeContextHeight(void *context) +qreal NodeGraph::GetNodeContextHeight(Node *context) { const PositionMap &map = position_map_.value(context); diff --git a/app/node/graph.h b/app/node/graph.h index 1751d49a5..5ebe8d5fa 100644 --- a/app/node/graph.h +++ b/app/node/graph.h @@ -63,39 +63,39 @@ public: return default_nodes_; } - bool NodeMapContainsNode(Node* node, void* relative) const + bool NodeMapContainsNode(Node* node, Node* context) const { - return position_map_.value(relative).contains(node); + return position_map_.value(context).contains(node); } - QPointF GetNodePosition(Node* node, void* relative) + QPointF GetNodePosition(Node* node, Node* context) { - return position_map_.value(relative).value(node); + return position_map_.value(context).value(node); } - void SetNodePosition(Node* node, void* relative, const QPointF& pos) + void SetNodePosition(Node* node, Node* context, const QPointF& pos) { - position_map_[relative].insert(node, pos); - emit NodePositionAdded(node, relative, pos); + position_map_[context].insert(node, pos); + emit NodePositionAdded(node, context, pos); } - void RemoveNodePosition(Node* node, void* relative) + void RemoveNodePosition(Node* node, Node* context) { - PositionMap& map = position_map_[relative]; + PositionMap& map = position_map_[context]; map.remove(node); if (map.isEmpty()) { - position_map_.remove(relative); + position_map_.remove(context); } - emit NodePositionRemoved(node, relative);; + emit NodePositionRemoved(node, context); } - qreal GetNodeContextHeight(void *context); + qreal GetNodeContextHeight(Node *context); using PositionMap = QMap; - const PositionMap &GetNodesForRelative(void *relative) + const PositionMap &GetNodesForContext(Node *context) { - return position_map_[relative]; + return position_map_[context]; } signals: @@ -115,9 +115,9 @@ signals: void ValueChanged(const NodeInput& input); - void NodePositionAdded(Node *node, void *relative, const QPointF &position); + void NodePositionAdded(Node *node, Node *relative, const QPointF &position); - void NodePositionRemoved(Node *node, void *relative); + void NodePositionRemoved(Node *node, Node *relative); protected: void AddDefaultNode(Node* n) @@ -132,7 +132,7 @@ private: QVector default_nodes_; - QMap position_map_; + QMap position_map_; PositionMap root_position_map_; diff --git a/app/node/node.h b/app/node/node.h index 914761420..44c384fb6 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -1303,7 +1303,7 @@ using NodePtr = std::shared_ptr; class NodeSetPositionCommand : public UndoCommand { public: - NodeSetPositionCommand(Node* node, void* relevant, const QPointF& pos, bool move_dependencies_relatively) + NodeSetPositionCommand(Node* node, Node* relevant, const QPointF& pos, bool move_dependencies_relatively) { node_ = node; relevant_ = relevant; @@ -1322,7 +1322,7 @@ public: private: Node* node_; - void* relevant_; + Node* relevant_; QPointF pos_; QPointF old_pos_; bool added_; @@ -1333,7 +1333,7 @@ private: class NodeSetPositionAndShiftSurroundingsCommand : public UndoCommand { public: - NodeSetPositionAndShiftSurroundingsCommand(Node* node, void *relative, const QPointF& pos, bool move_dependencies_relatively) : + NodeSetPositionAndShiftSurroundingsCommand(Node* node, Node *relative, const QPointF& pos, bool move_dependencies_relatively) : node_(node), relative_(relative), position_(pos), @@ -1362,7 +1362,7 @@ public: private: Node* node_; - void *relative_; + Node *relative_; QPointF position_; @@ -1375,7 +1375,7 @@ private: class NodeSetPositionAsChildCommand : public UndoCommand { public: - NodeSetPositionAsChildCommand(Node* node, Node* parent, void *relative, int this_index, int child_count, bool shift_surroundings) : + NodeSetPositionAsChildCommand(Node* node, Node* parent, Node *relative, int this_index, int child_count, bool shift_surroundings) : node_(node), parent_(parent), relative_(relative), @@ -1406,7 +1406,7 @@ public: private: Node* node_; Node* parent_; - void *relative_; + Node *relative_; int this_index_; int child_count_; @@ -1420,7 +1420,7 @@ private: class NodeSetPositionToOffsetOfAnotherNodeCommand : public UndoCommand { public: - NodeSetPositionToOffsetOfAnotherNodeCommand(Node* node, Node* other_node, void *relative, const QPointF& offset) : + NodeSetPositionToOffsetOfAnotherNodeCommand(Node* node, Node* other_node, Node *relative, const QPointF& offset) : node_(node), other_node_(other_node), relative_(relative), @@ -1439,7 +1439,7 @@ public: private: Node* node_; Node* other_node_; - void *relative_; + Node *relative_; QPointF offset_; QPointF old_pos_; diff --git a/app/node/project/folder/folder.cpp b/app/node/project/folder/folder.cpp index 576d8b829..336feb6bc 100644 --- a/app/node/project/folder/folder.cpp +++ b/app/node/project/folder/folder.cpp @@ -139,7 +139,7 @@ void FolderAddChild::redo() if (autoposition_) { if (!position_command_) { - position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, folder_->project(), array_index, array_index+1, true); + position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, folder_->project()->root(), array_index, array_index+1, true); } position_command_->redo(); } diff --git a/app/node/project/project.cpp b/app/node/project/project.cpp index 35a8b485b..a3f4aca9e 100644 --- a/app/node/project/project.cpp +++ b/app/node/project/project.cpp @@ -39,27 +39,27 @@ Project::Project() : // Generate UUID for this project RegenerateUuid(); + // Folder root for project + root_ = new Folder(); + root_->setParent(this); + root_->SetLabel(tr("Root")); + root_->SetCanBeDeleted(false); + SetNodePosition(root_, root_, QPointF(0, 0)); + // Adds a color manager "node" to this project so that it synchronizes color_manager_ = new ColorManager(); color_manager_->setParent(this); - SetNodePosition(color_manager_, this, QPointF(1, 0)); + SetNodePosition(color_manager_, root_, QPointF(1, 0)); color_manager_->SetCanBeDeleted(false); AddDefaultNode(color_manager_); // Same with project settings settings_ = new ProjectSettingsNode(); settings_->setParent(this); - SetNodePosition(settings_, this, QPointF(2, 0)); + SetNodePosition(settings_, root_, QPointF(2, 0)); settings_->SetCanBeDeleted(false); AddDefaultNode(settings_); - // Folder root for project - root_ = new Folder(); - root_->setParent(this); - root_->SetLabel(tr("Root")); - root_->SetCanBeDeleted(false); - SetNodePosition(root_, this, QPointF(0, 0)); - connect(color_manager(), &ColorManager::ValueChanged, this, &Project::ColorManagerValueChanged); } diff --git a/app/panel/node/node.h b/app/panel/node/node.h index 02600ec65..c465bf725 100644 --- a/app/panel/node/node.h +++ b/app/panel/node/node.h @@ -40,7 +40,7 @@ public: return node_view_->GetGraph(); } - void SetGraph(NodeGraph *graph, const QVector &nodes) + void SetGraph(NodeGraph *graph, const QVector &nodes) { node_view_->SetGraph(graph, nodes); } diff --git a/app/widget/nodeview/nodeview.cpp b/app/widget/nodeview/nodeview.cpp index ac037f2b2..e8e07eac4 100644 --- a/app/widget/nodeview/nodeview.cpp +++ b/app/widget/nodeview/nodeview.cpp @@ -70,7 +70,7 @@ NodeView::~NodeView() ClearGraph(); } -void NodeView::SetGraph(NodeGraph *graph, const QVector &nodes) +void NodeView::SetGraph(NodeGraph *graph, const QVector &nodes) { bool graph_changed = graph_ != graph; bool context_changed = filter_nodes_ != nodes; @@ -126,8 +126,8 @@ void NodeView::SetGraph(NodeGraph *graph, const QVector &nodes) qreal last_offset = 0; int additional_spacing = 0; - foreach (void *n, filter_nodes_) { - const NodeGraph::PositionMap &map = graph_->GetNodesForRelative(n); + foreach (Node *n, filter_nodes_) { + const NodeGraph::PositionMap &map = graph_->GetNodesForContext(n); // First determine the total "height" of this graph and how much we need to offset it qreal top = 0; @@ -154,7 +154,7 @@ void NodeView::SetGraph(NodeGraph *graph, const QVector &nodes) void NodeView::ClearGraph() { - SetGraph(nullptr, QVector()); + SetGraph(nullptr, QVector()); } void NodeView::DeleteSelected() @@ -851,7 +851,7 @@ void NodeView::ContextMenuFilterChanged(QAction *action) if (filter_mode_ != mode) { // Store temporary graph variables NodeGraph *graph = graph_; - QVector nodes = filter_nodes_; + QVector nodes = filter_nodes_; // Unset graph with current filter mode ClearGraph(); @@ -905,7 +905,7 @@ void NodeView::RemoveEdge(const NodeOutput &output, const NodeInput &input) scene_.RemoveEdge(output, input); } -void NodeView::AddNodePosition(Node *node, void *relative) +void NodeView::AddNodePosition(Node *node, Node *relative) { if (filter_mode_ == kFilterShowSelective) { if (filter_nodes_.contains(relative)) { @@ -918,8 +918,8 @@ void NodeView::AddNodePosition(Node *node, void *relative) // Determine "view" position by averaging the Y value and "min"ing the X value of all contexts QPointF item_pos(DBL_MAX, 0.0); int average_count = 0; - foreach (void *context, filter_nodes_) { - if (graph_->GetNodesForRelative(context).contains(node)) { + foreach (Node *context, filter_nodes_) { + if (graph_->GetNodesForContext(context).contains(node)) { QPointF this_context_pos = graph_->GetNodePosition(node, context); this_context_pos += context_offsets_.value(context); item_pos.setX(qMin(item_pos.x(), this_context_pos.x())); @@ -936,7 +936,7 @@ void NodeView::AddNodePosition(Node *node, void *relative) } } -void NodeView::RemoveNodePosition(Node *node, void *relative) +void NodeView::RemoveNodePosition(Node *node, Node *relative) { if (filter_mode_ == kFilterShowSelective) { if (filter_nodes_.contains(relative)) { @@ -953,8 +953,8 @@ void NodeView::NodePositionChanged(NodeViewItem *item, const QPointF &pos) QPointF diff = pos - original_pos.original_item_pos; original_pos.original_item_pos = pos; - foreach (void *context, filter_nodes_) { - if (graph_->GetNodesForRelative(context).contains(node)) { + foreach (Node *context, filter_nodes_) { + if (graph_->GetNodesForContext(context).contains(node)) { QPointF p = graph_->GetNodePosition(node, context); p += diff; graph_->SetNodePosition(node, context, p); diff --git a/app/widget/nodeview/nodeview.h b/app/widget/nodeview/nodeview.h index 5cf9f8502..c07536f2c 100644 --- a/app/widget/nodeview/nodeview.h +++ b/app/widget/nodeview/nodeview.h @@ -51,7 +51,7 @@ public: return graph_; } - void SetGraph(NodeGraph *graph, const QVector &nodes); + void SetGraph(NodeGraph *graph, const QVector &nodes); void ClearGraph(); @@ -164,8 +164,8 @@ private: FilterMode filter_mode_; - QVector filter_nodes_; - QMap context_offsets_; + QVector filter_nodes_; + QMap context_offsets_; double scale_; @@ -214,8 +214,8 @@ private slots: void AddEdge(const NodeOutput& output, const NodeInput& input); void RemoveEdge(const NodeOutput& output, const NodeInput& input); - void AddNodePosition(Node *node, void *relative); - void RemoveNodePosition(Node *node, void *relative); + void AddNodePosition(Node *node, Node *relative); + void RemoveNodePosition(Node *node, Node *relative); void NodePositionChanged(NodeViewItem *item, const QPointF &pos); diff --git a/app/window/mainwindow/mainwindow.cpp b/app/window/mainwindow/mainwindow.cpp index 7f3d00d56..4acd6a562 100644 --- a/app/window/mainwindow/mainwindow.cpp +++ b/app/window/mainwindow/mainwindow.cpp @@ -719,7 +719,7 @@ void MainWindow::UpdateNodePanelContextFromTimelinePanel(TimelinePanel *panel) { // Add selected blocks (if any) const QVector &blocks = panel->GetSelectedBlocks(); - QVector context(blocks.size()); + QVector context(blocks.size()); for (int i=0; i(panel)) { // Signal project panel focus UpdateTitle(); - node_panel_->SetGraph(project->project(), {project->project()}); + if (project->project()) { + node_panel_->SetGraph(project->project(), {project->project()->root()}); + } } }