Skip to content

(fix) Playlists: keep correct track selection (# position) when sorting - #13103

Merged
daschuer merged 4 commits into
mixxxdj:2.4from
ronso0:playlist-sort-keep-selection
Sep 20, 2024
Merged

(fix) Playlists: keep correct track selection (# position) when sorting#13103
daschuer merged 4 commits into
mixxxdj:2.4from
ronso0:playlist-sort-keep-selection

Conversation

@ronso0

@ronso0 ronso0 commented Apr 15, 2024

Copy link
Copy Markdown
Member

Previously, tracks were reselected by TrackId after sorting which would add wrong tracks to the selection in case the playlist contains tracks multiple times.

Introduces QHash<int row, int position>, equivalent to existing m_trackIdToRows hash, and repopulates that on every select (if table is a playlist).
Then, when sorting, query that for each previously selected playlist position, select, done.

@ronso0
ronso0 marked this pull request as draft April 15, 2024 11:33
@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch 2 times, most recently from a4c0768 to f99815a Compare April 15, 2024 13:57
@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch from f99815a to fe9c71d Compare April 16, 2024 23:16
@ronso0
ronso0 marked this pull request as ready for review April 17, 2024 08:36
@ronso0

ronso0 commented Apr 17, 2024

Copy link
Copy Markdown
Member Author

I went with the position->row hash.
Works nicely, didn't noticew any performance regression in select().

@ronso0

ronso0 commented Apr 17, 2024

Copy link
Copy Markdown
Member Author

This is actually a bugfix for 2.4, though it's low prio and I was to lazy to resolve the conflicts when applying this to 2.4 (since I worked off a main-based branch with lots of changes).

@m0dB

m0dB commented Apr 20, 2024

Copy link
Copy Markdown
Contributor

LGTM with a minor nitpick.

@JoergAtGithub

Copy link
Copy Markdown
Member

What you mean with nitpick?

@m0dB

m0dB commented Apr 20, 2024

Copy link
Copy Markdown
Contributor

I mean my being "pingelig" about comparing with <=0 instead of -1

@JoergAtGithub

Copy link
Copy Markdown
Member

Did you miss to Submit your review? I don't see anything.

Comment thread src/library/basesqltablemodel.cpp Outdated
@m0dB

m0dB commented Apr 20, 2024

Copy link
Copy Markdown
Contributor

Did you miss to Submit your review? I don't see anything.

Oops!

@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch from fecdccc to 3191b6e Compare May 1, 2024 02:55
@JoergAtGithub

Copy link
Copy Markdown
Member

There's a merge conflict now

@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch from 3191b6e to 81d60a1 Compare May 1, 2024 09:48
@ronso0
ronso0 changed the base branch from main to 2.4 May 1, 2024 09:49
@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch from d5e1ceb to 81d60a1 Compare May 1, 2024 09:50
@ronso0

ronso0 commented May 1, 2024

Copy link
Copy Markdown
Member Author

I have rebased this onto 2.4 and dropped the 'p' prefix commit in order to hopefully reduce merge conflicts with main.

@ronso0

ronso0 commented May 26, 2024

Copy link
Copy Markdown
Member Author

@m0dB I think I addressed your comments, wanna check it once more?

@daschuer daschuer added this to the 2.4.2 milestone Jun 9, 2024
@ronso0 ronso0 changed the title Playlists: keep correct track selection (position) when sorting (fix) Playlists: keep correct track selection (# position) when sorting Aug 14, 2024
@ronso0

ronso0 commented Aug 14, 2024

Copy link
Copy Markdown
Member Author

ping
I resolved the conflicts, all green now.

@daschuer daschuer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its works like a charm. The position look up can be simplified see my comments.

Comment thread src/library/basesqltablemodel.cpp Outdated
trackPosToRows.insert(rowInfo.position, i);
}
}
if (!m_positionColumn.isEmpty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about wrapping this to bool hasPositionColumn()?
I am unsure, but it can probably be reimplemented as:
fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION) >= 0

Comment thread src/library/basesqltablemodel.cpp Outdated
@@ -271,6 +279,18 @@ void BaseSqlTableModel::select() {
rowInfo.trackId = trackId;
// current position defines the ordering

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated: I do not really understand this comment?
rowInfo.order will be the rownNumber maybe should remove the comment and rename the element instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, removed and renamed order -> row

Comment thread src/library/basesqltablemodel.h Outdated
struct RowInfo {
TrackId trackId;
int order;
int position; // used by playlist models only

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be already in the metadata below. The name metadata IMHO misleading. Can we rename it into columnValues or such?
As a workaround it is accessed as const QVector<QVariant>& columns = rowInfo.metadata;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can replace the position with a getter function in BaseSqlTableModel: (Not tested)

int getPosition() {
   int posColumn = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION);
   if (posColumn < 0) {
       return -1;
   }
   return metadata[posCoumn];
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I copied the trackId implementation, but the position is needed (explicitly) only once to populate TrackPos2Row, so this change makes sense. Thanks!

Comment thread src/library/playlisttablemodel.cpp Outdated
@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch 2 times, most recently from 5995cf9 to cd160bb Compare August 17, 2024 15:09

@daschuer daschuer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you. Con you sqash the fixup and resolve the conflicts?
Than we can merge this.

@ronso0
ronso0 force-pushed the playlist-sort-keep-selection branch from cd160bb to 29526d7 Compare September 19, 2024 22:27
@daschuer

Copy link
Copy Markdown
Member

Thank you.

@daschuer
daschuer merged commit fbaff06 into mixxxdj:2.4 Sep 20, 2024
@ronso0
ronso0 deleted the playlist-sort-keep-selection branch September 20, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sorting of playlist with duplicates and selection selects all duplicates of selection

4 participants