added convenience functions for working with NodeInputArray
NodeInputArray has to work a certain way internally, but it can still provide array-like convenience functions to the rest of the program.
This commit is contained in:
+91
-2
@@ -13,6 +13,11 @@ int NodeInputArray::GetSize() const
|
||||
return sub_params_.size();
|
||||
}
|
||||
|
||||
void NodeInputArray::Prepend()
|
||||
{
|
||||
InsertAt(0);
|
||||
}
|
||||
|
||||
void NodeInputArray::SetSize(int size)
|
||||
{
|
||||
int old_size = GetSize();
|
||||
@@ -23,7 +28,7 @@ void NodeInputArray::SetSize(int size)
|
||||
|
||||
if (size < old_size) {
|
||||
// If the new size is less, delete all extraneous parameters
|
||||
for (int i=size;i<sub_params_.size();i++) {
|
||||
for (int i=size;i<old_size;i++) {
|
||||
delete sub_params_.at(i);
|
||||
}
|
||||
}
|
||||
@@ -47,9 +52,93 @@ void NodeInputArray::SetSize(int size)
|
||||
connect(new_param, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
|
||||
}
|
||||
}
|
||||
|
||||
emit SizeChanged(size);
|
||||
}
|
||||
|
||||
NodeInput *NodeInputArray::ParamAt(int index)
|
||||
int NodeInputArray::IndexOfSubParameter(NodeInput *input) const
|
||||
{
|
||||
return sub_params_.indexOf(input);
|
||||
}
|
||||
|
||||
NodeInput *NodeInputArray::ParamAt(int index) const
|
||||
{
|
||||
return sub_params_.at(index);
|
||||
}
|
||||
|
||||
void NodeInputArray::InsertAt(int index)
|
||||
{
|
||||
qDebug() << "Inserted at";
|
||||
|
||||
// Add another input at the end
|
||||
Append();
|
||||
|
||||
// Shift all connections from index down
|
||||
for (int i=sub_params_.size()-1;i>index;i--) {
|
||||
NodeInput* this_param = sub_params_.at(i);
|
||||
NodeInput* prev_param = sub_params_.at(i-1);
|
||||
|
||||
if (this_param->IsConnected()) {
|
||||
// Disconnect whatever is at this parameter (presumably its connection has already been copied so we can just remove it)
|
||||
NodeParam::DisconnectEdge(this_param->edges().first());
|
||||
}
|
||||
|
||||
if (prev_param->IsConnected()) {
|
||||
// Get edge here (only one since it's an input)
|
||||
NodeEdgePtr edge = prev_param->edges().first();
|
||||
|
||||
// Disconnect it
|
||||
NodeParam::DisconnectEdge(edge);
|
||||
|
||||
// Create a new edge between it and the next one down
|
||||
NodeParam::ConnectEdge(edge->output(),
|
||||
this_param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NodeInputArray::Append()
|
||||
{
|
||||
qDebug() << "Appended";
|
||||
|
||||
SetSize(GetSize() + 1);
|
||||
}
|
||||
|
||||
void NodeInputArray::RemoveLast()
|
||||
{
|
||||
qDebug() << "Removed last";
|
||||
|
||||
SetSize(GetSize() - 1);
|
||||
}
|
||||
|
||||
void NodeInputArray::RemoveAt(int index)
|
||||
{
|
||||
qDebug() << "Removed at";
|
||||
|
||||
int limit = sub_params_.size() - 1;
|
||||
|
||||
// Shift all connections from index down
|
||||
for (int i=index;i<limit;i++) {
|
||||
NodeInput* this_param = sub_params_.at(i);
|
||||
NodeInput* next_param = sub_params_.at(i + 1);
|
||||
|
||||
if (this_param->IsConnected()) {
|
||||
// Disconnect current edge
|
||||
NodeParam::DisconnectEdge(this_param->edges().first());
|
||||
}
|
||||
|
||||
if (next_param->IsConnected()) {
|
||||
// Get edge from next param
|
||||
NodeEdgePtr edge = next_param->edges().first();
|
||||
|
||||
// Disconnect it
|
||||
NodeParam::DisconnectEdge(edge);
|
||||
|
||||
// Reconnect it to this param
|
||||
NodeParam::ConnectEdge(edge->output(),
|
||||
this_param);
|
||||
}
|
||||
}
|
||||
|
||||
RemoveLast();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user