Skip to content

Commit

Permalink
playlist features: use unique_ptr for temp PlaylistModels
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 3, 2024
1 parent 6950df4 commit 89e2f09
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
24 changes: 12 additions & 12 deletions src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ void BasePlaylistFeature::slotImportPlaylistFile(const QString& playlistFile,
// This is used as a proxy object to write to the database.
// We cannot use m_pPlaylistTableModel since it might have another playlist selected which
// is not the playlist that received the right-click.
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
std::unique_ptr<PlaylistTableModel> pPlaylistTableModel =
std::make_unique<PlaylistTableModel>(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_export"));
"mixxx.db.model.playlist_export");
pPlaylistTableModel->selectPlaylist(playlistId);
pPlaylistTableModel->setSort(
pPlaylistTableModel->fieldIndex(
Expand Down Expand Up @@ -565,10 +565,10 @@ void BasePlaylistFeature::slotExportPlaylist() {

// Create a new table model since the main one might have an active search.
// This will only export songs that we think exist on default
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
std::unique_ptr<PlaylistTableModel> pPlaylistTableModel =
std::make_unique<PlaylistTableModel>(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_export"));
"mixxx.db.model.playlist_export");

emit saveModelState();
pPlaylistTableModel->selectPlaylist(playlistId);
Expand All @@ -583,13 +583,13 @@ void BasePlaylistFeature::slotExportPlaylist() {
kUseRelativePathOnExportConfigKey);

if (fileLocation.endsWith(".csv", Qt::CaseInsensitive)) {
ParserCsv::writeCSVFile(fileLocation, pPlaylistTableModel.data(), useRelativePath);
ParserCsv::writeCSVFile(fileLocation, pPlaylistTableModel.get(), useRelativePath);
} else if (fileLocation.endsWith(".txt", Qt::CaseInsensitive)) {
if (m_playlistDao.getHiddenType(pPlaylistTableModel->getPlaylist()) ==
PlaylistDAO::PLHT_SET_LOG) {
ParserCsv::writeReadableTextFile(fileLocation, pPlaylistTableModel.data(), true);
ParserCsv::writeReadableTextFile(fileLocation, pPlaylistTableModel.get(), true);
} else {
ParserCsv::writeReadableTextFile(fileLocation, pPlaylistTableModel.data(), false);
ParserCsv::writeReadableTextFile(fileLocation, pPlaylistTableModel.get(), false);
}
} else {
// Create and populate a list of files of the playlist
Expand All @@ -611,10 +611,10 @@ void BasePlaylistFeature::slotExportTrackFiles() {
if (playlistId == kInvalidPlaylistId) {
return;
}
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
std::unique_ptr<PlaylistTableModel> pPlaylistTableModel =
std::make_unique<PlaylistTableModel>(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_export"));
"mixxx.db.model.playlist_export");

emit saveModelState();
pPlaylistTableModel->selectPlaylist(playlistId);
Expand Down
6 changes: 3 additions & 3 deletions src/library/trackset/playlistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ void PlaylistFeature::slotShufflePlaylist() {
} else {
// Create a temp model so we don't need to select the playlist
// in the persistent model in order to shuffle it
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
std::unique_ptr<PlaylistTableModel> pPlaylistTableModel =
std::make_unique<PlaylistTableModel>(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_shuffle"));
"mixxx.db.model.playlist_shuffle");
pPlaylistTableModel->selectPlaylist(playlistId);
pPlaylistTableModel->setSort(
pPlaylistTableModel->fieldIndex(
Expand Down
12 changes: 6 additions & 6 deletions src/library/trackset/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ void SetlogFeature::slotJoinWithPrevious() {

// Right-clicked playlist may not be loaded. Use a temporary model to
// keep sidebar selection and table view in sync
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
std::unique_ptr<PlaylistTableModel> pPlaylistTableModel =
std::make_unique<PlaylistTableModel>(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_export"));
"mixxx.db.model.playlist_export");
pPlaylistTableModel->selectPlaylist(previousPlaylistId);

if (clickedPlaylistId == m_currentPlaylistId) {
Expand Down Expand Up @@ -438,10 +438,10 @@ void SetlogFeature::slotMarkAllTracksPlayed() {

// Right-clicked playlist may not be loaded. Use a temporary model to
// keep sidebar selection and table view in sync
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this,
std::unique_ptr<PlaylistTableModel> pPlaylistTableModel =
std::make_unique<PlaylistTableModel>(this,
m_pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist_export"));
"mixxx.db.model.playlist_export");
pPlaylistTableModel->selectPlaylist(clickedPlaylistId);
// mark all the Tracks in the previous Playlist as played
pPlaylistTableModel->select();
Expand Down

0 comments on commit 89e2f09

Please sign in to comment.