From 9548ef2a196bdb4f6bd14b06dcf54949382b600d Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 15 Apr 2024 15:16:18 +0200 Subject: [PATCH 1/3] Playlists: keep correct track selection (position) when sorting --- src/library/autodj/autodjfeature.cpp | 1 + src/library/banshee/bansheeplaylistmodel.cpp | 1 + src/library/baseexternalplaylistmodel.cpp | 2 +- src/library/basesqltablemodel.cpp | 41 ++++++-- src/library/basesqltablemodel.h | 32 +++++- src/library/dao/playlistdao.cpp | 1 + src/library/dao/playlistdao.h | 17 ---- src/library/dao/trackschema.h | 17 ++++ src/library/playlisttablemodel.cpp | 14 +++ src/library/playlisttablemodel.h | 1 + src/library/trackmodel.h | 9 ++ src/test/autodjprocessor_test.cpp | 1 + src/widget/wtracktableview.cpp | 101 ++++++++++++++----- src/widget/wtracktableview.h | 3 + 14 files changed, 185 insertions(+), 56 deletions(-) diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index 59525f24a389..e17d3e4da98d 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -5,6 +5,7 @@ #include "library/autodj/autodjprocessor.h" #include "library/autodj/dlgautodj.h" +#include "library/dao/trackschema.h" #include "library/library.h" #include "library/parser.h" #include "library/trackcollection.h" diff --git a/src/library/banshee/bansheeplaylistmodel.cpp b/src/library/banshee/bansheeplaylistmodel.cpp index 30805b66bea3..b6203ba009bd 100644 --- a/src/library/banshee/bansheeplaylistmodel.cpp +++ b/src/library/banshee/bansheeplaylistmodel.cpp @@ -4,6 +4,7 @@ #include "library/banshee/bansheedbconnection.h" #include "library/dao/playlistdao.h" +#include "library/dao/trackschema.h" #include "library/queryutil.h" #include "library/trackcollectionmanager.h" #include "mixer/playermanager.h" diff --git a/src/library/baseexternalplaylistmodel.cpp b/src/library/baseexternalplaylistmodel.cpp index f8e643c43239..01169cd9a377 100644 --- a/src/library/baseexternalplaylistmodel.cpp +++ b/src/library/baseexternalplaylistmodel.cpp @@ -136,7 +136,7 @@ void BaseExternalPlaylistModel::setPlaylistById(int playlistId) { // The ordering of columns is relevant (see below)! auto playlistViewColumns = QStringList{ QStringLiteral("track_id"), - QStringLiteral("position"), + PLAYLISTTRACKSTABLE_POSITION, QStringLiteral("'' AS ") + LIBRARYTABLE_PREVIEW}; const auto queryString = QStringLiteral( diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index 94b103dd4304..df981ab368a5 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -164,15 +164,18 @@ void BaseSqlTableModel::clearRows() { beginRemoveRows(QModelIndex(), 0, m_rowInfo.size() - 1); m_rowInfo.clear(); m_trackIdToRows.clear(); + m_trackPosToRow.clear(); endRemoveRows(); } DEBUG_ASSERT(m_rowInfo.isEmpty()); DEBUG_ASSERT(m_trackIdToRows.isEmpty()); + DEBUG_ASSERT(m_trackPosToRow.isEmpty()); } void BaseSqlTableModel::replaceRows( QVector&& rows, - TrackId2Rows&& trackIdToRows) { + TrackId2Rows&& trackIdToRows, + TrackPos2Row&& trackPosToRows) { // NOTE(uklotzde): Use r-value references for parameters here, because // conceptually those parameters should replace the corresponding internal // member variables. Currently Qt4/5 doesn't support move semantics and @@ -182,12 +185,16 @@ void BaseSqlTableModel::replaceRows( // its container types in the future this code becomes even more efficient. DEBUG_ASSERT(rows.empty() == trackIdToRows.empty()); DEBUG_ASSERT(rows.size() >= trackIdToRows.size()); + if (hasPositionColumn()) { + DEBUG_ASSERT(rows.size() == trackPosToRows.size()); + } if (rows.isEmpty()) { clearRows(); } else { beginInsertRows(QModelIndex(), 0, rows.size() - 1); m_rowInfo = rows; m_trackIdToRows = trackIdToRows; + m_trackPosToRow = trackPosToRows; endInsertRows(); } } @@ -246,6 +253,7 @@ void BaseSqlTableModel::select() { QVector rowInfos; QSet trackIds; int idColumn = -1; + int posColumn = -1; while (query.next()) { QSqlRecord sqlRecord = query.record(); @@ -253,11 +261,15 @@ void BaseSqlTableModel::select() { idColumn = sqlRecord.indexOf(m_idColumn); } + if (posColumn == -1 && hasPositionColumn()) { + posColumn = sqlRecord.indexOf(PLAYLISTTABLE_POSITION); + } + // TODO(XXX): Can we get rid of the hard-coded assumption that // the the first column always contains the id? DEBUG_ASSERT(idColumn == kIdColumn); - VERIFY_OR_DEBUG_ASSERT(idColumn >= 0) { + VERIFY_OR_DEBUG_ASSERT(idColumn != -1) { qCritical() << "ID column not available in database query results:" << m_idColumn; @@ -269,8 +281,8 @@ void BaseSqlTableModel::select() { RowInfo rowInfo; rowInfo.trackId = trackId; - // current position defines the ordering - rowInfo.order = rowInfos.size(); + rowInfo.row = rowInfos.size(); + rowInfo.metadata.reserve(sqlRecord.count()); for (int i = 0; i < m_tableColumns.size(); ++i) { rowInfo.metadata.push_back(sqlRecord.value(i)); @@ -298,9 +310,9 @@ void BaseSqlTableModel::select() { // separate removed tracks (order == -1) from present tracks (order == // 0). Otherwise we sort by the order that filterAndSort returned to us. if (m_trackSourceOrderBy.isEmpty()) { - rowInfo.order = m_trackSortOrder.contains(rowInfo.trackId) ? 0 : -1; + rowInfo.row = m_trackSortOrder.contains(rowInfo.trackId) ? 0 : -1; } else { - rowInfo.order = m_trackSortOrder.value(rowInfo.trackId, -1); + rowInfo.row = m_trackSortOrder.value(rowInfo.trackId, -1); } } } @@ -317,8 +329,7 @@ void BaseSqlTableModel::select() { trackIdToRows.reserve(rowInfos.size()); for (int i = 0; i < rowInfos.size(); ++i) { const RowInfo& rowInfo = rowInfos[i]; - - if (rowInfo.order == -1) { + if (rowInfo.row == -1) { // We've reached the end of valid rows. Resize rowInfo to cut off // this and all further elements. rowInfos.resize(i); @@ -330,10 +341,22 @@ void BaseSqlTableModel::select() { // number of total rows returned by the query DEBUG_ASSERT(trackIdToRows.size() <= rowInfos.size()); + TrackPos2Row trackPosToRows; + if (hasPositionColumn()) { + // We expect as many positions as we have rows + trackPosToRows.reserve(rowInfos.size()); + for (int i = 0; i < rowInfos.size(); ++i) { + const RowInfo& rowInfo = rowInfos[i]; + trackPosToRows.insert(rowInfo.getPosition(posColumn), i); + } + DEBUG_ASSERT(trackPosToRows.size() == rowInfos.size()); + } + // We're done! Issue the update signals and replace the main maps. replaceRows( std::move(rowInfos), - std::move(trackIdToRows)); + std::move(trackIdToRows), + std::move(trackPosToRows)); // Both rowInfo and trackIdToRows (might) have been moved and // must not be used afterwards! diff --git a/src/library/basesqltablemodel.h b/src/library/basesqltablemodel.h index 711185600dd9..167ae1a1af0e 100644 --- a/src/library/basesqltablemodel.h +++ b/src/library/basesqltablemodel.h @@ -56,6 +56,9 @@ class BaseSqlTableModel : public BaseTrackTableModel { const QVector getTrackRows(TrackId trackId) const override { return m_trackIdToRows.value(trackId); } + int getTrackRowByPosition(int position) const override { + return m_trackPosToRow.value(position); + } void search(const QString& searchText, const QString& extraFilter = QString()) override; const QString currentSearch() const override; @@ -100,6 +103,10 @@ class BaseSqlTableModel : public BaseTrackTableModel { protected: QList getTrackRefs(const QModelIndexList& indices) const; + bool hasPositionColumn() { + return fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION) >= 0; + } + QSqlDatabase m_database; QString m_tableName; @@ -121,26 +128,40 @@ class BaseSqlTableModel : public BaseTrackTableModel { struct RowInfo { TrackId trackId; - int order; + int row; QVector metadata; + int getPosition(int posCol) const { + if (posCol < 0) { + return -1; + } + bool ok = false; + int pos = metadata.at(posCol).toInt(&ok); + if (ok) { + return pos; + } + return -1; + } + bool operator<(const RowInfo& other) const { // -1 is greater than anything - if (order == -1) { + if (row == -1) { return false; - } else if (other.order == -1) { + } else if (other.row == -1) { return true; } - return order < other.order; + return row < other.row; } }; typedef QHash> TrackId2Rows; + typedef QHash TrackPos2Row; void clearRows(); void replaceRows( QVector&& rows, - TrackId2Rows&& trackIdToRows); + TrackId2Rows&& trackIdToRows, + TrackPos2Row&& trackPosToRows); QVector m_rowInfo; @@ -151,6 +172,7 @@ class BaseSqlTableModel : public BaseTrackTableModel { bool m_bInitialized; QHash m_trackSortOrder; TrackId2Rows m_trackIdToRows; + TrackPos2Row m_trackPosToRow; QString m_currentSearch; QString m_currentSearchFilter; QVector> m_headerInfo; diff --git a/src/library/dao/playlistdao.cpp b/src/library/dao/playlistdao.cpp index 40e8682bcccd..4eb91eccf3e9 100644 --- a/src/library/dao/playlistdao.cpp +++ b/src/library/dao/playlistdao.cpp @@ -4,6 +4,7 @@ #include #include "library/autodj/autodjprocessor.h" +#include "library/dao/trackschema.h" #include "library/queryutil.h" #include "moc_playlistdao.cpp" #include "util/db/dbconnection.h" diff --git a/src/library/dao/playlistdao.h b/src/library/dao/playlistdao.h index 885bcdbcbf18..636fce65637d 100644 --- a/src/library/dao/playlistdao.h +++ b/src/library/dao/playlistdao.h @@ -8,23 +8,6 @@ #include "track/trackid.h" #include "util/class.h" -#define PLAYLIST_TABLE "Playlists" -#define PLAYLIST_TRACKS_TABLE "PlaylistTracks" - -const QString PLAYLISTTABLE_ID = QStringLiteral("id"); -const QString PLAYLISTTABLE_NAME = QStringLiteral("name"); -const QString PLAYLISTTABLE_POSITION = QStringLiteral("position"); -const QString PLAYLISTTABLE_HIDDEN = QStringLiteral("hidden"); -const QString PLAYLISTTABLE_DATECREATED = QStringLiteral("date_created"); -const QString PLAYLISTTABLE_DATEMODIFIED = QStringLiteral("date_modified"); - -const QString PLAYLISTTRACKSTABLE_TRACKID = QStringLiteral("track_id"); -const QString PLAYLISTTRACKSTABLE_POSITION = QStringLiteral("position"); -const QString PLAYLISTTRACKSTABLE_PLAYLISTID = QStringLiteral("playlist_id"); -const QString PLAYLISTTRACKSTABLE_DATETIMEADDED = QStringLiteral("pl_datetime_added"); - -#define AUTODJ_TABLE "Auto DJ" - class AutoDJProcessor; class QSqlDatabase; diff --git a/src/library/dao/trackschema.h b/src/library/dao/trackschema.h index 328a6a6b30a7..3e1a010d657b 100644 --- a/src/library/dao/trackschema.h +++ b/src/library/dao/trackschema.h @@ -5,6 +5,11 @@ #define LIBRARY_TABLE "library" #define TRACKLOCATIONS_TABLE "track_locations" +#define PLAYLIST_TABLE "Playlists" +#define PLAYLIST_TRACKS_TABLE "PlaylistTracks" + +#define AUTODJ_TABLE "Auto DJ" + const QString LIBRARYTABLE_ID = QStringLiteral("id"); const QString LIBRARYTABLE_ARTIST = QStringLiteral("artist"); const QString LIBRARYTABLE_TITLE = QStringLiteral("title"); @@ -56,6 +61,18 @@ const QString TRACKLOCATIONSTABLE_FILESIZE = QStringLiteral("filesize"); const QString TRACKLOCATIONSTABLE_FSDELETED = QStringLiteral("fs_deleted"); const QString TRACKLOCATIONSTABLE_NEEDSVERIFICATION = QStringLiteral("needs_verification"); +const QString PLAYLISTTABLE_ID = QStringLiteral("id"); +const QString PLAYLISTTABLE_NAME = QStringLiteral("name"); +const QString PLAYLISTTABLE_POSITION = QStringLiteral("position"); +const QString PLAYLISTTABLE_HIDDEN = QStringLiteral("hidden"); +const QString PLAYLISTTABLE_DATECREATED = QStringLiteral("date_created"); +const QString PLAYLISTTABLE_DATEMODIFIED = QStringLiteral("date_modified"); + +const QString PLAYLISTTRACKSTABLE_TRACKID = QStringLiteral("track_id"); +const QString PLAYLISTTRACKSTABLE_POSITION = QStringLiteral("position"); +const QString PLAYLISTTRACKSTABLE_PLAYLISTID = QStringLiteral("playlist_id"); +const QString PLAYLISTTRACKSTABLE_DATETIMEADDED = QStringLiteral("pl_datetime_added"); + const QString REKORDBOX_ANALYZE_PATH = "analyze_path"; namespace mixxx { diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index 5e526db22186..2e56b2868406 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -327,6 +327,20 @@ void PlaylistTableModel::shuffleTracks(const QModelIndexList& shuffle, const QMo m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().shuffleTracks(m_iPlaylistId, positions, allIds); } +const QList PlaylistTableModel::getSelectedPositions(const QModelIndexList& indices) const { + if (indices.isEmpty()) { + return {}; + } + QList positions; + // TODO Transpose m_trackPosToRow ?? Would it be faster? + const int positionColumn = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION); + for (auto idx : indices) { + int pos = idx.siblingAtColumn(positionColumn).data().toInt(); + positions.append(pos); + } + return positions; +} + mixxx::Duration PlaylistTableModel::getTotalDuration(const QModelIndexList& indices) { if (indices.isEmpty()) { return mixxx::Duration::empty(); diff --git a/src/library/playlisttablemodel.h b/src/library/playlisttablemodel.h index 9fe6407b68d1..530233631a28 100644 --- a/src/library/playlisttablemodel.h +++ b/src/library/playlisttablemodel.h @@ -33,6 +33,7 @@ class PlaylistTableModel final : public TrackSetTableModel { /// Get the total duration of all tracks referenced by the given model indices mixxx::Duration getTotalDuration(const QModelIndexList& indices); + const QList getSelectedPositions(const QModelIndexList& indices) const override; Capabilities getCapabilities() const final; diff --git a/src/library/trackmodel.h b/src/library/trackmodel.h index c811114709ad..f8790aa6f021 100644 --- a/src/library/trackmodel.h +++ b/src/library/trackmodel.h @@ -128,6 +128,15 @@ class TrackModel { // Gets the rows of the track in the current result set. Returns an // empty list if the track ID is not present in the result set. virtual const QVector getTrackRows(TrackId trackId) const = 0; + virtual int getTrackRowByPosition(int position) const { + Q_UNUSED(position); + return -1; + } + + virtual const QList getSelectedPositions(const QModelIndexList& indices) const { + Q_UNUSED(indices); + return {}; + } virtual void search(const QString& searchText, const QString& extraFilter=QString()) = 0; virtual const QString currentSearch() const = 0; diff --git a/src/test/autodjprocessor_test.cpp b/src/test/autodjprocessor_test.cpp index a9d4b3eb9da1..72ac2ca7f531 100644 --- a/src/test/autodjprocessor_test.cpp +++ b/src/test/autodjprocessor_test.cpp @@ -10,6 +10,7 @@ #include "control/controlpotmeter.h" #include "control/controlpushbutton.h" #include "engine/engine.h" +#include "library/dao/trackschema.h" #include "library/playlisttablemodel.h" #include "mixer/basetrackplayer.h" #include "mixer/playerinfo.h" diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index d036bb31cfa4..acb6cb498577 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -1214,41 +1214,98 @@ void WTrackTableView::slotSelectTrack(const TrackId& trackId) { void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder) { TrackModel* trackModel = getTrackModel(); - QAbstractItemModel* itemModel = model(); - if (trackModel == nullptr || itemModel == nullptr || !m_sorting) { + if (trackModel == nullptr || !m_sorting) { return; } // Save the selection - const QList selectedTrackIds = getSelectedTrackIds(); + // If this is track model that may contain a track multiple times (a playlist), + // we store the positions in order to reselect only the current selection, + // not all occurrences of selected tracks. + QList selectedTrackIds; + QList selectedTrackPositions; + bool usePositions = trackModel->hasCapabilities(TrackModel::Capability::Reorder); + if (usePositions) { + const QModelIndexList indices = selectionModel()->selectedRows(); + selectedTrackPositions = trackModel->getSelectedPositions(indices); + } else { + selectedTrackIds = getSelectedTrackIds(); + } + int savedHScrollBarPos = horizontalScrollBar()->value(); // Save the column of focused table cell. // The cell is not necessarily part of the selection, but even if it's // focused after deselecting a row we may assume the user clicked onto the // column that will be used for sorting. - int prevColum = 0; + int prevColumn = 0; if (currentIndex().isValid()) { - prevColum = currentIndex().column(); + prevColumn = currentIndex().column(); } sortByColumn(headerSection, sortOrder); - QItemSelectionModel* currentSelection = selectionModel(); - currentSelection->reset(); // remove current selection + if (usePositions) { + selectTracksByPosition(selectedTrackPositions, prevColumn); + } else { + selectTracksById(selectedTrackIds, prevColumn); + } + + // This seems to be broken since at least Qt 5.12: no scrolling is issued + // scrollTo(first, QAbstractItemView::EnsureVisible); + horizontalScrollBar()->setValue(savedHScrollBarPos); +} + +void WTrackTableView::selectTracksByPosition(const QList& positions, int prevColumn) { + if (positions.isEmpty()) { + return; + } + TrackModel* pTrackModel = getTrackModel(); + QItemSelectionModel* pSelectionModel = selectionModel(); + pSelectionModel->reset(); // remove current selection + + // Find previously selected tracks and store respective rows for reselection. + QList rows; + for (int pos : positions) { + rows.append(pTrackModel->getTrackRowByPosition(pos)); + } + + // Select the first row of the previous selection. + // This scrolls to that row and with the leftmost cell being focused we have + // a starting point (currentIndex) for navigation with Up/Down keys. + // Replaces broken scrollTo() (see comment below) + if (!rows.isEmpty()) { + selectRow(rows.first()); + } + + // Refocus the cell in the column that was focused before sorting. + // With this, any Up/Down key press moves the selection and keeps the + // horizontal scrollbar position we will restore below. + QModelIndex restoreIndex = model()->index(currentIndex().row(), prevColumn); + if (restoreIndex.isValid()) { + setCurrentIndex(restoreIndex); + } + + // Restore previous selection (doesn't affect focused cell). + for (int row : rows) { + pSelectionModel->select(model()->index(row, prevColumn), + QItemSelectionModel::Select | QItemSelectionModel::Rows); + } +} + +// Don't use this on playlists since they may contain a TrackId multiple times. +// See doSortByColumn. +void WTrackTableView::selectTracksById(const QList& trackIds, int prevColum) { + TrackModel* pTrackModel = getTrackModel(); + QAbstractItemModel* pItemModel = model(); + + QItemSelectionModel* pSelectionModel = selectionModel(); + pSelectionModel->reset(); // remove current selection // Find previously selected tracks and store respective rows for reselection. QMap selectedRows; - for (const auto& trackId : selectedTrackIds) { - // TODO(rryan) slowly fixing the issues with BaseSqlTableModel. This - // code is broken for playlists because it assumes each trackid is in - // the table once. This will erroneously select all instances of the - // track for playlists, but it works fine for every other view. The way - // to fix this that we should do is to delegate the selection saving to - // the TrackModel. This will allow the playlist table model to use the - // table index as the unique id instead of this code stupidly using - // trackid. - const auto rows = trackModel->getTrackRows(trackId); + for (const auto& trackId : trackIds) { + const auto rows = pTrackModel->getTrackRows(trackId); for (int row : rows) { // Restore sort order by rows, so the following commands will act as expected selectedRows.insert(row, 0); @@ -1266,7 +1323,7 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder) // Refocus the cell in the column that was focused before sorting. // With this, any Up/Down key press moves the selection and keeps the // horizontal scrollbar position we will restore below. - QModelIndex restoreIndex = itemModel->index(currentIndex().row(), prevColum); + QModelIndex restoreIndex = pItemModel->index(currentIndex().row(), prevColum); if (restoreIndex.isValid()) { setCurrentIndex(restoreIndex); } @@ -1275,13 +1332,9 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder) QMapIterator i(selectedRows); while (i.hasNext()) { i.next(); - QModelIndex tl = itemModel->index(i.key(), 0); - currentSelection->select(tl, QItemSelectionModel::Rows | QItemSelectionModel::Select); + QModelIndex tl = pItemModel->index(i.key(), 0); + pSelectionModel->select(tl, QItemSelectionModel::Rows | QItemSelectionModel::Select); } - - // This seems to be broken since at least Qt 5.12: no scrolling is issued - //scrollTo(first, QAbstractItemView::EnsureVisible); - horizontalScrollBar()->setValue(savedHScrollBarPos); } void WTrackTableView::applySortingIfVisible() { diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h index 7b2d82204d79..91052531cafc 100644 --- a/src/widget/wtracktableview.h +++ b/src/widget/wtracktableview.h @@ -47,6 +47,9 @@ class WTrackTableView : public WLibraryTableView { TrackId getCurrentTrackId() const; bool setCurrentTrackId(const TrackId& trackId, int column = 0, bool scrollToTrack = false); + void selectTracksById(const QList& tracks, int prevColumn); + void selectTracksByPosition(const QList& positions, int prevColum); + double getBackgroundColorOpacity() const { return m_backgroundColorOpacity; } From 0a34e4b9f10a9776f0fedcc316880c9d766e4e45 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sat, 17 Aug 2024 14:53:36 +0200 Subject: [PATCH 2/3] BaseSqlTablemodel RowInfo: rename metadata -> columnValues --- src/library/basesqltablemodel.cpp | 12 ++++++------ src/library/basesqltablemodel.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index df981ab368a5..4521c6f992ea 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -283,9 +283,9 @@ void BaseSqlTableModel::select() { rowInfo.trackId = trackId; rowInfo.row = rowInfos.size(); - rowInfo.metadata.reserve(sqlRecord.count()); + rowInfo.columnValues.reserve(sqlRecord.count()); for (int i = 0; i < m_tableColumns.size(); ++i) { - rowInfo.metadata.push_back(sqlRecord.value(i)); + rowInfo.columnValues.push_back(sqlRecord.value(i)); } rowInfos.push_back(rowInfo); } @@ -674,13 +674,13 @@ QVariant BaseSqlTableModel::rawValue( return previewDeckTrackId() == trackId; } - const QVector& columns = rowInfo.metadata; + const QVector& columnValues = rowInfo.columnValues; if (sDebug) { qDebug() << "Returning table-column value" - << columns.at(column) - << "for column" << column; + << columnValues.at(column) + << "for column" << column; } - return columns[column]; + return columnValues[column]; } // Otherwise, return the information from the track record cache for the diff --git a/src/library/basesqltablemodel.h b/src/library/basesqltablemodel.h index 167ae1a1af0e..94a3ccd90cd2 100644 --- a/src/library/basesqltablemodel.h +++ b/src/library/basesqltablemodel.h @@ -129,14 +129,14 @@ class BaseSqlTableModel : public BaseTrackTableModel { struct RowInfo { TrackId trackId; int row; - QVector metadata; + QVector columnValues; int getPosition(int posCol) const { if (posCol < 0) { return -1; } bool ok = false; - int pos = metadata.at(posCol).toInt(&ok); + int pos = columnValues.at(posCol).toInt(&ok); if (ok) { return pos; } From fc123136fea0a875da08c02871f0f5dbb264e017 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Fri, 20 Sep 2024 00:31:51 +0200 Subject: [PATCH 3/3] remove comment --- src/library/playlisttablemodel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index 97e3d286dee1..06c11183eaaf 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -340,7 +340,6 @@ const QList PlaylistTableModel::getSelectedPositions(const QModelIndexList& return {}; } QList positions; - // TODO Transpose m_trackPosToRow ?? Would it be faster? const int positionColumn = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION); for (auto idx : indices) { int pos = idx.siblingAtColumn(positionColumn).data().toInt();