| 50 | } |
| 51 | |
| 52 | void |
| 53 | Node::initNodeScriptName(const NodeSerialization* serialization, const QString& fixedName) |
| 54 | { |
| 55 | /* |
| 56 | If the serialization is not null, we are either pasting a node or loading it from a project. |
| 57 | */ |
| 58 | NodeCollectionPtr group = getGroup(); |
| 59 | bool isMultiInstanceChild = false; |
| 60 | if ( !_imp->multiInstanceParentName.empty() ) { |
| 61 | isMultiInstanceChild = true; |
| 62 | } |
| 63 | |
| 64 | if (!fixedName.isEmpty()) { |
| 65 | |
| 66 | std::string name = fixedName.toStdString(); |
| 67 | // If the script name is available, use it as is (else we get issue #755). |
| 68 | // Else look for a similar name by adding a (different) number suffix. |
| 69 | if ( group && group->checkIfNodeNameExists(name, this) ) { |
| 70 | std::string baseName = name; |
| 71 | trimNumber(baseName); |
| 72 | int no = 1; |
| 73 | do { |
| 74 | name = baseName; |
| 75 | if (no > 1) { |
| 76 | name += '_'; |
| 77 | std::stringstream ss; |
| 78 | ss << no; |
| 79 | name += ss.str(); |
| 80 | } |
| 81 | ++no; |
| 82 | } while ( group && group->checkIfNodeNameExists(name, this) ); |
| 83 | } |
| 84 | //This version of setScriptName will not error if the name is invalid or already taken |
| 85 | setScriptName_no_error_check(name); |
| 86 | |
| 87 | } else if (serialization) { |
| 88 | if ( group && !group->isCacheIDAlreadyTaken( serialization->getCacheID() ) ) { |
| 89 | QMutexLocker k(&_imp->nameMutex); |
| 90 | _imp->cacheID = serialization->getCacheID(); |
| 91 | } |
| 92 | std::string name = serialization->getNodeScriptName(); |
| 93 | // If the serialized script name is available, use it as is (else we get issue #755). |
| 94 | // Else look for a similar name by adding a (different) number suffix. |
| 95 | if ( group && group->checkIfNodeNameExists(name, this) ) { |
| 96 | std::string baseName = name; |
| 97 | trimNumber(baseName); |
| 98 | int no = 1; |
| 99 | do { |
| 100 | name = baseName; |
| 101 | if (no > 1) { |
| 102 | name += '_'; |
| 103 | std::stringstream ss; |
| 104 | ss << no; |
| 105 | name += ss.str(); |
| 106 | } |
| 107 | ++no; |
| 108 | } while ( group->checkIfNodeNameExists(name, this) ); |
| 109 | } |
no test coverage detected