@@ -720,7 +720,7 @@ void PlaylistDoc::Reader::parsePlaylistGame()
720720 existingPlaylistGame->setLBDatabaseId (optIdx.value_or (0 ));
721721 }
722722 else
723- static_cast <PlaylistDoc*>(mTargetDocument )->mLaunchBoxDatabaseIdTracker ->release (existingPlaylistGame->lbDatabaseId ());
723+ static_cast <PlaylistDoc*>(mTargetDocument )->mLaunchBoxDatabaseIdTracker ->reserve (existingPlaylistGame->lbDatabaseId ());
724724
725725 // Add to document
726726 targetDocExistingPlaylistGames ()[existingPlaylistGame->gameId ()] = existingPlaylistGame;
@@ -1090,36 +1090,64 @@ ParentsDoc::ParentsDoc(Install* const parent, const QString& xmlPath, const DocK
10901090// Private:
10911091Fe::DataDoc::Type ParentsDoc::type () const { return Fe::DataDoc::Type::Config; }
10921092
1093- // Public:
1094- bool ParentsDoc::isEmpty () const { return mParents .isEmpty (); }
1095-
1096- bool ParentsDoc::containsPlatformCategory (QStringView platformCategory)
1093+ bool ParentsDoc::removeIfPresent (qsizetype idx)
10971094{
1098- for (const Parent& p : mParents )
1099- if (p.platformCategoryName () == platformCategory)
1100- return true ;
1095+ if (idx != -1 )
1096+ {
1097+ mParents .remove (idx);
1098+ return true ;
1099+ }
11011100
11021101 return false ;
11031102}
11041103
1105- bool ParentsDoc::containsPlatformUnderCategory (QStringView platform , QStringView platformCategory)
1104+ qsizetype ParentsDoc::findPlatformCategory (QStringView platformCategory , QStringView parentCategory) const
11061105{
1107- for (const Parent& p : mParents )
1108- if (p.parentPlatformCategoryName () == platformCategory && p.platformName () == platform)
1109- return true ;
1106+ for (auto i = 0 ; i < mParents .size (); i++)
1107+ {
1108+ auto p = mParents .at (i);
1109+ if (p.platformCategoryName () == platformCategory && p.parentPlatformCategoryName () == parentCategory)
1110+ return i;
1111+ }
11101112
1111- return false ;
1113+ return - 1 ;
11121114}
11131115
1114- bool ParentsDoc::containsPlaylistUnderCategory ( const QUuid& playlistId , QStringView platformCategory)
1116+ qsizetype ParentsDoc::findPlatform (QStringView platform , QStringView parentCategory) const
11151117{
1116- for (const Parent& p : mParents )
1117- if (p.parentPlatformCategoryName () == platformCategory && p.playlistId () == playlistId)
1118- return true ;
1118+ for (auto i = 0 ; i < mParents .size (); i++)
1119+ {
1120+ auto p = mParents .at (i);
1121+ if (p.platformName () == platform && p.parentPlatformCategoryName () == parentCategory)
1122+ return i;
1123+ }
11191124
1120- return false ;
1125+ return - 1 ;
11211126}
11221127
1128+ qsizetype ParentsDoc::findPlaylist (const QUuid& playlistId, QStringView parentCategory) const
1129+ {
1130+ for (auto i = 0 ; i < mParents .size (); i++)
1131+ {
1132+ auto p = mParents .at (i);
1133+ if (p.playlistId () == playlistId && p.parentPlatformCategoryName () == parentCategory)
1134+ return i;
1135+ }
1136+
1137+ return -1 ;
1138+ }
1139+
1140+ // Public:
1141+ bool ParentsDoc::isEmpty () const { return mParents .isEmpty (); }
1142+
1143+ bool ParentsDoc::containsPlatformCategory (QStringView platformCategory, QStringView parentCategory) const { return findPlatformCategory (platformCategory, parentCategory) != -1 ; }
1144+ bool ParentsDoc::containsPlatform (QStringView platform, QStringView parentCategory) const { return findPlatform (platform, parentCategory) != -1 ; }
1145+ bool ParentsDoc::containsPlaylist (const QUuid& playlistId, QStringView parentCategory) const { return findPlaylist (playlistId, parentCategory) != -1 ; }
1146+
1147+ bool ParentsDoc::removePlatformCategory (QStringView platformCategory, QStringView parentCategory) { return removeIfPresent (findPlatformCategory (platformCategory, parentCategory)); }
1148+ bool ParentsDoc::removePlatform (QStringView platform, QStringView parentCategory) { return removeIfPresent (findPlatform (platform, parentCategory)); }
1149+ bool ParentsDoc::removePlaylist (const QUuid& playlistId, QStringView parentCategory) { return removeIfPresent (findPlaylist (playlistId, parentCategory)); }
1150+
11231151const QList<Parent>& ParentsDoc::parents () const { return mParents ; }
11241152
11251153void ParentsDoc::addParent (const Parent& parent) { mParents .append (parent); }
0 commit comments