Skip to content

Commit

Permalink
rename PlaylistTableModel::getDurationOfRows(), return mixxx::Duratio…
Browse files Browse the repository at this point in the history
…n, add comment
  • Loading branch information
ronso0 committed Jan 9, 2024
1 parent c28a789 commit 69d65d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,20 @@ 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)
.data(Qt::EditRole)
.toDouble();
}

return durationTotal;
return mixxx::Duration::fromSeconds(durationTotal);
}

bool PlaylistTableModel::isColumnInternal(int column) {
Expand Down
4 changes: 3 additions & 1 deletion src/library/playlisttablemodel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "library/trackset/tracksettablemodel.h"
#include "util/duration.h"

class PlaylistTableModel final : public TrackSetTableModel {
Q_OBJECT
Expand All @@ -27,7 +28,8 @@ class PlaylistTableModel final : public TrackSetTableModel {
int addTracks(const QModelIndex& index, const QList<QString>& 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;

Expand Down

0 comments on commit 69d65d7

Please sign in to comment.