Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/library/trackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ class TrackModel {

/// @brief modelKey returns a unique identifier for the model
/// @param noSearch don't include the current search in the key
/// @param baseOnly return only a identifier for the whole subsystem
virtual QString modelKey(bool noSearch) const = 0;

virtual bool getRequireConfirmationToHideRemoveTracks() {
Expand Down
85 changes: 52 additions & 33 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ void WTrackTableView::selectionChanged(
}

void WTrackTableView::slotGuiTick50ms(double /*unused*/) {
if (!isVisible()) {
// Don't proceed if this isn't visible.
return;
}

// if the user is stopped in the same row for more than 0.1 s,
// we load un-cached cover arts as well.
mixxx::Duration timeDelta = mixxx::Time::elapsed() - m_lastUserAction;
Expand All @@ -116,7 +121,7 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) {
// slows down scrolling performance so we wait until the user has
// stopped interacting first.
if (m_selectionChangedSinceLastGuiTick) {
const QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.size() == 1 && indices.first().isValid()) {
// A single track has been selected
TrackModel* trackModel = getTrackModel();
Expand Down Expand Up @@ -401,7 +406,7 @@ TrackModel::SortColumnId WTrackTableView::getColumnIdFromCurrentIndex() {
}

void WTrackTableView::assignPreviousTrackColor() {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand All @@ -422,7 +427,7 @@ void WTrackTableView::assignPreviousTrackColor() {
}

void WTrackTableView::assignNextTrackColor() {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand All @@ -443,7 +448,7 @@ void WTrackTableView::assignNextTrackColor() {
}

void WTrackTableView::slotPurge() {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand All @@ -457,7 +462,7 @@ void WTrackTableView::slotPurge() {
}

void WTrackTableView::slotDeleteTracksFromDisk() {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand All @@ -468,7 +473,7 @@ void WTrackTableView::slotDeleteTracksFromDisk() {
}

void WTrackTableView::slotUnhide() {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand Down Expand Up @@ -505,7 +510,10 @@ void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) {
}
event->accept();
// Update track indices in context menu
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
m_pTrackMenu->loadTrackModelIndices(indices);

saveCurrentIndex();
Expand Down Expand Up @@ -576,7 +584,7 @@ void WTrackTableView::mouseMoveEvent(QMouseEvent* pEvent) {
if (DragAndDropHelper::mouseMoveInitiatesDrag(pEvent)) {
// Iterate over selected rows and append each item's location url to a list.
QList<QString> locations;
const QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();

for (const QModelIndex& index : indices) {
if (!index.isValid()) {
Expand Down Expand Up @@ -635,13 +643,18 @@ void WTrackTableView::dragMoveEvent(QDragMoveEvent * event) {
// Drag-and-drop "drop" event. Occurs when something is dropped onto the track table view
void WTrackTableView::dropEvent(QDropEvent * event) {
TrackModel* trackModel = getTrackModel();

// We only do things to the TrackModel in this method so if we don't have
// one we should just bail.
if (!trackModel) {
return;
}

QItemSelectionModel* pSelectionModel = selectionModel();
VERIFY_OR_DEBUG_ASSERT(pSelectionModel != nullptr) {
qWarning() << "No selection model available";
return;
}

if (!event->mimeData()->hasUrls() || trackModel->isLocked()) {
event->ignore();
return;
Expand Down Expand Up @@ -684,7 +697,7 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
// Save a list of row (just plain ints) so we don't get screwed over
// when the QModelIndexes all become invalid (eg. after moveTrack()
// or addTrack())
const QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();

QList<int> selectedRows;
for (const QModelIndex& idx : indices) {
Expand Down Expand Up @@ -764,13 +777,13 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
// Highlight the moved rows again (restoring the selection)
//QModelIndex newSelectedIndex = destIndex;
for (int i = 0; i < selectedRowCount; i++) {
this->selectionModel()->select(model()->index(selectionRestoreStartRow + i, 0),
QItemSelectionModel::Select | QItemSelectionModel::Rows);
pSelectionModel->select(model()->index(selectionRestoreStartRow + i, 0),
QItemSelectionModel::Select | QItemSelectionModel::Rows);
}
} else { // Drag and drop inside Mixxx is only for few rows, bulks happen here
// Reset the selected tracks (if you had any tracks highlighted, it
// clears them)
this->selectionModel()->clear();
pSelectionModel->clear();

// Have to do this here because the index is invalid after
// addTrack
Expand Down Expand Up @@ -811,9 +824,9 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
// reordering. (eg. crates don't support reordering/indexes)
if (trackModel->hasCapabilities(TrackModel::Capability::Reorder)) {
for (int i = selectionStartRow; i < selectionStartRow + numNewRows; i++) {
this->selectionModel()->select(model()->index(i, 0),
QItemSelectionModel::Select |
QItemSelectionModel::Rows);
pSelectionModel->select(model()->index(i, 0),
QItemSelectionModel::Select |
QItemSelectionModel::Rows);
}
}
}
Expand All @@ -823,6 +836,15 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
verticalScrollBar()->setValue(vScrollBarPos);
}

QModelIndexList WTrackTableView::getSelectedRows() const {
QItemSelectionModel* pSelectionModel = selectionModel();
VERIFY_OR_DEBUG_ASSERT(pSelectionModel != nullptr) {
qWarning() << "No selection model available";
return {};
}
return pSelectionModel->selectedRows();
}

TrackModel* WTrackTableView::getTrackModel() const {
TrackModel* trackModel = dynamic_cast<TrackModel*>(model());
return trackModel;
Expand All @@ -842,7 +864,7 @@ void WTrackTableView::keyPressEvent(QKeyEvent* event) {
if (event->modifiers().testFlag(Qt::NoModifier)) {
slotMouseDoubleClicked(currentIndex());
} else if ((event->modifiers() & kPropertiesShortcutModifier)) {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.length() == 1) {
m_pTrackMenu->loadTrackModelIndices(indices);
m_pTrackMenu->slotShowDlgTrackInfo();
Expand Down Expand Up @@ -902,7 +924,7 @@ void WTrackTableView::resizeEvent(QResizeEvent* event) {
}

void WTrackTableView::hideOrRemoveSelectedTracks() {
QModelIndexList indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand Down Expand Up @@ -997,15 +1019,15 @@ void WTrackTableView::hideOrRemoveSelectedTracks() {
}

void WTrackTableView::activateSelectedTrack() {
auto indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
slotMouseDoubleClicked(indices.at(0));
}

void WTrackTableView::loadSelectedTrackToGroup(const QString& group, bool play) {
auto indices = selectionModel()->selectedRows();
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}
Expand Down Expand Up @@ -1045,21 +1067,14 @@ void WTrackTableView::loadSelectedTrackToGroup(const QString& group, bool play)
}

QList<TrackId> WTrackTableView::getSelectedTrackIds() const {
QList<TrackId> trackIds;

QItemSelectionModel* pSelectionModel = selectionModel();
VERIFY_OR_DEBUG_ASSERT(pSelectionModel != nullptr) {
qWarning() << "No selected tracks available";
return trackIds;
}

TrackModel* pTrackModel = getTrackModel();
VERIFY_OR_DEBUG_ASSERT(pTrackModel != nullptr) {
qWarning() << "No selected tracks available";
return trackIds;
return {};
}

const QModelIndexList rows = selectionModel()->selectedRows();
const QModelIndexList rows = getSelectedRows();
QList<TrackId> trackIds;
trackIds.reserve(rows.size());
for (const QModelIndex& row: rows) {
const TrackId trackId = pTrackModel->getTrackId(row);
Expand Down Expand Up @@ -1234,8 +1249,12 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder)

sortByColumn(headerSection, sortOrder);

QItemSelectionModel* currentSelection = selectionModel();
currentSelection->reset(); // remove current selection
QItemSelectionModel* pSelectionModel = selectionModel();
VERIFY_OR_DEBUG_ASSERT(pSelectionModel != nullptr) {
qWarning() << "No selection model available";
return;
}
pSelectionModel->reset(); // remove current selection

// Find previously selected tracks and store respective rows for reselection.
QMap<int, int> selectedRows;
Expand Down Expand Up @@ -1276,7 +1295,7 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder)
while (i.hasNext()) {
i.next();
QModelIndex tl = itemModel->index(i.key(), 0);
currentSelection->select(tl, QItemSelectionModel::Rows | QItemSelectionModel::Select);
pSelectionModel->select(tl, QItemSelectionModel::Rows | QItemSelectionModel::Select);
}

// This seems to be broken since at least Qt 5.12: no scrolling is issued
Expand Down
3 changes: 3 additions & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class WTrackTableView : public WLibraryTableView {
// when dragging.
void mouseMoveEvent(QMouseEvent *pEvent) override;

// Returns the list of selected rows, or an empty list if none are selected.
QModelIndexList getSelectedRows() const;

// Returns the current TrackModel, or returns NULL if none is set.
TrackModel* getTrackModel() const;

Expand Down