bool PlugHandle::connectPlug(PlugHandle other) { #ifdef QT_DEBUG Q_ASSERT(m_isValid); #else if(!m_isValid){ return false; } #endif if(m_plug->getDirection() == PlugDirection::OUT){ return m_plug->getNode()->getScene()->createEdge(m_plug, other.data()) != nullptr; } else { return m_plug->getNode()->getScene()->createEdge(other.data(), m_plug) != nullptr; } }
bool NodeCtrl::removePlug(const QString & name) { // get the plug that is about to be removed PlugHandle plug = m_node.getPlug(name); if (!plug.isValid() || !plug.isRemovable()) { return false; } // remove all references to the plug Q_ASSERT(m_plugs.contains(plug)); Q_ASSERT(m_plugs[plug].size() == 0); m_plugs.remove(plug); // remove the plug bool result = plug.remove(); Q_ASSERT(result); return result; }
bool PlugHandle::disconnectPlug(PlugHandle other) { #ifdef QT_DEBUG Q_ASSERT(m_isValid && other.isValid()); #else if(!m_isValid || !other.isValid()){ return false; } #endif PlugEdge* edge; Scene* scene = m_plug->getNode()->getScene(); if(m_plug->getDirection() == PlugDirection::OUT){ edge = scene->getEdge(m_plug, other.data()); } else { edge = scene->getEdge(other.data(), m_plug); } if(!edge){ return false; } scene->removeEdge(edge); return true; }
QString NodeCtrl::renamePlug(const QString & oldName, const QString & newName) { if (newName == oldName) { return oldName; } PlugHandle plug = m_node.getPlug(oldName); if (!plug.isValid()) { // return the empty string if there is no plug by the given name return ""; } // disconnect all connected plugs if (plug.isIncoming()) { for (PlugHandle otherPlug : m_plugs.value(plug)) { m_manager->getCtrlForHandle(otherPlug.getNode())-> outputDisconnected(otherPlug, plug); } } else { for (PlugHandle otherPlug : m_plugs.value(plug)) { m_manager->getCtrlForHandle(otherPlug.getNode())-> inputDisconnected(otherPlug, plug); } } // rename the plug QString actualName = plug.rename(newName); // reconnect other plugs if (plug.isIncoming()) { for (PlugHandle otherPlug : m_plugs.value(plug)) { m_manager->getCtrlForHandle(otherPlug.getNode())-> outputConnected(otherPlug, plug); } } else { for (PlugHandle otherPlug : m_plugs.value(plug)) { m_manager->getCtrlForHandle(otherPlug.getNode())-> inputConnected(otherPlug, plug); } } return actualName; }