@@ -107,6 +107,11 @@ void WTrackTableView::selectionChanged(
107107}
108108
109109void WTrackTableView::slotGuiTick50ms (double /* unused*/ ) {
110+ if (!isVisible ()) {
111+ // Don't proceed if this isn't visible.
112+ return ;
113+ }
114+
110115 // if the user is stopped in the same row for more than 0.1 s,
111116 // we load un-cached cover arts as well.
112117 mixxx::Duration timeDelta = mixxx::Time::elapsed () - m_lastUserAction;
@@ -116,7 +121,7 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) {
116121 // slows down scrolling performance so we wait until the user has
117122 // stopped interacting first.
118123 if (m_selectionChangedSinceLastGuiTick) {
119- const QModelIndexList indices = selectionModel ()-> selectedRows ();
124+ const QModelIndexList indices = getSelectedRows ();
120125 if (indices.size () == 1 && indices.first ().isValid ()) {
121126 // A single track has been selected
122127 TrackModel* trackModel = getTrackModel ();
@@ -401,7 +406,7 @@ TrackModel::SortColumnId WTrackTableView::getColumnIdFromCurrentIndex() {
401406}
402407
403408void WTrackTableView::assignPreviousTrackColor () {
404- QModelIndexList indices = selectionModel ()-> selectedRows ();
409+ const QModelIndexList indices = getSelectedRows ();
405410 if (indices.isEmpty ()) {
406411 return ;
407412 }
@@ -422,7 +427,7 @@ void WTrackTableView::assignPreviousTrackColor() {
422427}
423428
424429void WTrackTableView::assignNextTrackColor () {
425- QModelIndexList indices = selectionModel ()-> selectedRows ();
430+ const QModelIndexList indices = getSelectedRows ();
426431 if (indices.isEmpty ()) {
427432 return ;
428433 }
@@ -443,7 +448,7 @@ void WTrackTableView::assignNextTrackColor() {
443448}
444449
445450void WTrackTableView::slotPurge () {
446- QModelIndexList indices = selectionModel ()-> selectedRows ();
451+ const QModelIndexList indices = getSelectedRows ();
447452 if (indices.isEmpty ()) {
448453 return ;
449454 }
@@ -457,7 +462,7 @@ void WTrackTableView::slotPurge() {
457462}
458463
459464void WTrackTableView::slotDeleteTracksFromDisk () {
460- QModelIndexList indices = selectionModel ()-> selectedRows ();
465+ const QModelIndexList indices = getSelectedRows ();
461466 if (indices.isEmpty ()) {
462467 return ;
463468 }
@@ -468,7 +473,7 @@ void WTrackTableView::slotDeleteTracksFromDisk() {
468473}
469474
470475void WTrackTableView::slotUnhide () {
471- QModelIndexList indices = selectionModel ()-> selectedRows ();
476+ const QModelIndexList indices = getSelectedRows ();
472477 if (indices.isEmpty ()) {
473478 return ;
474479 }
@@ -505,7 +510,10 @@ void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) {
505510 }
506511 event->accept ();
507512 // Update track indices in context menu
508- QModelIndexList indices = selectionModel ()->selectedRows ();
513+ const QModelIndexList indices = getSelectedRows ();
514+ if (indices.isEmpty ()) {
515+ return ;
516+ }
509517 m_pTrackMenu->loadTrackModelIndices (indices);
510518
511519 saveCurrentIndex ();
@@ -576,7 +584,7 @@ void WTrackTableView::mouseMoveEvent(QMouseEvent* pEvent) {
576584 if (DragAndDropHelper::mouseMoveInitiatesDrag (pEvent)) {
577585 // Iterate over selected rows and append each item's location url to a list.
578586 QList<QString> locations;
579- const QModelIndexList indices = selectionModel ()-> selectedRows ();
587+ const QModelIndexList indices = getSelectedRows ();
580588
581589 for (const QModelIndex& index : indices) {
582590 if (!index.isValid ()) {
@@ -635,13 +643,18 @@ void WTrackTableView::dragMoveEvent(QDragMoveEvent * event) {
635643// Drag-and-drop "drop" event. Occurs when something is dropped onto the track table view
636644void WTrackTableView::dropEvent (QDropEvent * event) {
637645 TrackModel* trackModel = getTrackModel ();
638-
639646 // We only do things to the TrackModel in this method so if we don't have
640647 // one we should just bail.
641648 if (!trackModel) {
642649 return ;
643650 }
644651
652+ QItemSelectionModel* pSelectionModel = selectionModel ();
653+ VERIFY_OR_DEBUG_ASSERT (pSelectionModel != nullptr ) {
654+ qWarning () << " No selection model available" ;
655+ return ;
656+ }
657+
645658 if (!event->mimeData ()->hasUrls () || trackModel->isLocked ()) {
646659 event->ignore ();
647660 return ;
@@ -684,7 +697,7 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
684697 // Save a list of row (just plain ints) so we don't get screwed over
685698 // when the QModelIndexes all become invalid (eg. after moveTrack()
686699 // or addTrack())
687- const QModelIndexList indices = selectionModel ()-> selectedRows ();
700+ const QModelIndexList indices = getSelectedRows ();
688701
689702 QList<int > selectedRows;
690703 for (const QModelIndex& idx : indices) {
@@ -764,13 +777,13 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
764777 // Highlight the moved rows again (restoring the selection)
765778 // QModelIndex newSelectedIndex = destIndex;
766779 for (int i = 0 ; i < selectedRowCount; i++) {
767- this -> selectionModel () ->select (model ()->index (selectionRestoreStartRow + i, 0 ),
768- QItemSelectionModel::Select | QItemSelectionModel::Rows);
780+ pSelectionModel ->select (model ()->index (selectionRestoreStartRow + i, 0 ),
781+ QItemSelectionModel::Select | QItemSelectionModel::Rows);
769782 }
770783 } else { // Drag and drop inside Mixxx is only for few rows, bulks happen here
771784 // Reset the selected tracks (if you had any tracks highlighted, it
772785 // clears them)
773- this -> selectionModel () ->clear ();
786+ pSelectionModel ->clear ();
774787
775788 // Have to do this here because the index is invalid after
776789 // addTrack
@@ -811,9 +824,9 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
811824 // reordering. (eg. crates don't support reordering/indexes)
812825 if (trackModel->hasCapabilities (TrackModel::Capability::Reorder)) {
813826 for (int i = selectionStartRow; i < selectionStartRow + numNewRows; i++) {
814- this -> selectionModel () ->select (model ()->index (i, 0 ),
815- QItemSelectionModel::Select |
816- QItemSelectionModel::Rows);
827+ pSelectionModel ->select (model ()->index (i, 0 ),
828+ QItemSelectionModel::Select |
829+ QItemSelectionModel::Rows);
817830 }
818831 }
819832 }
@@ -823,6 +836,15 @@ void WTrackTableView::dropEvent(QDropEvent * event) {
823836 verticalScrollBar ()->setValue (vScrollBarPos);
824837}
825838
839+ QModelIndexList WTrackTableView::getSelectedRows () const {
840+ QItemSelectionModel* pSelectionModel = selectionModel ();
841+ VERIFY_OR_DEBUG_ASSERT (pSelectionModel != nullptr ) {
842+ qWarning () << " No selection model available" ;
843+ return {};
844+ }
845+ return pSelectionModel->selectedRows ();
846+ }
847+
826848TrackModel* WTrackTableView::getTrackModel () const {
827849 TrackModel* trackModel = dynamic_cast <TrackModel*>(model ());
828850 return trackModel;
@@ -842,7 +864,7 @@ void WTrackTableView::keyPressEvent(QKeyEvent* event) {
842864 if (event->modifiers ().testFlag (Qt::NoModifier)) {
843865 slotMouseDoubleClicked (currentIndex ());
844866 } else if ((event->modifiers () & kPropertiesShortcutModifier )) {
845- QModelIndexList indices = selectionModel ()-> selectedRows ();
867+ const QModelIndexList indices = getSelectedRows ();
846868 if (indices.length () == 1 ) {
847869 m_pTrackMenu->loadTrackModelIndices (indices);
848870 m_pTrackMenu->slotShowDlgTrackInfo ();
@@ -902,7 +924,7 @@ void WTrackTableView::resizeEvent(QResizeEvent* event) {
902924}
903925
904926void WTrackTableView::hideOrRemoveSelectedTracks () {
905- QModelIndexList indices = selectionModel ()-> selectedRows ();
927+ const QModelIndexList indices = getSelectedRows ();
906928 if (indices.isEmpty ()) {
907929 return ;
908930 }
@@ -997,15 +1019,15 @@ void WTrackTableView::hideOrRemoveSelectedTracks() {
9971019}
9981020
9991021void WTrackTableView::activateSelectedTrack () {
1000- auto indices = selectionModel ()-> selectedRows ();
1022+ const QModelIndexList indices = getSelectedRows ();
10011023 if (indices.isEmpty ()) {
10021024 return ;
10031025 }
10041026 slotMouseDoubleClicked (indices.at (0 ));
10051027}
10061028
10071029void WTrackTableView::loadSelectedTrackToGroup (const QString& group, bool play) {
1008- auto indices = selectionModel ()-> selectedRows ();
1030+ const QModelIndexList indices = getSelectedRows ();
10091031 if (indices.isEmpty ()) {
10101032 return ;
10111033 }
@@ -1045,21 +1067,14 @@ void WTrackTableView::loadSelectedTrackToGroup(const QString& group, bool play)
10451067}
10461068
10471069QList<TrackId> WTrackTableView::getSelectedTrackIds () const {
1048- QList<TrackId> trackIds;
1049-
1050- QItemSelectionModel* pSelectionModel = selectionModel ();
1051- VERIFY_OR_DEBUG_ASSERT (pSelectionModel != nullptr ) {
1052- qWarning () << " No selected tracks available" ;
1053- return trackIds;
1054- }
1055-
10561070 TrackModel* pTrackModel = getTrackModel ();
10571071 VERIFY_OR_DEBUG_ASSERT (pTrackModel != nullptr ) {
10581072 qWarning () << " No selected tracks available" ;
1059- return trackIds ;
1073+ return {} ;
10601074 }
10611075
1062- const QModelIndexList rows = selectionModel ()->selectedRows ();
1076+ const QModelIndexList rows = getSelectedRows ();
1077+ QList<TrackId> trackIds;
10631078 trackIds.reserve (rows.size ());
10641079 for (const QModelIndex& row: rows) {
10651080 const TrackId trackId = pTrackModel->getTrackId (row);
@@ -1234,8 +1249,12 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder)
12341249
12351250 sortByColumn (headerSection, sortOrder);
12361251
1237- QItemSelectionModel* currentSelection = selectionModel ();
1238- currentSelection->reset (); // remove current selection
1252+ QItemSelectionModel* pSelectionModel = selectionModel ();
1253+ VERIFY_OR_DEBUG_ASSERT (pSelectionModel != nullptr ) {
1254+ qWarning () << " No selection model available" ;
1255+ return ;
1256+ }
1257+ pSelectionModel->reset (); // remove current selection
12391258
12401259 // Find previously selected tracks and store respective rows for reselection.
12411260 QMap<int , int > selectedRows;
@@ -1276,7 +1295,7 @@ void WTrackTableView::doSortByColumn(int headerSection, Qt::SortOrder sortOrder)
12761295 while (i.hasNext ()) {
12771296 i.next ();
12781297 QModelIndex tl = itemModel->index (i.key (), 0 );
1279- currentSelection ->select (tl, QItemSelectionModel::Rows | QItemSelectionModel::Select);
1298+ pSelectionModel ->select (tl, QItemSelectionModel::Rows | QItemSelectionModel::Select);
12801299 }
12811300
12821301 // This seems to be broken since at least Qt 5.12: no scrolling is issued
0 commit comments