From e9086005d4b2eeece96866fdfd173f43b2aea4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 8 Jan 2020 09:35:14 +0100 Subject: [PATCH] #5310 Fix wrong use of new path id. Used last used instead of first unused --- ApplicationCode/ProjectDataModel/RimProject.cpp | 12 +++++++----- ApplicationCode/ProjectDataModel/RimProject.h | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index c7e67325d4..15c8033eed 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -1399,7 +1399,7 @@ class GlobalPathListMapper public: GlobalPathListMapper( const QString& globalPathListTable ) { - m_nextValidIdNumber = 1; + m_maxUsedIdNumber = 0; QStringList pathPairs = globalPathListTable.split( ";", QString::SkipEmptyParts ); for ( const QString& pathIdPathPair : pathPairs ) @@ -1422,7 +1422,7 @@ public: if ( isOk ) { - m_nextValidIdNumber = std::max( m_nextValidIdNumber, idNumber ); + m_maxUsedIdNumber = std::max( m_maxUsedIdNumber, idNumber ); } } @@ -1516,13 +1516,15 @@ public: private: QString createUnusedId() { - QString numberString = QString( "%1" ).arg( (uint)m_nextValidIdNumber, 3, 10, QChar( '0' ) ); + m_maxUsedIdNumber++; + + QString numberString = QString( "%1" ).arg( (uint)m_maxUsedIdNumber, 3, 10, QChar( '0' ) ); QString pathIdentifier = PATHIDCHAR + pathIdBaseString + numberString + PATHIDCHAR; - m_nextValidIdNumber++; + return pathIdentifier; } - size_t m_nextValidIdNumber; // Set when parsing the globalPathListTable. Increment while creating new id's + size_t m_maxUsedIdNumber; // Set when parsing the globalPathListTable. Increment while creating new id's std::map m_newPathIdToPathMap; std::map m_newPathToPathIdMap; diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index 808fdc40f2..4bfd84414f 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -193,7 +193,7 @@ protected: private: template - void fieldContentsByType( caf::PdmObjectHandle* object, std::vector& typedFields ); + void fieldContentsByType( caf::PdmObjectHandle* object, std::vector& fieldContents ); void transferPathsToGlobalPathList(); void distributePathsFromGlobalPathList(); @@ -225,7 +225,7 @@ private: /// //-------------------------------------------------------------------------------------------------- template -void RimProject::fieldContentsByType( caf::PdmObjectHandle* object, std::vector& typedFields ) +void RimProject::fieldContentsByType( caf::PdmObjectHandle* object, std::vector& fieldContents ) { if ( !object ) return; @@ -237,14 +237,14 @@ void RimProject::fieldContentsByType( caf::PdmObjectHandle* object, std::vector< for ( const auto& field : allFieldsInObject ) { caf::PdmField* typedField = dynamic_cast*>( field ); - if ( typedField ) typedFields.push_back( &typedField->v() ); + if ( typedField ) fieldContents.push_back( &typedField->v() ); caf::PdmField>* typedFieldInVector = dynamic_cast>*>( field ); if ( typedFieldInVector ) { for ( T& typedFieldFromVector : typedFieldInVector->v() ) { - typedFields.push_back( &typedFieldFromVector ); + fieldContents.push_back( &typedFieldFromVector ); } } @@ -253,6 +253,6 @@ void RimProject::fieldContentsByType( caf::PdmObjectHandle* object, std::vector< for ( const auto& child : children ) { - fieldContentsByType( child, typedFields ); + fieldContentsByType( child, fieldContents ); } }