use nodes as context rather than void

This commit is contained in:
itsmattkc
2021-05-27 13:32:32 +10:00
parent 0c5c9f0794
commit f876240443
9 changed files with 57 additions and 55 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ void NodeGraph::Clear()
}
}
qreal NodeGraph::GetNodeContextHeight(void *context)
qreal NodeGraph::GetNodeContextHeight(Node *context)
{
const PositionMap &map = position_map_.value(context);
+17 -17
View File
@@ -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<Node*, QPointF>;
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<Node*> default_nodes_;
QMap<void *, PositionMap> position_map_;
QMap<Node *, PositionMap> position_map_;
PositionMap root_position_map_;
+8 -8
View File
@@ -1303,7 +1303,7 @@ using NodePtr = std::shared_ptr<Node>;
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_;
+1 -1
View File
@@ -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();
}
+9 -9
View File
@@ -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);
}
+1 -1
View File
@@ -40,7 +40,7 @@ public:
return node_view_->GetGraph();
}
void SetGraph(NodeGraph *graph, const QVector<void*> &nodes)
void SetGraph(NodeGraph *graph, const QVector<Node*> &nodes)
{
node_view_->SetGraph(graph, nodes);
}
+11 -11
View File
@@ -70,7 +70,7 @@ NodeView::~NodeView()
ClearGraph();
}
void NodeView::SetGraph(NodeGraph *graph, const QVector<void*> &nodes)
void NodeView::SetGraph(NodeGraph *graph, const QVector<Node*> &nodes)
{
bool graph_changed = graph_ != graph;
bool context_changed = filter_nodes_ != nodes;
@@ -126,8 +126,8 @@ void NodeView::SetGraph(NodeGraph *graph, const QVector<void*> &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<void*> &nodes)
void NodeView::ClearGraph()
{
SetGraph(nullptr, QVector<void*>());
SetGraph(nullptr, QVector<Node*>());
}
void NodeView::DeleteSelected()
@@ -851,7 +851,7 @@ void NodeView::ContextMenuFilterChanged(QAction *action)
if (filter_mode_ != mode) {
// Store temporary graph variables
NodeGraph *graph = graph_;
QVector<void*> nodes = filter_nodes_;
QVector<Node*> 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);
+5 -5
View File
@@ -51,7 +51,7 @@ public:
return graph_;
}
void SetGraph(NodeGraph *graph, const QVector<void *> &nodes);
void SetGraph(NodeGraph *graph, const QVector<Node *> &nodes);
void ClearGraph();
@@ -164,8 +164,8 @@ private:
FilterMode filter_mode_;
QVector<void*> filter_nodes_;
QMap<void*, QPointF> context_offsets_;
QVector<Node*> filter_nodes_;
QMap<Node*, QPointF> 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);
+4 -2
View File
@@ -719,7 +719,7 @@ void MainWindow::UpdateNodePanelContextFromTimelinePanel(TimelinePanel *panel)
{
// Add selected blocks (if any)
const QVector<Block*> &blocks = panel->GetSelectedBlocks();
QVector<void *> context(blocks.size());
QVector<Node *> context(blocks.size());
for (int i=0; i<blocks.size(); i++) {
context[i] = blocks.at(i);
}
@@ -748,7 +748,9 @@ void MainWindow::FocusedPanelChanged(PanelWidget *panel)
} else if (ProjectPanel* project = dynamic_cast<ProjectPanel*>(panel)) {
// Signal project panel focus
UpdateTitle();
node_panel_->SetGraph(project->project(), {project->project()});
if (project->project()) {
node_panel_->SetGraph(project->project(), {project->project()->root()});
}
}
}