use std::map instead of QMap for the node connections
std::map gives us a reverse iterator which we need. QMap doesn't seem to.
This commit is contained in:
@@ -30,17 +30,17 @@ void NodeConnectable::ConnectEdge(Node *output, NodeInput *input, int element)
|
||||
InputConnection conn_to_in = {input, element};
|
||||
|
||||
// Connection exists
|
||||
if (output->output_connections_.contains(conn_to_in)) {
|
||||
if (std::find(output->output_connections_.begin(), output->output_connections_.end(), conn_to_in) != output->output_connections_.end()) {
|
||||
qDebug() << "Ignored connect that already exists";
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure a connection isn't getting overwritten
|
||||
Q_ASSERT(!input->input_connections_.contains(element));
|
||||
Q_ASSERT(input->input_connections_.find(element) == input->input_connections_.end());
|
||||
|
||||
// Insert connections in both sides
|
||||
output->output_connections_.append(conn_to_in);
|
||||
input->input_connections_.insert(element, output);
|
||||
output->output_connections_.push_back(conn_to_in);
|
||||
input->input_connections_[element] = output;
|
||||
|
||||
// Emit signals
|
||||
emit input->InputConnected(output, element);
|
||||
@@ -52,17 +52,17 @@ void NodeConnectable::DisconnectEdge(Node *output, NodeInput *input, int element
|
||||
InputConnection conn_to_in = {input, element};
|
||||
|
||||
// Connection exists
|
||||
if (!output->output_connections_.contains(conn_to_in)) {
|
||||
if (std::find(output->output_connections_.begin(), output->output_connections_.end(), conn_to_in) == output->output_connections_.end()) {
|
||||
qDebug() << "Ignored disconnect that doesn't exist";
|
||||
return;
|
||||
}
|
||||
|
||||
// Assertions to ensure connection exists
|
||||
Q_ASSERT(input->input_connections_.value(element) == output);
|
||||
Q_ASSERT(input->input_connections_.at(element) == output);
|
||||
|
||||
// Remove connections from both sides
|
||||
output->output_connections_.removeOne(conn_to_in);
|
||||
input->input_connections_.remove(element);
|
||||
output->output_connections_.erase(std::find(output->output_connections_.begin(), output->output_connections_.end(), conn_to_in));
|
||||
input->input_connections_.erase(input->input_connections_.find(element));
|
||||
|
||||
// Emit signals
|
||||
emit input->InputDisconnected(output, element);
|
||||
|
||||
@@ -72,20 +72,20 @@ signals:
|
||||
void InputDisconnected(Node* source, int element);
|
||||
|
||||
protected:
|
||||
const QVector<InputConnection>& output_connections() const
|
||||
const std::vector<InputConnection>& output_connections() const
|
||||
{
|
||||
return output_connections_;
|
||||
}
|
||||
|
||||
const QMap<int, Node*>& input_connections() const
|
||||
const std::map<int, Node*>& input_connections() const
|
||||
{
|
||||
return input_connections_;
|
||||
}
|
||||
|
||||
private:
|
||||
QVector<InputConnection> output_connections_;
|
||||
std::vector<InputConnection> output_connections_;
|
||||
|
||||
QMap<int, Node*> input_connections_;
|
||||
std::map<int, Node*> input_connections_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
+20
-21
@@ -66,10 +66,10 @@ QString NodeInput::name() const
|
||||
|
||||
void NodeInput::DisconnectAll()
|
||||
{
|
||||
auto copied_edges = edges();
|
||||
std::map<int, Node*> copied_edges = edges();
|
||||
|
||||
for (auto it=copied_edges.cbegin(); it!=copied_edges.cend(); it++) {
|
||||
DisconnectEdge(it.value(), this, it.key());
|
||||
DisconnectEdge(it->second, this, it->first);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,9 +154,9 @@ void NodeInput::Save(QXmlStreamWriter *writer) const
|
||||
for (auto it=input_connections().cbegin(); it!=input_connections().cend(); it++) {
|
||||
writer->writeStartElement(QStringLiteral("connection"));
|
||||
|
||||
writer->writeAttribute(QStringLiteral("element"), QString::number(it.key()));
|
||||
writer->writeAttribute(QStringLiteral("element"), QString::number(it->first));
|
||||
|
||||
writer->writeCharacters(QString::number(reinterpret_cast<quintptr>(it.value())));
|
||||
writer->writeCharacters(QString::number(reinterpret_cast<quintptr>(it->second)));
|
||||
|
||||
writer->writeEndElement(); // connection
|
||||
}
|
||||
@@ -389,9 +389,9 @@ NodeInputImmediate *NodeInput::CreateImmediate()
|
||||
void NodeInput::GetDependencies(QVector<Node *> &list, bool traverse, bool exclusive_only) const
|
||||
{
|
||||
for (auto it=input_connections().cbegin(); it!=input_connections().cend(); it++) {
|
||||
if (it.value()->edges().size() == 1 || !exclusive_only) {
|
||||
Node* connected = it.value();
|
||||
Node* connected = it->second;
|
||||
|
||||
if (connected->edges().size() == 1 || !exclusive_only) {
|
||||
if (!list.contains(connected)) {
|
||||
list.append(connected);
|
||||
|
||||
@@ -439,12 +439,12 @@ void NodeInput::ArrayInsert(int index)
|
||||
subinputs_.insert(index, CreateImmediate());
|
||||
|
||||
// Move connections down
|
||||
auto copied_edges = edges();
|
||||
for (auto it=copied_edges.cend(); it!=copied_edges.cbegin(); it--) {
|
||||
if (it.key() >= index) {
|
||||
std::map<int, Node*> copied_edges = edges();
|
||||
for (auto it=copied_edges.crbegin(); it!=copied_edges.crend(); it++) {
|
||||
if (it->first >= index) {
|
||||
// Disconnect this and reconnect it one element down
|
||||
DisconnectEdge(it.value(), this, it.key());
|
||||
ConnectEdge(it.value(), this, it.key() + 1);
|
||||
DisconnectEdge(it->second, this, it->first);
|
||||
ConnectEdge(it->second, this, it->first + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,14 +454,14 @@ void NodeInput::ArrayInsert(int index)
|
||||
void NodeInput::ArrayRemove(int index)
|
||||
{
|
||||
// Move connections up
|
||||
auto copied_edges = edges();
|
||||
std::map<int, Node*> copied_edges = edges();
|
||||
for (auto it=copied_edges.cbegin(); it!=copied_edges.cend(); it++) {
|
||||
if (it.key() >= index) {
|
||||
if (it->first >= index) {
|
||||
// Disconnect this and reconnect it one element up if it's not the element being removed
|
||||
DisconnectEdge(it.value(), this, it.key());
|
||||
DisconnectEdge(it->second, this, it->first);
|
||||
|
||||
if (it.key() > index) {
|
||||
ConnectEdge(it.value(), this, it.key() - 1);
|
||||
if (it->first > index) {
|
||||
ConnectEdge(it->second, this, it->first - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,10 +482,9 @@ void NodeInput::ArrayResize(int size)
|
||||
if (array_size_ > size) {
|
||||
// Decreasing in size, disconnect any extraneous edges
|
||||
for (int i=size; i<array_size_; i++) {
|
||||
Node* connection = edges().value(i);
|
||||
if (connection) {
|
||||
DisconnectEdge(connection, this, i);
|
||||
}
|
||||
try {
|
||||
DisconnectEdge(edges().at(i), this, i);
|
||||
} catch (std::out_of_range&) {}
|
||||
}
|
||||
|
||||
// Note that we do not delete any immediates since the user might still want that data.
|
||||
@@ -650,7 +649,7 @@ void NodeInput::CopyValues(NodeInput *source, NodeInput *dest, bool include_conn
|
||||
if (traverse_arrays) {
|
||||
// Copy all connections
|
||||
for (auto it=source->input_connections().cbegin(); it!=source->input_connections().cend(); it++) {
|
||||
ConnectEdge(it.value(), dest, it.key());
|
||||
ConnectEdge(it->second, dest, it->first);
|
||||
}
|
||||
} else {
|
||||
// Just copy the primary connection (at -1)
|
||||
|
||||
+3
-3
@@ -106,14 +106,14 @@ public:
|
||||
emit DataTypeChanged(type);
|
||||
}
|
||||
|
||||
const QMap<int, Node*>& edges() const
|
||||
const std::map<int, Node*>& edges() const
|
||||
{
|
||||
return input_connections();
|
||||
}
|
||||
|
||||
bool IsConnected(int element = -1) const
|
||||
{
|
||||
return input_connections().contains(element);
|
||||
return input_connections().find(element) != input_connections().end();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
|
||||
Node* GetConnectedNode(int element = -1) const
|
||||
{
|
||||
return input_connections().value(element);
|
||||
return input_connections().at(element);
|
||||
}
|
||||
|
||||
bool IsConnectable() const
|
||||
|
||||
+10
-10
@@ -167,7 +167,7 @@ void Node::RemoveNodeAndDisconnect(Node *node, QUndoCommand *command)
|
||||
|
||||
foreach (NodeInput* input, node->inputs_) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
new NodeEdgeRemoveCommand(it.value(), input, it.key(), command);
|
||||
new NodeEdgeRemoveCommand(it->second, input, it->first, command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ void Node::CopyDependencyGraph(const QVector<Node *> &src, const QVector<Node *>
|
||||
for (int i=0; i<src.size(); i++) {
|
||||
foreach (NodeInput* input, src.at(i)->inputs()) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
int connection_index = src.indexOf(it.value());
|
||||
int connection_index = src.indexOf(it->second);
|
||||
|
||||
if (connection_index > -1) {
|
||||
// Found a connection
|
||||
@@ -258,9 +258,9 @@ void Node::CopyDependencyGraph(const QVector<Node *> &src, const QVector<Node *>
|
||||
NodeInput* dst_input = dst.at(i)->GetInputWithID(input->id());
|
||||
|
||||
if (command) {
|
||||
new NodeEdgeAddCommand(dst_output, dst_input, it.key(), command);
|
||||
new NodeEdgeAddCommand(dst_output, dst_input, it->first, command);
|
||||
} else {
|
||||
ConnectEdge(dst_output, dst_input, it.key());
|
||||
ConnectEdge(dst_output, dst_input, it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -560,7 +560,7 @@ bool Node::InputsFrom(Node *n, bool recursively) const
|
||||
{
|
||||
foreach (NodeInput* input, inputs_) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
Node* connected = it.value();
|
||||
Node* connected = it->second;
|
||||
|
||||
if (connected == n) {
|
||||
return true;
|
||||
@@ -577,7 +577,7 @@ bool Node::InputsFrom(const QString &id, bool recursively) const
|
||||
{
|
||||
foreach (NodeInput* input, inputs_) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
Node* connected = it.value();
|
||||
Node* connected = it->second;
|
||||
|
||||
if (connected->id() == id) {
|
||||
return true;
|
||||
@@ -615,8 +615,8 @@ int Node::GetRoutesTo(Node *n) const
|
||||
void Node::DisconnectAll()
|
||||
{
|
||||
// Disconnect outputs (inputs will be disconnected in their respective destructors)
|
||||
while (!edges().isEmpty()) {
|
||||
DisconnectEdge(this, edges().first().input, edges().first().element);
|
||||
while (!edges().empty()) {
|
||||
DisconnectEdge(this, edges().front().input, edges().front().element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,8 +661,8 @@ QVector<TimeRange> Node::TransformTimeTo(const TimeRange &time, Node *target, bo
|
||||
// If this input is connected, traverse it to see if we stumble across the specified `node`
|
||||
foreach (NodeInput* input, inputs_) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
TimeRange input_adjustment = InputTimeAdjustment(input, it.key(), time);
|
||||
Node* connected = it.value();
|
||||
TimeRange input_adjustment = InputTimeAdjustment(input, it->first, time);
|
||||
Node* connected = it->second;
|
||||
|
||||
if (connected == target) {
|
||||
// We found the target, no need to keep traversing
|
||||
|
||||
+3
-2
@@ -396,7 +396,7 @@ public:
|
||||
|
||||
virtual void Hash(QCryptographicHash& hash, const rational &time) const;
|
||||
|
||||
const QVector<InputConnection>& edges() const
|
||||
const std::vector<InputConnection>& edges() const
|
||||
{
|
||||
return output_connections();
|
||||
}
|
||||
@@ -491,7 +491,8 @@ template<class T>
|
||||
void Node::FindInputNodeInternal(const Node* n, QVector<T *> &list)
|
||||
{
|
||||
foreach (NodeInput* input, n->inputs_) {
|
||||
foreach (Node* edge, input->edges()) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
Node* edge = it->second;
|
||||
T* cast_test = dynamic_cast<T*>(edge);
|
||||
|
||||
if (cast_test) {
|
||||
|
||||
@@ -679,7 +679,7 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
|
||||
foreach (Node* node, graph->nodes()) {
|
||||
foreach (NodeInput* input, node->inputs()) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
AddEdge(it.value(), input, it.key());
|
||||
AddEdge(it->second, input, it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user