Skip to content

Commit

Permalink
PlaylistStatsDAO: Add TrackCollection::getPlaylistStatsDAO()
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed Apr 26, 2024
1 parent fe1d9ef commit e1c91cb
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src/library/dao/playliststatsdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#include "util/math.h"

PlaylistStatsDAO::PlaylistStatsDAO(const QString& countsDurationTableName,
const PlaylistDAO::HiddenType hiddenType)
const PlaylistDAO::HiddenType playlistType)
: m_countsDurationTableName(countsDurationTableName),
m_hiddenType(hiddenType) {
m_hiddenType(playlistType) {
}

void PlaylistStatsDAO::initialize(const QSqlDatabase& database) {
DAO::initialize(database);
preparePlaylistSummaryTable();
}

void PlaylistStatsDAO::preparePlaylistSummaryTable() {
Expand Down
2 changes: 1 addition & 1 deletion src/library/dao/playliststatsdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PlaylistStatsDAO : public QObject, public virtual DAO {
Q_OBJECT
public:
PlaylistStatsDAO(const QString& countsDurationTableName,
const PlaylistDAO::HiddenType hiddenType);
const PlaylistDAO::HiddenType playlistType);
~PlaylistStatsDAO() override = default;

void initialize(const QSqlDatabase& database) override;
Expand Down
16 changes: 12 additions & 4 deletions src/library/trackcollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ mixxx::Logger kLogger("TrackCollection");
} // anonymous namespace

TrackCollection::TrackCollection(
QObject* parent,
const UserSettingsPointer& pConfig)
QObject* parent, const UserSettingsPointer& pConfig)
: QObject(parent),
m_playlistStatsDao(QStringLiteral("PlaylistsCountsDurations"),
PlaylistDAO::PLHT_NOT_HIDDEN),
m_setlogStatsDao(QStringLiteral("SetlogCountsDurations"),
PlaylistDAO::PLHT_SET_LOG),
m_analysisDao(pConfig),
m_trackDao(m_cueDao, m_playlistDao,
m_analysisDao, m_libraryHashDao, pConfig) {
m_trackDao(m_cueDao,
m_playlistDao,
m_analysisDao,
m_libraryHashDao,
pConfig) {
// Forward signals from TrackDAO
connect(&m_trackDao,
&TrackDAO::trackClean,
Expand Down Expand Up @@ -78,6 +84,8 @@ void TrackCollection::connectDatabase(const QSqlDatabase& database) {
m_database = database;
m_trackDao.initialize(database);
m_playlistDao.initialize(database);
m_playlistStatsDao.initialize(database);
m_setlogStatsDao.initialize(database);
m_cueDao.initialize(database);
m_directoryDao.initialize(database);
m_analysisDao.initialize(database);
Expand Down
21 changes: 21 additions & 0 deletions src/library/trackcollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "library/dao/directorydao.h"
#include "library/dao/libraryhashdao.h"
#include "library/dao/playlistdao.h"
#include "library/dao/playliststatsdao.h"
#include "library/dao/trackdao.h"
#include "library/trackset/crate/cratestorage.h"
#include "preferences/usersettings.h"
Expand Down Expand Up @@ -60,6 +61,24 @@ class TrackCollection : public QObject,
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
return m_playlistDao;
}
PlaylistStatsDAO& getPlaylistStatsDAO(PlaylistDAO::HiddenType playlistType) {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
switch (playlistType) {
case PlaylistDAO::PLHT_NOT_HIDDEN: {
return m_playlistStatsDao;
}
case PlaylistDAO::PLHT_SET_LOG: {
return m_setlogStatsDao;
}
case PlaylistDAO::PLHT_AUTO_DJ:
case PlaylistDAO::PLHT_UNKNOWN:
default: {
// This can only ever happen due to a coding error
DEBUG_ASSERT(false);
return m_playlistStatsDao;
}
}
}
const DirectoryDAO& getDirectoryDAO() const {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
return m_directoryDao;
Expand Down Expand Up @@ -169,6 +188,8 @@ class TrackCollection : public QObject,
QSqlDatabase m_database;

PlaylistDAO m_playlistDao;
PlaylistStatsDAO m_playlistStatsDao;
PlaylistStatsDAO m_setlogStatsDao;
CrateStorage m_crates;
CueDAO m_cueDao;
DirectoryDAO m_directoryDao;
Expand Down
14 changes: 4 additions & 10 deletions src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ BasePlaylistFeature::BasePlaylistFeature(
PlaylistTableModel* pModel,
const QString& rootViewName,
const QString& iconName,
const QString& countsDurationTableName,
bool keepHiddenTracks)
: BaseTrackSetFeature(pLibrary, pConfig, rootViewName, iconName),
m_playlistDao(pLibrary->trackCollectionManager()
->internalCollection()
->getPlaylistDAO()),
m_pPlaylistTableModel(pModel),
m_countsDurationTableName(countsDurationTableName),
m_keepHiddenTracks(keepHiddenTracks) {
pModel->setParent(this);

Expand Down Expand Up @@ -715,14 +713,10 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) {
QString BasePlaylistFeature::fetchPlaylistLabel(int playlistId) {
// This queries the temporary id/count/duration table that was has been created
// by the features' createPlaylistLabels() (updated each time playlists are added/removed)
QSqlDatabase database =
m_pLibrary->trackCollectionManager()->internalCollection()->database();

PlaylistStatsDAO playlistStatsDao(
m_countsDurationTableName,
PlaylistDAO::PLHT_NOT_HIDDEN);

playlistStatsDao.initialize(database);
PlaylistStatsDAO& playlistStatsDao =
m_pLibrary->trackCollectionManager()
->internalCollection()
->getPlaylistStatsDAO(PlaylistDAO::PLHT_NOT_HIDDEN);

auto playlistInfo = playlistStatsDao.getPlaylistSummary(playlistId);
if (!playlistInfo.isEmpty()) {
Expand Down
2 changes: 0 additions & 2 deletions src/library/trackset/baseplaylistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
PlaylistTableModel* pModel,
const QString& rootViewName,
const QString& iconName,
const QString& countsDurationTableName,
bool keepHiddenTracks = false);
~BasePlaylistFeature() override = default;

Expand Down Expand Up @@ -117,7 +116,6 @@ class BasePlaylistFeature : public BaseTrackSetFeature {

PlaylistTableModel* m_pPlaylistTableModel;
QSet<int> m_playlistIdsOfSelectedTrack;
const QString m_countsDurationTableName;

private slots:
void slotTrackSelected(TrackId trackId);
Expand Down
18 changes: 6 additions & 12 deletions src/library/trackset/playlistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ PlaylistFeature::PlaylistFeature(Library* pLibrary, UserSettingsPointer pConfig)
pLibrary->trackCollectionManager(),
"mixxx.db.model.playlist"),
QStringLiteral("PLAYLISTHOME"),
QStringLiteral("playlist"),
QStringLiteral("PlaylistsCountsDurations")) {
QStringLiteral("playlist")) {
// construct child model
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
m_pSidebarModel->setRootItem(std::move(pRootItem));
Expand Down Expand Up @@ -120,17 +119,12 @@ bool PlaylistFeature::dragMoveAcceptChild(const QModelIndex& index, const QUrl&
}

QList<BasePlaylistFeature::IdAndLabel> PlaylistFeature::createPlaylistLabels() {
QSqlDatabase database =
m_pLibrary->trackCollectionManager()->internalCollection()->database();

PlaylistStatsDAO playlistStatsDao(
m_countsDurationTableName,
PlaylistDAO::PLHT_NOT_HIDDEN);

playlistStatsDao.initialize(database);
playlistStatsDao.preparePlaylistSummaryTable();

// Setup the sidebar playlist model
PlaylistStatsDAO& playlistStatsDao =
m_pLibrary->trackCollectionManager()
->internalCollection()
->getPlaylistStatsDAO(PlaylistDAO::PLHT_NOT_HIDDEN);

QList<BasePlaylistFeature::IdAndLabel> playlistLabels;
for (auto playlistInfo : playlistStatsDao.getPlaylistSummaries()) {
BasePlaylistFeature::IdAndLabel idAndLabel;
Expand Down
14 changes: 4 additions & 10 deletions src/library/trackset/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ SetlogFeature::SetlogFeature(
/*keep hidden tracks*/ true),
QStringLiteral("SETLOGHOME"),
QStringLiteral("history"),
QStringLiteral("SetlogCountsDurations"),
/*keep hidden tracks*/ true),
m_currentPlaylistId(kInvalidPlaylistId),
m_yearNodeId(kInvalidPlaylistId),
Expand Down Expand Up @@ -231,15 +230,10 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, const QModelIndex
QModelIndex SetlogFeature::constructChildModel(int selectedId) {
// qDebug() << "SetlogFeature::constructChildModel() selected:" << selectedId;
// Setup the sidebar playlist model
QSqlDatabase database =
m_pLibrary->trackCollectionManager()->internalCollection()->database();

PlaylistStatsDAO playlistStatsDao(
m_countsDurationTableName,
PlaylistDAO::PLHT_SET_LOG);

playlistStatsDao.initialize(database);
playlistStatsDao.preparePlaylistSummaryTable();
PlaylistStatsDAO& playlistStatsDao =
m_pLibrary->trackCollectionManager()
->internalCollection()
->getPlaylistStatsDAO(PlaylistDAO::PLHT_SET_LOG);

// Nice to have: restore previous expanded/collapsed state of YEAR items
clearChildModel();
Expand Down

0 comments on commit e1c91cb

Please sign in to comment.