diff --git a/app/node/inputarray.cpp b/app/node/inputarray.cpp index cbc830a02..e6ed231d5 100644 --- a/app/node/inputarray.cpp +++ b/app/node/inputarray.cpp @@ -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;iindex;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;iIsConnected()) { + // 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(); +} diff --git a/app/node/inputarray.h b/app/node/inputarray.h index 3fd3b043d..924deacc0 100644 --- a/app/node/inputarray.h +++ b/app/node/inputarray.h @@ -5,13 +5,25 @@ class NodeInputArray : public NodeInput { + Q_OBJECT public: NodeInputArray(const QString &id); int GetSize() const; + + void Prepend(); + void Append(); + void InsertAt(int index); + void RemoveLast(); + void RemoveAt(int index); void SetSize(int size); - NodeInput* ParamAt(int index); + int IndexOfSubParameter(NodeInput* input) const; + + NodeInput* ParamAt(int index) const; + +signals: + void SizeChanged(int size); private: QVector sub_params_;