nodeparamview: remove item when nodes is removed from context

This commit is contained in:
itsmattkc
2022-04-09 15:36:49 -07:00
parent 48adb159b8
commit 1448f641e5
6 changed files with 41 additions and 7 deletions
+14 -3
View File
@@ -246,6 +246,7 @@ void NodeParamView::SetContexts(const QVector<Node *> &contexts, bool group_mode
foreach (Node *ctx, contexts_) {
disconnect(ctx, &Node::NodeAddedToContext, this, &NodeParamView::NodeAddedToContext);
disconnect(ctx, &Node::NodeRemovedFromContext, this, &NodeParamView::NodeRemovedFromContext);
}
contexts_ = contexts;
@@ -257,6 +258,7 @@ void NodeParamView::SetContexts(const QVector<Node *> &contexts, bool group_mode
// Queued so that if any further work is done in connecting this node to the context, it'll be
// done before our sorting function is called
connect(ctx, &Node::NodeAddedToContext, this, &NodeParamView::NodeAddedToContext, Qt::QueuedConnection);
connect(ctx, &Node::NodeRemovedFromContext, this, &NodeParamView::NodeRemovedFromContext, Qt::QueuedConnection);
}
if (keyframe_view_) {
@@ -275,7 +277,7 @@ void NodeParamView::SetContexts(const QVector<Node *> &contexts, bool group_mode
item->setVisible(true);
for (auto it=ctx->GetContextPositions().cbegin(); it!=ctx->GetContextPositions().cend(); it++) {
AddNode(it.key(), item);
AddNode(it.key(), ctx, item);
}
}
@@ -389,7 +391,7 @@ void NodeParamView::QueueKeyframePositionUpdate()
QMetaObject::invokeMethod(this, &NodeParamView::UpdateElementY, Qt::QueuedConnection);
}
void NodeParamView::AddNode(Node *n, NodeParamViewContext *context)
void NodeParamView::AddNode(Node *n, Node *ctx, NodeParamViewContext *context)
{
if ((n->GetFlags() & Node::kDontShowInParamView) && !group_mode_) {
return;
@@ -402,6 +404,7 @@ void NodeParamView::AddNode(Node *n, NodeParamViewContext *context)
connect(item, &NodeParamViewItem::PinToggled, this, &NodeParamView::PinNode);
connect(item, &NodeParamViewItem::InputCheckedChanged, this, &NodeParamView::InputCheckBoxChanged);
item->SetContext(ctx);
item->SetTimeTarget(GetTimeTarget());
item->SetTimebase(timebase());
item->SetTime(GetTime());
@@ -608,11 +611,19 @@ void NodeParamView::NodeAddedToContext(Node *n)
Node *ctx = static_cast<Node*>(sender());
NodeParamViewContext *item = GetContextItemFromContext(ctx);
AddNode(n, item);
AddNode(n, ctx, item);
SortItemsInContext(item);
}
void NodeParamView::NodeRemovedFromContext(Node *n)
{
Node *ctx = static_cast<Node*>(sender());
NodeParamViewContext *item = GetContextItemFromContext(ctx);
item->RemoveNode(n, ctx);
}
void NodeParamView::InputCheckBoxChanged(const NodeInput &input, bool e)
{
NodeGroup *group = static_cast<NodeGroup*>(contexts_.first());
+3 -1
View File
@@ -93,7 +93,7 @@ private:
void QueueKeyframePositionUpdate();
void AddNode(Node* n, NodeParamViewContext *context);
void AddNode(Node* n, Node *ctx, NodeParamViewContext *context);
void SortItemsInContext(NodeParamViewContext *context);
@@ -136,6 +136,8 @@ private slots:
void NodeAddedToContext(Node *n);
void NodeRemovedFromContext(Node *n);
void InputCheckBoxChanged(const NodeInput &input, bool e);
void GroupInputPassthroughAdded(olive::NodeGroup *group, const olive::NodeInput &input);
@@ -51,8 +51,16 @@ void NodeParamViewContext::AddNode(NodeParamViewItem *item)
dock_area_->AddItem(item);
}
void NodeParamViewContext::RemoveNode(Node *node)
void NodeParamViewContext::RemoveNode(Node *node, Node *ctx)
{
for (auto it=items_.begin(); it!=items_.end(); ) {
if (it.value()->GetContext() == ctx) {
delete it.value();
it = items_.erase(it);
} else {
it++;
}
}
}
void NodeParamViewContext::Clear()
@@ -50,7 +50,7 @@ public:
void AddNode(NodeParamViewItem *item);
void RemoveNode(Node *node);
void RemoveNode(Node *node, Node *ctx);
void Clear();
@@ -46,7 +46,8 @@ const int NodeParamViewItemBody::kMaxWidgetColumn = kKeyControlColumn;
NodeParamViewItem::NodeParamViewItem(Node *node, NodeParamViewCheckBoxBehavior create_checkboxes, QWidget *parent) :
super(parent),
node_(node)
node_(node),
ctx_(nullptr)
{
node_->Retranslate();
@@ -182,6 +182,16 @@ public:
body_->SetTimebase(timebase);
}
Node *GetContext() const
{
return ctx_;
}
void SetContext(Node *ctx)
{
ctx_ = ctx;
}
Node* GetNode() const
{
return node_;
@@ -218,6 +228,8 @@ private:
Node* node_;
Node *ctx_;
rational time_;
KeyframeView::NodeConnections keyframe_connections_;