diff --git a/src/library/autodj/dlgautodj.cpp b/src/library/autodj/dlgautodj.cpp index d1b2a3ffd64..2830fc45aef 100644 --- a/src/library/autodj/dlgautodj.cpp +++ b/src/library/autodj/dlgautodj.cpp @@ -363,18 +363,16 @@ void DlgAutoDJ::slotRepeatPlaylistChanged(int checkState) { } void DlgAutoDJ::updateSelectionInfo() { - double duration = 0.0; - QModelIndexList indices = m_pTrackTableView->selectionModel()->selectedRows(); // Derive total duration from the table model. This is much faster than // getting the duration from individual track objects. - duration = m_pAutoDJTableModel->getDurationOfRows(indices); + mixxx::Duration duration = m_pAutoDJTableModel->getTotalDuration(indices); QString label; if (!indices.isEmpty()) { - label.append(mixxx::DurationBase::formatTime(duration)); + label.append(mixxx::DurationBase::formatTime(duration.toDoubleSeconds())); label.append(QString(" (%1)").arg(indices.size())); labelSelectionInfo->setToolTip(tr("Displays the duration and number of selected tracks.")); labelSelectionInfo->setText(label); diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index c233157f9f7..a860ebab6e6 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -319,12 +319,12 @@ void PlaylistTableModel::shuffleTracks(const QModelIndexList& shuffle, const QMo m_pTrackCollectionManager->internalCollection()->getPlaylistDAO().shuffleTracks(m_iPlaylistId, positions, allIds); } -double PlaylistTableModel::getDurationOfRows(const QModelIndexList& indices) { - double durationTotal = 0.0; +mixxx::Duration PlaylistTableModel::getTotalDuration(const QModelIndexList& indices) { if (indices.isEmpty()) { - return durationTotal; + return mixxx::Duration::empty(); } + double durationTotal = 0.0; const int durationColumnIndex = fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_DURATION); for (const auto& index : indices) { durationTotal += index.sibling(index.row(), durationColumnIndex) @@ -332,7 +332,7 @@ double PlaylistTableModel::getDurationOfRows(const QModelIndexList& indices) { .toDouble(); } - return durationTotal; + return mixxx::Duration::fromSeconds(durationTotal); } bool PlaylistTableModel::isColumnInternal(int column) { diff --git a/src/library/playlisttablemodel.h b/src/library/playlisttablemodel.h index 3720f2dfe8c..0443bd53577 100644 --- a/src/library/playlisttablemodel.h +++ b/src/library/playlisttablemodel.h @@ -1,6 +1,7 @@ #pragma once #include "library/trackset/tracksettablemodel.h" +#include "util/duration.h" class PlaylistTableModel final : public TrackSetTableModel { Q_OBJECT @@ -27,7 +28,8 @@ class PlaylistTableModel final : public TrackSetTableModel { int addTracks(const QModelIndex& index, const QList& locations) final; bool isLocked() final; - double getDurationOfRows(const QModelIndexList& indices); + /// Get the total duration of all tracks referenced by the given model indices + mixxx::Duration getTotalDuration(const QModelIndexList& indices); Capabilities getCapabilities() const final;