Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 13 additions & 11 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ const QString kViewName = QStringLiteral("Auto DJ");
namespace {
constexpr int kMaxRetrieveAttempts = 3;

int findOrCrateAutoDjPlaylistId(PlaylistDAO& playlistDAO) {
int playlistId = playlistDAO.getPlaylistIdFromName(AUTODJ_TABLE);
// If the AutoDJ playlist does not exist yet then create it.
if (playlistId < 0) {
playlistId = playlistDAO.createPlaylist(
AUTODJ_TABLE, PlaylistDAO::PLHT_AUTO_DJ);
VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) {
qWarning() << "Failed to create Auto DJ playlist!";
}
int findOrCrateAutoDjPlaylistId(PlaylistDAO& playlistDAO) {
int playlistId = playlistDAO.getPlaylistIdFromName(AUTODJ_TABLE);
// If the AutoDJ playlist does not exist yet then create it.
if (playlistId < 0) {
playlistId = playlistDAO.createPlaylist(
AUTODJ_TABLE, PlaylistDAO::PLHT_AUTO_DJ);
VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) {
qWarning() << "Failed to create Auto DJ playlist!";
}
return playlistId;
}
return playlistId;
}
} // anonymous namespace

AutoDJFeature::AutoDJFeature(Library* pLibrary,
Expand Down Expand Up @@ -159,7 +159,9 @@ TreeItemModel* AutoDJFeature::sidebarModel() const {
void AutoDJFeature::activate() {
//qDebug() << "AutoDJFeature::activate()";
emit switchToView(kViewName);
emit disableSearch();
if (m_pAutoDJView) {
emit restoreSearch(m_pAutoDJView->currentSearch());
}
emit enableCoverArtDisplay(true);
}

Expand Down
22 changes: 18 additions & 4 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/library.h"
#include "library/playlisttablemodel.h"
#include "library/proxytrackmodel.h"
#include "moc_dlgautodj.cpp"
#include "track/track.h"
#include "util/assert.h"
Expand Down Expand Up @@ -34,6 +35,7 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
parent->getTrackTableBackgroundColorOpacity(),
/*no sorting*/ false)),
m_bShowButtonText(parent->getShowButtonText()),
m_pProxyTableModel(nullptr),
m_pAutoDJTableModel(nullptr) {
setupUi(this);

Expand Down Expand Up @@ -79,7 +81,15 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,

// We do _NOT_ take ownership of this from AutoDJProcessor.
m_pAutoDJTableModel = m_pAutoDJProcessor->getTableModel();
m_pTrackTableView->loadTrackModel(m_pAutoDJTableModel);

// Wrap the table model so users can search it without
// messing up the table view for the AutoDJProcessor.
m_pProxyTableModel = new ProxyTrackModel(
m_pAutoDJTableModel,
/* handle searches*/ true);

// Use the proxy model for the displayed table & searches
m_pTrackTableView->loadTrackModel(m_pProxyTableModel);

// Do not set this because it disables auto-scrolling
//m_pTrackTableView->setDragDropMode(QAbstractItemView::InternalMove);
Expand Down Expand Up @@ -227,6 +237,7 @@ DlgAutoDJ::~DlgAutoDJ() {
// Delete m_pTrackTableView before the table model. This is because the
// table view saves the header state using the model.
delete m_pTrackTableView;
delete m_pProxyTableModel;
}

void DlgAutoDJ::setupActionButton(QPushButton* pButton,
Expand All @@ -240,12 +251,15 @@ void DlgAutoDJ::setupActionButton(QPushButton* pButton,

void DlgAutoDJ::onShow() {
m_pAutoDJTableModel->select();
m_pProxyTableModel->select();
}

void DlgAutoDJ::onSearch(const QString& text) {
// Do not allow filtering the Auto DJ playlist, because
// Auto DJ will work from the filtered table
Q_UNUSED(text);
m_pTrackTableView->onSearch(text);
}

const QString DlgAutoDJ::currentSearch() const {
return m_pProxyTableModel->currentSearch();
}

void DlgAutoDJ::activateSelectedTrack() {
Expand Down
3 changes: 3 additions & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "track/track_decl.h"

class PlaylistTableModel;
class ProxyTrackModel;
class WLibrary;
class WTrackTableView;
class Library;
Expand All @@ -35,6 +36,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void moveSelection(int delta) override;
void saveCurrentViewState() override;
bool restoreCurrentViewState() override;
const QString currentSearch() const;

public slots:
void shufflePlaylistButton(bool buttonChecked);
Expand Down Expand Up @@ -67,6 +69,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
WTrackTableView* const m_pTrackTableView;
const bool m_bShowButtonText;

ProxyTrackModel* m_pProxyTableModel;
PlaylistTableModel* m_pAutoDJTableModel;

QString m_enableBtnTooltip;
Expand Down
26 changes: 26 additions & 0 deletions src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ const QString COLUMNS_SORTING = QStringLiteral("ColumnsSorting");

const QString kModelName = "table:";

QList<int> columnNamesToIndices(
const QStringList& columnNames, const BaseSqlTableModel& tableModel) {
QList<int> indices;
indices.reserve(columnNames.size());
for (const QString& columnName : columnNames) {
auto index = tableModel.fieldIndex(columnName);
if (index < 0) {
continue;
}
indices.append(index);
}
return indices;
}
} // anonymous namespace

BaseSqlTableModel::BaseSqlTableModel(
Expand Down Expand Up @@ -157,6 +170,13 @@ void BaseSqlTableModel::initSortColumnMapping() {
}
}

void BaseSqlTableModel::initSearchColumns() {
if (m_trackSource) {
m_searchColumns = columnNamesToIndices(
m_trackSource->searchColumnsByName(), *this);
}
}

void BaseSqlTableModel::clearRows() {
DEBUG_ASSERT(m_rowInfo.empty() == m_trackIdToRows.empty());
DEBUG_ASSERT(m_rowInfo.size() >= m_trackIdToRows.size());
Expand Down Expand Up @@ -351,6 +371,7 @@ void BaseSqlTableModel::setTable(QString tableName,
m_tableName = std::move(tableName);
m_idColumn = std::move(idColumn);
m_tableColumns = std::move(tableColumns);
m_searchColumns.clear();

if (m_trackSource) {
disconnect(m_trackSource.data(),
Expand All @@ -376,6 +397,7 @@ void BaseSqlTableModel::setTable(QString tableName,

initTableColumnsAndHeaderProperties(m_tableColumns);
initSortColumnMapping();
initSearchColumns();

m_bInitialized = true;
}
Expand Down Expand Up @@ -422,6 +444,10 @@ void BaseSqlTableModel::search(const QString& searchText, const QString& extraFi
select();
}

const QList<int>& BaseSqlTableModel::searchColumns() const {
return m_searchColumns;
}

void BaseSqlTableModel::setSort(int column, Qt::SortOrder order) {
if (sDebug) {
qDebug() << this << "setSort()" << column << order << m_tableColumns;
Expand Down
3 changes: 3 additions & 0 deletions src/library/basesqltablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class BaseSqlTableModel : public BaseTrackTableModel {

void search(const QString& searchText, const QString& extraFilter = QString()) override;
const QString currentSearch() const override;
const QList<int>& searchColumns() const override;

TrackModel::SortColumnId sortColumnIdFromColumnIndex(int column) const override;
int columnIndexFromSortColumnId(TrackModel::SortColumnId sortColumn) const override;
Expand Down Expand Up @@ -94,6 +95,7 @@ class BaseSqlTableModel : public BaseTrackTableModel {
QSharedPointer<BaseTrackCache> trackSource);
void initHeaderProperties() override;
virtual void initSortColumnMapping();
void initSearchColumns();

TrackCollectionManager* const m_pTrackCollectionManager;

Expand Down Expand Up @@ -147,6 +149,7 @@ class BaseSqlTableModel : public BaseTrackTableModel {
QString m_idColumn;
QSharedPointer<BaseTrackCache> m_trackSource;
QStringList m_tableColumns;
QList<int> m_searchColumns;
QList<SortColumn> m_sortColumns;
bool m_bInitialized;
QHash<TrackId, int> m_trackSortOrder;
Expand Down
25 changes: 24 additions & 1 deletion src/library/basetrackcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ namespace {

constexpr bool sDebug = false;

QList<int> columnNamesToIndices(const QStringList& columnNames, const ColumnCache& columnCache) {
QList<int> indices;
indices.reserve(columnNames.size());
for (const QString& columnName : columnNames) {
auto index = columnCache.fieldIndex(columnName);
if (index < 0) {
continue;
}
indices.append(index);
}
return indices;
}
} // namespace

BaseTrackCache::BaseTrackCache(TrackCollection* pTrackCollection,
Expand All @@ -27,8 +39,11 @@ BaseTrackCache::BaseTrackCache(TrackCollection* pTrackCollection,
m_columnCount(columns.size()),
m_columnsJoined(columns.join(",")),
m_columnCache(std::move(columns)),
m_searchColumnNames(std::move(searchColumns)),
m_searchColumns(columnNamesToIndices(
m_searchColumnNames, m_columnCache)),
m_pQueryParser(std::make_unique<SearchQueryParser>(
pTrackCollection, std::move(searchColumns))),
pTrackCollection, m_searchColumnNames)),
m_bIndexBuilt(false),
m_bIsCaching(isCaching),
m_database(pTrackCollection->database()) {
Expand Down Expand Up @@ -437,6 +452,14 @@ QVariant BaseTrackCache::data(TrackId trackId, int column) const {
return result;
}

const QList<int>& BaseTrackCache::searchColumnsByIndex() const {
return m_searchColumns;
}

const QStringList& BaseTrackCache::searchColumnsByName() const {
return m_searchColumnNames;
}

void BaseTrackCache::filterAndSort(const QSet<TrackId>& trackIds,
const QString& searchQuery,
const QString& extraFilter,
Expand Down
4 changes: 4 additions & 0 deletions src/library/basetrackcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class BaseTrackCache : public QObject {
QString columnNameForFieldIndex(int index) const;
QString columnSortForFieldIndex(int index) const;
int fieldIndex(ColumnCache::Column column) const;
const QList<int>& searchColumnsByIndex() const;
const QStringList& searchColumnsByName() const;
virtual void filterAndSort(const QSet<TrackId>& trackIds,
const QString& query,
const QString& extraFilter,
Expand Down Expand Up @@ -122,6 +124,8 @@ class BaseTrackCache : public QObject {

const ColumnCache m_columnCache;

const QStringList m_searchColumnNames;
const QList<int> m_searchColumns;
const std::unique_ptr<SearchQueryParser> m_pQueryParser;

const mixxx::StringCollator m_collator;
Expand Down
23 changes: 23 additions & 0 deletions src/library/proxytrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ void ProxyTrackModel::removeTracks(const QModelIndexList& indices) {
}
}

void ProxyTrackModel::cutTracks(const QModelIndexList& indices) {
QModelIndexList translatedList;
foreach (QModelIndex index, indices) {
QModelIndex indexSource = mapToSource(index);
translatedList.append(indexSource);
}
if (m_pTrackModel) {
m_pTrackModel->cutTracks(translatedList);
}
}

void ProxyTrackModel::copyTracks(const QModelIndexList& indices) const {
QModelIndexList translatedList;
foreach (QModelIndex index, indices) {
Expand All @@ -124,6 +135,18 @@ void ProxyTrackModel::copyTracks(const QModelIndexList& indices) const {
}
}

QList<int> ProxyTrackModel::pasteTracks(const QModelIndex& index) {
QList<int> translatedList;
if (m_pTrackModel) {
QList<int> rowIndices = m_pTrackModel->pasteTracks(mapToSource(index));
foreach (int row, rowIndices) {
QModelIndex indexProxy = mapFromSource(sourceModel()->index(row, 0));
translatedList.append(indexProxy.row());
}
}
return translatedList;
}

void ProxyTrackModel::moveTrack(const QModelIndex& sourceIndex,
const QModelIndex& destIndex) {
QModelIndex sourceIndexSource = mapToSource(sourceIndex);
Expand Down
2 changes: 2 additions & 0 deletions src/library/proxytrackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class ProxyTrackModel : public QSortFilterProxyModel, public TrackModel {
bool isColumnInternal(int column) final;
bool isColumnHiddenByDefault(int column) final;
void removeTracks(const QModelIndexList& indices) final;
void cutTracks(const QModelIndexList& indices) final;
void copyTracks(const QModelIndexList& indices) const final;
QList<int> pasteTracks(const QModelIndex& index) final;
void moveTrack(const QModelIndex& sourceIndex, const QModelIndex& destIndex) final;
QAbstractItemDelegate* delegateForColumn(const int i, QObject* pParent) final;
QString getModelSetting(const QString& name) final;
Expand Down
Loading