Skip to content

Commit

Permalink
TEST: port mixxxdj#2996 'poelzi:history' to 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Sep 16, 2020
1 parent a0fd569 commit 8f0436f
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 73 deletions.
37 changes: 0 additions & 37 deletions src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,43 +599,6 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) {
}
}

/**
* Purpose: When inserting or removing playlists,
* we require the sidebar model not to reset.
* This method queries the database and does dynamic insertion
*/
QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) {
QList<TreeItem*> data_list;
int selected_row = -1;

int row = 0;
for (const IdAndLabel& idAndLabel : createPlaylistLabels()) {
int playlistId = idAndLabel.id;
QString playlistLabel = idAndLabel.label;

if (selected_id == playlistId) {
// save index for selection
selected_row = row;
}

// Create the TreeItem whose parent is the invisible root item
TreeItem* item = new TreeItem(playlistLabel, playlistId);
item->setBold(m_playlistsSelectedTrackIsIn.contains(playlistId));

decorateChild(item, playlistId);
data_list.append(item);

++row;
}

// Append all the newly created TreeItems in a dynamic way to the childmodel
m_childModel.insertTreeItemRows(data_list, 0);
if (selected_row == -1) {
return QModelIndex();
}
return m_childModel.index(selected_row, 0);
}

void BasePlaylistFeature::updateChildModel(int playlistId) {
QString playlistLabel = fetchPlaylistLabel(playlistId);

Expand Down
5 changes: 1 addition & 4 deletions src/library/baseplaylistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
QString label;
};

virtual QModelIndex constructChildModel(int selected_id);
virtual void updateChildModel(int selected_id);
virtual void clearChildModel();
virtual QList<IdAndLabel> createPlaylistLabels() = 0;
virtual QString fetchPlaylistLabel(int playlistId) = 0;
virtual void decorateChild(TreeItem* pChild, int playlistId) = 0;
virtual void addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc);
Expand Down Expand Up @@ -97,6 +95,7 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
QAction* m_pAnalyzePlaylistAction;

PlaylistTableModel* m_pPlaylistTableModel;
QSet<int> m_playlistsSelectedTrackIsIn;

private slots:
void slotTrackSelected(TrackPointer pTrack);
Expand All @@ -107,6 +106,4 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
virtual QString getRootViewHtml() const = 0;

TrackPointer m_pSelectedTrack;

QSet<int> m_playlistsSelectedTrackIsIn;
};
38 changes: 38 additions & 0 deletions src/library/playlistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,44 @@ QString PlaylistFeature::fetchPlaylistLabel(int playlistId) {
return QString();
}

/**
* Purpose: When inserting or removing playlists,
* we require the sidebar model not to reset.
* This method queries the database and does dynamic insertion
* @param selectedId entry which should be selected
*/
QModelIndex PlaylistFeature::constructChildModel(int selectedId) {
QList<TreeItem*> data_list;
int selectedRow = -1;

int row = 0;
for (const IdAndLabel& idAndLabel : createPlaylistLabels()) {
int playlistId = idAndLabel.id;
QString playlistLabel = idAndLabel.label;

if (selectedId == playlistId) {
// save index for selection
selectedRow = row;
}

// Create the TreeItem whose parent is the invisible root item
TreeItem* item = new TreeItem(playlistLabel, playlistId);
item->setBold(m_playlistsSelectedTrackIsIn.contains(playlistId));

decorateChild(item, playlistId);
data_list.append(item);

++row;
}

// Append all the newly created TreeItems in a dynamic way to the childmodel
m_childModel.insertTreeItemRows(data_list, 0);
if (selectedRow == -1) {
return QModelIndex();
}
return m_childModel.index(selectedRow, 0);
}

void PlaylistFeature::decorateChild(TreeItem* item, int playlistId) {
if (m_playlistDao.isPlaylistLocked(playlistId)) {
item->setIcon(QIcon(":/images/library/ic_library_locked_tracklist.svg"));
Expand Down
5 changes: 3 additions & 2 deletions src/library/playlistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class PlaylistFeature : public BasePlaylistFeature {
void slotPlaylistTableRenamed(int playlistId, QString newName) override;

protected:
QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels() override;
QString fetchPlaylistLabel(int playlistId) override;
void decorateChild(TreeItem* pChild, int playlist_id) override;
void decorateChild(TreeItem* pChild, int playlistId) override;
virtual QList<IdAndLabel> createPlaylistLabels();
QModelIndex constructChildModel(int selectedId);

private:
QString getRootViewHtml() const override;
Expand Down
144 changes: 117 additions & 27 deletions src/library/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "widget/wlibrarysidebar.h"
#include "widget/wtracktableview.h"

namespace {
constexpr int kNumDirectHistoryEntries = 5;
}

SetlogFeature::SetlogFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
Expand Down Expand Up @@ -101,8 +105,13 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index
//Save the model index so we can get it in the action slots...
m_lastRightClickedIndex = index;

QString playlistName = index.data().toString();
int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName);
// QString playlistName = index.data().toString();
// int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName);
int playlistId = index.data(TreeItemModel::kDataRole).toInt();
// not a real entry
if (playlistId == -1) {
return;
}

bool locked = m_playlistDao.isPlaylistLocked(playlistId);
m_pDeletePlaylistAction->setEnabled(!locked);
Expand Down Expand Up @@ -137,34 +146,95 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index
}

QList<BasePlaylistFeature::IdAndLabel> SetlogFeature::createPlaylistLabels() {
QList<BasePlaylistFeature::IdAndLabel> playlistLabels;
// QList<BasePlaylistFeature::IdAndLabel> playlistLabels;
return QList<BasePlaylistFeature::IdAndLabel>();
}

/**
* Purpose: When inserting or removing playlists,
* we require the sidebar model not to reset.
* This method queries the database and does dynamic insertion
* Use a custom model in the history for grouping by year
*/
QModelIndex SetlogFeature::constructChildModel(int selectedId) {
int selected_row = -1;

// Setup the sidebar playlist model
QSqlTableModel playlistTableModel(this, m_pLibrary->trackCollections()->internalCollection()->database());
playlistTableModel.setTable("Playlists");
playlistTableModel.setFilter("hidden=2"); // PLHT_SET_LOG
playlistTableModel.setSort(playlistTableModel.fieldIndex("id"),
Qt::AscendingOrder);
playlistTableModel.setSort(
playlistTableModel.fieldIndex("id"),
Qt::DescendingOrder);
playlistTableModel.select();
while (playlistTableModel.canFetchMore()) {
playlistTableModel.fetchMore();
}
QSqlRecord record = playlistTableModel.record();
int nameColumn = record.indexOf("name");
int idColumn = record.indexOf("id");
int createdColumn = record.indexOf("date_created");

auto groups = QMap<int, TreeItem*>();

QList<TreeItem*> data_list;
data_list.reserve(playlistTableModel.rowCount());

for (int row = 0; row < playlistTableModel.rowCount(); ++row) {
int id = playlistTableModel.data(
playlistTableModel.index(row, idColumn))
.toInt();
QString name = playlistTableModel.data(
playlistTableModel.index(row, nameColumn))
QString name = playlistTableModel
.data(playlistTableModel.index(row, nameColumn))
.toString();
BasePlaylistFeature::IdAndLabel idAndLabel;
idAndLabel.id = id;
idAndLabel.label = name;
playlistLabels.append(idAndLabel);

QDateTime created =
playlistTableModel
.data(playlistTableModel.index(row, createdColumn))
.toDateTime();

if (selectedId == id) {
// save index for selection
selected_row = row;
}

// Create the TreeItem whose parent is the invisible root item
if (row >= kNumDirectHistoryEntries) {
int year = created.date().year();

QMap<int, TreeItem*>::const_iterator i = groups.find(year);
TreeItem* groupItem;
if (i != groups.end() && i.key() == year) {
groupItem = i.value();
} else {
groupItem = new TreeItem(QString("%1").arg(year), -1);
groups.insert(year, groupItem);
data_list.append(groupItem);
}

std::unique_ptr<TreeItem> item(new TreeItem(name, id));
item->setBold(m_playlistsSelectedTrackIsIn.contains(id));

decorateChild(item.get(), id);

groupItem->appendChild(std::move(item));
} else {
TreeItem* item = new TreeItem(name, id);
item->setBold(m_playlistsSelectedTrackIsIn.contains(id));

decorateChild(item, id);

data_list.append(item);
}
}

// Append all the newly created TreeItems in a dynamic way to the childmodel
m_childModel.insertTreeItemRows(data_list, 0);
if (selected_row == -1) {
return QModelIndex();
}
return playlistLabels;
// return playlistLabels;
return m_childModel.index(selected_row, 0);
}

QString SetlogFeature::fetchPlaylistLabel(int playlistId) {
Expand Down Expand Up @@ -384,20 +454,40 @@ void SetlogFeature::slotPlaylistTableRenamed(
}
}

void SetlogFeature::activate() {
activatePlaylist(m_playlistId);
}

void SetlogFeature::activatePlaylist(int playlistId) {
//qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId;
QModelIndex index = indexFromPlaylistId(playlistId);
if (playlistId != -1 && index.isValid()) {
m_pPlaylistTableModel->setTableModel(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
// Update selection only, if it is not the current playlist
if (playlistId != m_playlistId) {
emit featureSelect(this, m_lastRightClickedIndex);
activateChild(m_lastRightClickedIndex);
}
}
}

QString SetlogFeature::getRootViewHtml() const {
QString playlistsTitle = tr("History");
QString playlistsSummary = tr("The history section automatically keeps a list of tracks you play in your DJ sets.");
QString playlistsSummary2 = tr("This is handy for remembering what worked in your DJ sets, posting set-lists, or reporting your plays to licensing organizations.");
QString playlistsSummary3 = tr("Every time you start Mixxx, a new history section is created. You can export it as a playlist in various formats or play it again with Auto DJ.");
QString playlistsSummary4 = tr("You can join the current history session with a previous one by right-clicking and selecting \"Join with previous\".");

QString html;
html.append(QString("<h2>%1</h2>").arg(playlistsTitle));
html.append("<table border=\"0\" cellpadding=\"5\"><tr><td>");
html.append(QString("<p>%1</p>").arg(playlistsSummary));
html.append(QString("<p>%1</p>").arg(playlistsSummary2));
html.append(QString("<p>%1</p>").arg(playlistsSummary3));
html.append(QString("<p>%1</p>").arg(playlistsSummary4));
html.append("</td></tr></table>");
return html;
// QString playlistsTitle = tr("History");
// QString playlistsSummary = tr("The history section automatically keeps a list of tracks you play in your DJ sets.");
// QString playlistsSummary2 = tr("This is handy for remembering what worked in your DJ sets, posting set-lists, or reporting your plays to licensing organizations.");
// QString playlistsSummary3 = tr("Every time you start Mixxx, a new history section is created. You can export it as a playlist in various formats or play it again with Auto DJ.");
// QString playlistsSummary4 = tr("You can join the current history session with a previous one by right-clicking and selecting \"Join with previous\".");
//
// QString html;
// html.append(QString("<h2>%1</h2>").arg(playlistsTitle));
// html.append("<table border=\"0\" cellpadding=\"5\"><tr><td>");
// html.append(QString("<p>%1</p>").arg(playlistsSummary));
// html.append(QString("<p>%1</p>").arg(playlistsSummary2));
// html.append(QString("<p>%1</p>").arg(playlistsSummary3));
// html.append(QString("<p>%1</p>").arg(playlistsSummary4));
// html.append("</td></tr></table>");
// return html;
return QString();
}
6 changes: 5 additions & 1 deletion src/library/setlogfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ class SetlogFeature : public BasePlaylistFeature {
void bindLibraryWidget(WLibrary* libraryWidget,
KeyboardEventFilter* keyboard) override;
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget) override;
void activatePlaylist(int playlistId) override;

public slots:
void onRightClick(const QPoint& globalPos) override;
void onRightClickChild(const QPoint& globalPos, QModelIndex index) override;
void slotJoinWithPrevious();
void slotGetNewPlaylist();
void activate() override;

protected:
QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels() override;
// QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels() override;
QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels();
QString fetchPlaylistLabel(int playlistId) override;
QModelIndex constructChildModel(int selectedId);
void decorateChild(TreeItem* pChild, int playlistId) override;

private slots:
Expand Down
3 changes: 1 addition & 2 deletions src/library/treeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TreeItem final {
// take ownership of children items
void insertChildren(int row, QList<TreeItem*>& children);
void removeChildren(int row, int count);

void insertChild(int row, TreeItem* pChild);

/////////////////////////////////////////////////////////////////////////
// Payload
Expand Down Expand Up @@ -135,7 +135,6 @@ class TreeItem final {
QString label = QString(),
QVariant data = QVariant());

void insertChild(int row, TreeItem* pChild);
void initFeatureRecursively(LibraryFeature* pFeature);

// The library feature is inherited from the parent.
Expand Down

0 comments on commit 8f0436f

Please sign in to comment.