Skip to content

Commit 8f0436f

Browse files
committed
TEST: port mixxxdj#2996 'poelzi:history' to 2.3
1 parent a0fd569 commit 8f0436f

File tree

7 files changed

+165
-73
lines changed

7 files changed

+165
-73
lines changed

src/library/baseplaylistfeature.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -599,43 +599,6 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) {
599599
}
600600
}
601601

602-
/**
603-
* Purpose: When inserting or removing playlists,
604-
* we require the sidebar model not to reset.
605-
* This method queries the database and does dynamic insertion
606-
*/
607-
QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) {
608-
QList<TreeItem*> data_list;
609-
int selected_row = -1;
610-
611-
int row = 0;
612-
for (const IdAndLabel& idAndLabel : createPlaylistLabels()) {
613-
int playlistId = idAndLabel.id;
614-
QString playlistLabel = idAndLabel.label;
615-
616-
if (selected_id == playlistId) {
617-
// save index for selection
618-
selected_row = row;
619-
}
620-
621-
// Create the TreeItem whose parent is the invisible root item
622-
TreeItem* item = new TreeItem(playlistLabel, playlistId);
623-
item->setBold(m_playlistsSelectedTrackIsIn.contains(playlistId));
624-
625-
decorateChild(item, playlistId);
626-
data_list.append(item);
627-
628-
++row;
629-
}
630-
631-
// Append all the newly created TreeItems in a dynamic way to the childmodel
632-
m_childModel.insertTreeItemRows(data_list, 0);
633-
if (selected_row == -1) {
634-
return QModelIndex();
635-
}
636-
return m_childModel.index(selected_row, 0);
637-
}
638-
639602
void BasePlaylistFeature::updateChildModel(int playlistId) {
640603
QString playlistLabel = fetchPlaylistLabel(playlistId);
641604

src/library/baseplaylistfeature.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
6565
QString label;
6666
};
6767

68-
virtual QModelIndex constructChildModel(int selected_id);
6968
virtual void updateChildModel(int selected_id);
7069
virtual void clearChildModel();
71-
virtual QList<IdAndLabel> createPlaylistLabels() = 0;
7270
virtual QString fetchPlaylistLabel(int playlistId) = 0;
7371
virtual void decorateChild(TreeItem* pChild, int playlistId) = 0;
7472
virtual void addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc);
@@ -97,6 +95,7 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
9795
QAction* m_pAnalyzePlaylistAction;
9896

9997
PlaylistTableModel* m_pPlaylistTableModel;
98+
QSet<int> m_playlistsSelectedTrackIsIn;
10099

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

109108
TrackPointer m_pSelectedTrack;
110-
111-
QSet<int> m_playlistsSelectedTrackIsIn;
112109
};

src/library/playlistfeature.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,44 @@ QString PlaylistFeature::fetchPlaylistLabel(int playlistId) {
224224
return QString();
225225
}
226226

227+
/**
228+
* Purpose: When inserting or removing playlists,
229+
* we require the sidebar model not to reset.
230+
* This method queries the database and does dynamic insertion
231+
* @param selectedId entry which should be selected
232+
*/
233+
QModelIndex PlaylistFeature::constructChildModel(int selectedId) {
234+
QList<TreeItem*> data_list;
235+
int selectedRow = -1;
236+
237+
int row = 0;
238+
for (const IdAndLabel& idAndLabel : createPlaylistLabels()) {
239+
int playlistId = idAndLabel.id;
240+
QString playlistLabel = idAndLabel.label;
241+
242+
if (selectedId == playlistId) {
243+
// save index for selection
244+
selectedRow = row;
245+
}
246+
247+
// Create the TreeItem whose parent is the invisible root item
248+
TreeItem* item = new TreeItem(playlistLabel, playlistId);
249+
item->setBold(m_playlistsSelectedTrackIsIn.contains(playlistId));
250+
251+
decorateChild(item, playlistId);
252+
data_list.append(item);
253+
254+
++row;
255+
}
256+
257+
// Append all the newly created TreeItems in a dynamic way to the childmodel
258+
m_childModel.insertTreeItemRows(data_list, 0);
259+
if (selectedRow == -1) {
260+
return QModelIndex();
261+
}
262+
return m_childModel.index(selectedRow, 0);
263+
}
264+
227265
void PlaylistFeature::decorateChild(TreeItem* item, int playlistId) {
228266
if (m_playlistDao.isPlaylistLocked(playlistId)) {
229267
item->setIcon(QIcon(":/images/library/ic_library_locked_tracklist.svg"));

src/library/playlistfeature.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ class PlaylistFeature : public BasePlaylistFeature {
4141
void slotPlaylistTableRenamed(int playlistId, QString newName) override;
4242

4343
protected:
44-
QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels() override;
4544
QString fetchPlaylistLabel(int playlistId) override;
46-
void decorateChild(TreeItem* pChild, int playlist_id) override;
45+
void decorateChild(TreeItem* pChild, int playlistId) override;
46+
virtual QList<IdAndLabel> createPlaylistLabels();
47+
QModelIndex constructChildModel(int selectedId);
4748

4849
private:
4950
QString getRootViewHtml() const override;

src/library/setlogfeature.cpp

Lines changed: 117 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "widget/wlibrarysidebar.h"
1818
#include "widget/wtracktableview.h"
1919

20+
namespace {
21+
constexpr int kNumDirectHistoryEntries = 5;
22+
}
23+
2024
SetlogFeature::SetlogFeature(
2125
Library* pLibrary,
2226
UserSettingsPointer pConfig)
@@ -101,8 +105,13 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index
101105
//Save the model index so we can get it in the action slots...
102106
m_lastRightClickedIndex = index;
103107

104-
QString playlistName = index.data().toString();
105-
int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName);
108+
// QString playlistName = index.data().toString();
109+
// int playlistId = m_playlistDao.getPlaylistIdFromName(playlistName);
110+
int playlistId = index.data(TreeItemModel::kDataRole).toInt();
111+
// not a real entry
112+
if (playlistId == -1) {
113+
return;
114+
}
106115

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

139148
QList<BasePlaylistFeature::IdAndLabel> SetlogFeature::createPlaylistLabels() {
140-
QList<BasePlaylistFeature::IdAndLabel> playlistLabels;
149+
// QList<BasePlaylistFeature::IdAndLabel> playlistLabels;
150+
return QList<BasePlaylistFeature::IdAndLabel>();
151+
}
152+
153+
/**
154+
* Purpose: When inserting or removing playlists,
155+
* we require the sidebar model not to reset.
156+
* This method queries the database and does dynamic insertion
157+
* Use a custom model in the history for grouping by year
158+
*/
159+
QModelIndex SetlogFeature::constructChildModel(int selectedId) {
160+
int selected_row = -1;
161+
141162
// Setup the sidebar playlist model
142163
QSqlTableModel playlistTableModel(this, m_pLibrary->trackCollections()->internalCollection()->database());
143164
playlistTableModel.setTable("Playlists");
144165
playlistTableModel.setFilter("hidden=2"); // PLHT_SET_LOG
145-
playlistTableModel.setSort(playlistTableModel.fieldIndex("id"),
146-
Qt::AscendingOrder);
166+
playlistTableModel.setSort(
167+
playlistTableModel.fieldIndex("id"),
168+
Qt::DescendingOrder);
147169
playlistTableModel.select();
148170
while (playlistTableModel.canFetchMore()) {
149171
playlistTableModel.fetchMore();
150172
}
151173
QSqlRecord record = playlistTableModel.record();
152174
int nameColumn = record.indexOf("name");
153175
int idColumn = record.indexOf("id");
176+
int createdColumn = record.indexOf("date_created");
177+
178+
auto groups = QMap<int, TreeItem*>();
179+
180+
QList<TreeItem*> data_list;
181+
data_list.reserve(playlistTableModel.rowCount());
154182

155183
for (int row = 0; row < playlistTableModel.rowCount(); ++row) {
156184
int id = playlistTableModel.data(
157185
playlistTableModel.index(row, idColumn))
158186
.toInt();
159-
QString name = playlistTableModel.data(
160-
playlistTableModel.index(row, nameColumn))
187+
QString name = playlistTableModel
188+
.data(playlistTableModel.index(row, nameColumn))
161189
.toString();
162-
BasePlaylistFeature::IdAndLabel idAndLabel;
163-
idAndLabel.id = id;
164-
idAndLabel.label = name;
165-
playlistLabels.append(idAndLabel);
190+
191+
QDateTime created =
192+
playlistTableModel
193+
.data(playlistTableModel.index(row, createdColumn))
194+
.toDateTime();
195+
196+
if (selectedId == id) {
197+
// save index for selection
198+
selected_row = row;
199+
}
200+
201+
// Create the TreeItem whose parent is the invisible root item
202+
if (row >= kNumDirectHistoryEntries) {
203+
int year = created.date().year();
204+
205+
QMap<int, TreeItem*>::const_iterator i = groups.find(year);
206+
TreeItem* groupItem;
207+
if (i != groups.end() && i.key() == year) {
208+
groupItem = i.value();
209+
} else {
210+
groupItem = new TreeItem(QString("%1").arg(year), -1);
211+
groups.insert(year, groupItem);
212+
data_list.append(groupItem);
213+
}
214+
215+
std::unique_ptr<TreeItem> item(new TreeItem(name, id));
216+
item->setBold(m_playlistsSelectedTrackIsIn.contains(id));
217+
218+
decorateChild(item.get(), id);
219+
220+
groupItem->appendChild(std::move(item));
221+
} else {
222+
TreeItem* item = new TreeItem(name, id);
223+
item->setBold(m_playlistsSelectedTrackIsIn.contains(id));
224+
225+
decorateChild(item, id);
226+
227+
data_list.append(item);
228+
}
229+
}
230+
231+
// Append all the newly created TreeItems in a dynamic way to the childmodel
232+
m_childModel.insertTreeItemRows(data_list, 0);
233+
if (selected_row == -1) {
234+
return QModelIndex();
166235
}
167-
return playlistLabels;
236+
// return playlistLabels;
237+
return m_childModel.index(selected_row, 0);
168238
}
169239

170240
QString SetlogFeature::fetchPlaylistLabel(int playlistId) {
@@ -384,20 +454,40 @@ void SetlogFeature::slotPlaylistTableRenamed(
384454
}
385455
}
386456

457+
void SetlogFeature::activate() {
458+
activatePlaylist(m_playlistId);
459+
}
460+
461+
void SetlogFeature::activatePlaylist(int playlistId) {
462+
//qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId;
463+
QModelIndex index = indexFromPlaylistId(playlistId);
464+
if (playlistId != -1 && index.isValid()) {
465+
m_pPlaylistTableModel->setTableModel(playlistId);
466+
emit showTrackModel(m_pPlaylistTableModel);
467+
emit enableCoverArtDisplay(true);
468+
// Update selection only, if it is not the current playlist
469+
if (playlistId != m_playlistId) {
470+
emit featureSelect(this, m_lastRightClickedIndex);
471+
activateChild(m_lastRightClickedIndex);
472+
}
473+
}
474+
}
475+
387476
QString SetlogFeature::getRootViewHtml() const {
388-
QString playlistsTitle = tr("History");
389-
QString playlistsSummary = tr("The history section automatically keeps a list of tracks you play in your DJ sets.");
390-
QString playlistsSummary2 = tr("This is handy for remembering what worked in your DJ sets, posting set-lists, or reporting your plays to licensing organizations.");
391-
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.");
392-
QString playlistsSummary4 = tr("You can join the current history session with a previous one by right-clicking and selecting \"Join with previous\".");
393-
394-
QString html;
395-
html.append(QString("<h2>%1</h2>").arg(playlistsTitle));
396-
html.append("<table border=\"0\" cellpadding=\"5\"><tr><td>");
397-
html.append(QString("<p>%1</p>").arg(playlistsSummary));
398-
html.append(QString("<p>%1</p>").arg(playlistsSummary2));
399-
html.append(QString("<p>%1</p>").arg(playlistsSummary3));
400-
html.append(QString("<p>%1</p>").arg(playlistsSummary4));
401-
html.append("</td></tr></table>");
402-
return html;
477+
// QString playlistsTitle = tr("History");
478+
// QString playlistsSummary = tr("The history section automatically keeps a list of tracks you play in your DJ sets.");
479+
// QString playlistsSummary2 = tr("This is handy for remembering what worked in your DJ sets, posting set-lists, or reporting your plays to licensing organizations.");
480+
// 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.");
481+
// QString playlistsSummary4 = tr("You can join the current history session with a previous one by right-clicking and selecting \"Join with previous\".");
482+
//
483+
// QString html;
484+
// html.append(QString("<h2>%1</h2>").arg(playlistsTitle));
485+
// html.append("<table border=\"0\" cellpadding=\"5\"><tr><td>");
486+
// html.append(QString("<p>%1</p>").arg(playlistsSummary));
487+
// html.append(QString("<p>%1</p>").arg(playlistsSummary2));
488+
// html.append(QString("<p>%1</p>").arg(playlistsSummary3));
489+
// html.append(QString("<p>%1</p>").arg(playlistsSummary4));
490+
// html.append("</td></tr></table>");
491+
// return html;
492+
return QString();
403493
}

src/library/setlogfeature.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ class SetlogFeature : public BasePlaylistFeature {
2020
void bindLibraryWidget(WLibrary* libraryWidget,
2121
KeyboardEventFilter* keyboard) override;
2222
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget) override;
23+
void activatePlaylist(int playlistId) override;
2324

2425
public slots:
2526
void onRightClick(const QPoint& globalPos) override;
2627
void onRightClickChild(const QPoint& globalPos, QModelIndex index) override;
2728
void slotJoinWithPrevious();
2829
void slotGetNewPlaylist();
30+
void activate() override;
2931

3032
protected:
31-
QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels() override;
33+
// QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels() override;
34+
QList<BasePlaylistFeature::IdAndLabel> createPlaylistLabels();
3235
QString fetchPlaylistLabel(int playlistId) override;
36+
QModelIndex constructChildModel(int selectedId);
3337
void decorateChild(TreeItem* pChild, int playlistId) override;
3438

3539
private slots:

src/library/treeitem.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TreeItem final {
9595
// take ownership of children items
9696
void insertChildren(int row, QList<TreeItem*>& children);
9797
void removeChildren(int row, int count);
98-
98+
void insertChild(int row, TreeItem* pChild);
9999

100100
/////////////////////////////////////////////////////////////////////////
101101
// Payload
@@ -135,7 +135,6 @@ class TreeItem final {
135135
QString label = QString(),
136136
QVariant data = QVariant());
137137

138-
void insertChild(int row, TreeItem* pChild);
139138
void initFeatureRecursively(LibraryFeature* pFeature);
140139

141140
// The library feature is inherited from the parent.

0 commit comments

Comments
 (0)