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
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
rename PlaylistTableModel::getDurationOfRows(), return mixxx::Duratio…
…n, add comment
ronso0 committed Jan 9, 2024
commit 69d65d751d358f8e5b393079537de85f31a96d54
6 changes: 2 additions & 4 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 4 additions & 4 deletions src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
@@ -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) {
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
@@ -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;