Skip to content

Commit

Permalink
playlist/crate features: use unique_ptr for temp trackset models
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 3, 2024
1 parent 6950df4 commit d567642
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 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
16 changes: 8 additions & 8 deletions src/library/trackset/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@ void CrateFeature::slotImportPlaylistFile(const QString& playlistFile, CrateId c
} else {
// Create a temporary table model since the main one might have another
// crate selected which is not the crate that received the right-click.
QScopedPointer<CrateTableModel> pCrateTableModel(
new CrateTableModel(this, m_pLibrary->trackCollectionManager()));
std::unique_ptr<CrateTableModel> pCrateTableModel =
std::make_unique<CrateTableModel>(this, m_pLibrary->trackCollectionManager());
pCrateTableModel->selectCrate(crateId);
pCrateTableModel->select();
pCrateTableModel->addTracks(QModelIndex(), locations);
Expand Down Expand Up @@ -808,15 +808,15 @@ void CrateFeature::slotExportPlaylist() {

// Create list of files of the crate
// Create a new table model since the main one might have an active search.
QScopedPointer<CrateTableModel> pCrateTableModel(
new CrateTableModel(this, m_pLibrary->trackCollectionManager()));
std::unique_ptr<CrateTableModel> pCrateTableModel =
std::make_unique<CrateTableModel>(this, m_pLibrary->trackCollectionManager());
pCrateTableModel->selectCrate(crateId);
pCrateTableModel->select();

if (fileLocation.endsWith(".csv", Qt::CaseInsensitive)) {
ParserCsv::writeCSVFile(fileLocation, pCrateTableModel.data(), useRelativePath);
ParserCsv::writeCSVFile(fileLocation, pCrateTableModel.get(), useRelativePath);
} else if (fileLocation.endsWith(".txt", Qt::CaseInsensitive)) {
ParserCsv::writeReadableTextFile(fileLocation, pCrateTableModel.data(), false);
ParserCsv::writeReadableTextFile(fileLocation, pCrateTableModel.get(), false);
} else {
// populate a list of files of the crate
QList<QString> playlistItems;
Expand All @@ -834,8 +834,8 @@ void CrateFeature::slotExportPlaylist() {

void CrateFeature::slotExportTrackFiles() {
// Create a new table model since the main one might have an active search.
QScopedPointer<CrateTableModel> pCrateTableModel(
new CrateTableModel(this, m_pLibrary->trackCollectionManager()));
std::unique_ptr<CrateTableModel> pCrateTableModel =
std::make_unique<CrateTableModel>(this, m_pLibrary->trackCollectionManager());
pCrateTableModel->selectCrate(m_crateTableModel.selectedCrate());
pCrateTableModel->select();

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 d567642

Please sign in to comment.