created NodeInputArray parameter type
It seems unwise to let NodeInputs take more than one value, but at times it makes sense to create a list or array of inputs. This class will create sub-parameters as an easy way to provide variable inputs while also enforcing one connection per input parameter. This is also the primary motivation for the previous commit (disambiguating when a NodeParam's parent is a Node vs some other type).
This commit is contained in:
@@ -32,6 +32,8 @@ set(OLIVE_SOURCES
|
||||
node/graph.cpp
|
||||
node/input.h
|
||||
node/input.cpp
|
||||
node/inputarray.h
|
||||
node/inputarray.cpp
|
||||
node/keyframe.h
|
||||
node/keyframe.cpp
|
||||
node/menu.h
|
||||
|
||||
+50
-1
@@ -1,6 +1,55 @@
|
||||
#include "inputarray.h"
|
||||
|
||||
InputArray::InputArray()
|
||||
#include "node.h"
|
||||
|
||||
NodeInputArray::NodeInputArray(const QString &id) :
|
||||
NodeInput(id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int NodeInputArray::GetSize() const
|
||||
{
|
||||
return sub_params_.size();
|
||||
}
|
||||
|
||||
void NodeInputArray::SetSize(int size)
|
||||
{
|
||||
int old_size = GetSize();
|
||||
|
||||
if (size == old_size) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (size < old_size) {
|
||||
// If the new size is less, delete all extraneous parameters
|
||||
for (int i=size;i<sub_params_.size();i++) {
|
||||
delete sub_params_.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
sub_params_.resize(size);
|
||||
|
||||
if (size > old_size) {
|
||||
// If the new size is greater, create valid parameters for each slot
|
||||
for (int i=old_size;i<size;i++) {
|
||||
QString sub_id = id();
|
||||
sub_id.append(QString::number(i));
|
||||
|
||||
Q_ASSERT(!parentNode()->HasParamWithID(sub_id));
|
||||
|
||||
NodeInput* new_param = new NodeInput(sub_id);
|
||||
new_param->setParent(this);
|
||||
sub_params_.replace(i, new_param);
|
||||
|
||||
connect(new_param, SIGNAL(ValueChanged(rational, rational)), this, SIGNAL(ValueChanged(rational, rational)));
|
||||
connect(new_param, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr)));
|
||||
connect(new_param, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NodeInput *NodeInputArray::ParamAt(int index)
|
||||
{
|
||||
return sub_params_.at(index);
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,11 +1,21 @@
|
||||
#ifndef INPUTARRAY_H
|
||||
#define INPUTARRAY_H
|
||||
|
||||
#include "input.h"
|
||||
|
||||
class InputArray
|
||||
class NodeInputArray : public NodeInput
|
||||
{
|
||||
public:
|
||||
InputArray();
|
||||
NodeInputArray(const QString &id);
|
||||
|
||||
int GetSize() const;
|
||||
void SetSize(int size);
|
||||
|
||||
NodeInput* ParamAt(int index);
|
||||
|
||||
private:
|
||||
QVector<NodeInput*> sub_params_;
|
||||
|
||||
};
|
||||
|
||||
#endif // INPUTARRAY_H
|
||||
|
||||
+6
-5
@@ -28,6 +28,7 @@
|
||||
#include "common/rational.h"
|
||||
#include "node/dependency.h"
|
||||
#include "node/input.h"
|
||||
#include "node/inputarray.h"
|
||||
#include "node/output.h"
|
||||
|
||||
/**
|
||||
@@ -254,6 +255,11 @@ public:
|
||||
*/
|
||||
virtual QVariant Value(NodeOutput* output);
|
||||
|
||||
/**
|
||||
* @brief Return whether a parameter with ID `id` has already been added to this Node
|
||||
*/
|
||||
bool HasParamWithID(const QString& id);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Add a parameter to this node
|
||||
@@ -309,11 +315,6 @@ signals:
|
||||
void EdgeRemoved(NodeEdgePtr edge);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Return whether a parameter with ID `id` has already been added to this Node
|
||||
*/
|
||||
bool HasParamWithID(const QString& id);
|
||||
|
||||
bool HasParamOfType(NodeParam::Type type, bool must_be_connected);
|
||||
|
||||
QList<NodeParam *> params_;
|
||||
|
||||
Reference in New Issue
Block a user