Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename PlaylistTableModel::getDurationOfRows(), return mixxx::Duration, add comment #12537

Merged
merged 1 commit into from
Jan 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/library/autodj/dlgautodj.cpp
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
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
@@ -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