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

Fix library track selection, save model state #4177

Merged
merged 12 commits into from
Nov 20, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,11 @@ bool DlgAutoDJ::hasFocus() const {
void DlgAutoDJ::setFocus() {
m_pTrackTableView->setFocus();
}

void DlgAutoDJ::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
}

void DlgAutoDJ::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();
}
2 changes: 2 additions & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void loadSelectedTrack() override;
void loadSelectedTrackToGroup(const QString& group, bool play) override;
void moveSelection(int delta) override;
void saveCurrentViewState() override;
void restoreCurrentViewState() override;

public slots:
void shufflePlaylistButton(bool buttonChecked);
Expand Down
21 changes: 20 additions & 1 deletion src/library/baseexternalplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include "moc_baseexternalplaylistmodel.cpp"
#include "track/track.h"

namespace {

const QString kModelName = "external:";

} // anonymous namespace

BaseExternalPlaylistModel::BaseExternalPlaylistModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
Expand All @@ -17,7 +23,8 @@ BaseExternalPlaylistModel::BaseExternalPlaylistModel(QObject* parent,
: BaseSqlTableModel(parent, pTrackCollectionManager, settingsNamespace),
m_playlistsTable(playlistsTable),
m_playlistTracksTable(playlistTracksTable),
m_trackSource(trackSource) {
m_trackSource(trackSource),
m_currentPlaylistId(-1) {
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
}

BaseExternalPlaylistModel::~BaseExternalPlaylistModel() {
Expand Down Expand Up @@ -134,6 +141,7 @@ void BaseExternalPlaylistModel::setPlaylist(const QString& playlist_path) {
return;
}

m_currentPlaylistId = playlistId;
playlistViewColumns.last() = LIBRARYTABLE_PREVIEW;
setTable(playlistViewTable, playlistViewColumns.first(), playlistViewColumns, m_trackSource);
setDefaultSort(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down Expand Up @@ -163,3 +171,14 @@ TrackModel::Capabilities BaseExternalPlaylistModel::getCapabilities() const {
Capability::LoadToPreviewDeck |
Capability::LoadToSampler;
}

QString BaseExternalPlaylistModel::modelKey(bool noSearch) const {
if (noSearch) {
return kModelName +
QString::number(m_currentPlaylistId);
}
return kModelName +
QString::number(m_currentPlaylistId) +
QStringLiteral("#") +
currentSearch();
}
12 changes: 7 additions & 5 deletions src/library/baseexternalplaylistmodel.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once

#include <QtSql>
#include <QItemDelegate>
#include <QString>
#include <QObject>
#include <QModelIndex>
#include <QObject>
#include <QString>
#include <QtSql>

#include "library/trackmodel.h"
#include "library/basesqltablemodel.h"
#include "library/librarytablemodel.h"
#include "library/dao/playlistdao.h"
#include "library/dao/trackdao.h"
#include "library/librarytablemodel.h"
#include "library/trackmodel.h"

class BaseExternalPlaylistModel : public BaseSqlTableModel {
Q_OBJECT
Expand All @@ -28,11 +28,13 @@ class BaseExternalPlaylistModel : public BaseSqlTableModel {
bool isColumnInternal(int column) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
Capabilities getCapabilities() const override;
QString modelKey(bool noSearch) const override;

private:
TrackId doGetTrackId(const TrackPointer& pTrack) const override;

QString m_playlistsTable;
QString m_playlistTracksTable;
QSharedPointer<BaseTrackCache> m_trackSource;
int m_currentPlaylistId;
};
11 changes: 11 additions & 0 deletions src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ constexpr int kMaxSortColumns = 3;
// Constant for getModelSetting(name)
const QString COLUMNS_SORTING = QStringLiteral("ColumnsSorting");

const QString kModelName = "table:";

} // anonymous namespace

BaseSqlTableModel::BaseSqlTableModel(
Expand Down Expand Up @@ -613,6 +615,15 @@ int BaseSqlTableModel::fieldIndex(const QString& fieldName) const {
return tableIndex;
}

QString BaseSqlTableModel::modelKey(bool noSearch) const {
if (noSearch) {
return kModelName + m_tableName;
}
return kModelName + m_tableName +
QStringLiteral("#") +
currentSearch();
}

QVariant BaseSqlTableModel::rawValue(
const QModelIndex& index) const {
DEBUG_ASSERT(index.isValid());
Expand Down
4 changes: 3 additions & 1 deletion src/library/basesqltablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class BaseSqlTableModel : public BaseTrackTableModel {
int fieldIndex(
ColumnCache::Column column) const final;

QString modelKey(bool noSearch) const override;

protected:
///////////////////////////////////////////////////////////////////////////
// Inherited from BaseTrackTableModel
Expand All @@ -98,6 +100,7 @@ class BaseSqlTableModel : public BaseTrackTableModel {
QList<TrackRef> getTrackRefs(const QModelIndexList& indices) const;

QSqlDatabase m_database;
QString m_tableName;

QString m_tableOrderBy;
int m_columnIndexBySortColumnId[static_cast<int>(TrackModel::SortColumnId::IdMax)];
Expand Down Expand Up @@ -140,7 +143,6 @@ class BaseSqlTableModel : public BaseTrackTableModel {

QVector<RowInfo> m_rowInfo;

QString m_tableName;
QString m_idColumn;
QSharedPointer<BaseTrackCache> m_trackSource;
QStringList m_tableColumns;
Expand Down
6 changes: 6 additions & 0 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ BrowseFeature::BrowseFeature(
&BrowseFeature::requestAddDir,
pLibrary,
&Library::slotRequestAddDir);
connect(&m_browseModel,
&BrowseTableModel::restoreModelState,
this,
&LibraryFeature::restoreModelState);

m_pAddQuickLinkAction = new QAction(tr("Add to Quick Links"),this);
connect(m_pAddQuickLinkAction,
Expand Down Expand Up @@ -245,6 +249,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) {

QString path = item->getData().toString();
if (path == QUICK_LINK_NODE || path == DEVICE_NODE) {
emit saveModelState();
m_browseModel.setPath({});
} else {
// Open a security token for this path and if we do not have access, ask
Expand All @@ -260,6 +265,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) {
return;
}
}
emit saveModelState();
m_browseModel.setPath(std::move(dirAccess));
}
emit showTrackModel(&m_proxyModel);
Expand Down
12 changes: 12 additions & 0 deletions src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ void BrowseTableModel::addSearchColumn(int index) {
}

void BrowseTableModel::setPath(mixxx::FileAccess path) {
if (path.info().hasLocation()) {
m_currentDirectory = path.info().locationPath();
} else {
m_currentDirectory = QString();
}
m_pBrowseThread->executePopulation(std::move(path), this);
}

Expand Down Expand Up @@ -360,6 +365,7 @@ void BrowseTableModel::slotInsert(const QList<QList<QStandardItem*> >& rows,
appendRow(rows.at(i));
}
}
emit restoreModelState();
}

TrackModel::Capabilities BrowseTableModel::getCapabilities() const {
Expand All @@ -370,6 +376,12 @@ TrackModel::Capabilities BrowseTableModel::getCapabilities() const {
Capability::LoadToSampler;
}

QString BrowseTableModel::modelKey(bool noSearch) const {
// Browse feature does currently not support searching.
Q_UNUSED(noSearch);
return QStringLiteral("browse:") + m_currentDirectory;
}

Qt::ItemFlags BrowseTableModel::flags(const QModelIndex& index) const {
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);

Expand Down
6 changes: 6 additions & 0 deletions src/library/browse/browsetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
BrowseTableModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager, RecordingManager* pRec);
virtual ~BrowseTableModel();

// initiate table population, store path
void setPath(mixxx::FileAccess path);

TrackPointer getTrack(const QModelIndex& index) const override;
Expand All @@ -78,6 +79,7 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
bool isColumnSortable(int column) const override;
TrackModel::SortColumnId sortColumnIdFromColumnIndex(int index) const override;
int columnIndexFromSortColumnId(TrackModel::SortColumnId sortColumn) const override;
QString modelKey(bool noSearch) const override;

bool updateTrackGenre(
Track* pTrack,
Expand All @@ -88,6 +90,9 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
const QString& mood) const override;
#endif // __EXTRA_METADATA__

signals:
void restoreModelState();

public slots:
void slotClear(BrowseTableModel*);
void slotInsert(const QList< QList<QStandardItem*> >&, BrowseTableModel*);
Expand All @@ -101,6 +106,7 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
QList<int> m_searchColumns;
RecordingManager* m_pRecordingManager;
BrowseThreadPointer m_pBrowseThread;
QString m_currentDirectory;
QString m_previewDeckGroup;
int m_columnIndexBySortColumnId[static_cast<int>(TrackModel::SortColumnId::IdMax)];
QMap<int, TrackModel::SortColumnId> m_sortColumnIdByColumnIndex;
Expand Down
8 changes: 8 additions & 0 deletions src/library/dlganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,11 @@ void DlgAnalysis::installEventFilter(QObject* pFilter) {
QWidget::installEventFilter(pFilter);
m_pAnalysisLibraryTableView->installEventFilter(pFilter);
}

void DlgAnalysis::saveCurrentViewState() {
m_pAnalysisLibraryTableView->saveCurrentViewState();
}

void DlgAnalysis::restoreCurrentViewState() {
m_pAnalysisLibraryTableView->restoreCurrentViewState();
}
6 changes: 4 additions & 2 deletions src/library/dlganalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <QButtonGroup>
#include <QItemSelection>

#include "preferences/usersettings.h"
#include "analyzer/analyzerprogress.h"
#include "library/analysislibrarytablemodel.h"
#include "library/libraryview.h"
#include "library/ui_dlganalysis.h"
#include "analyzer/analyzerprogress.h"
#include "preferences/usersettings.h"

class AnalysisLibraryTableModel;
class WAnalysisLibraryTableView;
Expand Down Expand Up @@ -35,6 +35,8 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra
inline const QString currentSearch() {
return m_pAnalysisLibraryTableModel->currentSearch();
}
void saveCurrentViewState() override;
void restoreCurrentViewState() override;

public slots:
void tableSelectionChanged(const QItemSelection& selected,
Expand Down
8 changes: 8 additions & 0 deletions src/library/dlghidden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ bool DlgHidden::hasFocus() const {
return m_pTrackTableView->hasFocus();
}

void DlgHidden::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
}

void DlgHidden::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();
}

void DlgHidden::setFocus() {
m_pTrackTableView->setFocus();
}
8 changes: 5 additions & 3 deletions src/library/dlghidden.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include <QItemSelection>

#include "library/ui_dlghidden.h"
#include "preferences/usersettings.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/library.h"
#include "library/libraryview.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/ui_dlghidden.h"
#include "preferences/usersettings.h"

class WLibrary;
class WTrackTableView;
Expand All @@ -26,6 +26,8 @@ class DlgHidden : public QWidget, public Ui::DlgHidden, public LibraryView {
void setFocus() override;
void onSearch(const QString& text) override;
QString currentSearch();
void saveCurrentViewState() override;
void restoreCurrentViewState() override;

public slots:
void clicked();
Expand Down
7 changes: 7 additions & 0 deletions src/library/dlgmissing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ bool DlgMissing::hasFocus() const {
return m_pTrackTableView->hasFocus();
}

void DlgMissing::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
};
void DlgMissing::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();
};

void DlgMissing::setFocus() {
m_pTrackTableView->setFocus();
}
8 changes: 5 additions & 3 deletions src/library/dlgmissing.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include <QItemSelection>

#include "library/ui_dlgmissing.h"
#include "preferences/usersettings.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/library.h"
#include "library/libraryview.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/ui_dlgmissing.h"
#include "preferences/usersettings.h"

class WLibrary;
class WTrackTableView;
Expand All @@ -26,6 +26,8 @@ class DlgMissing : public QWidget, public Ui::DlgMissing, public LibraryView {
void setFocus() override;
void onSearch(const QString& text) override;
QString currentSearch();
void saveCurrentViewState() override;
void restoreCurrentViewState() override;

public slots:
void clicked();
Expand Down
15 changes: 15 additions & 0 deletions src/library/hiddentablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "library/trackcollectionmanager.h"
#include "moc_hiddentablemodel.cpp"

namespace {

const QString kModelName = "hidden:";

} // anonymous namespace

HiddenTableModel::HiddenTableModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager)
: BaseSqlTableModel(parent, pTrackCollectionManager, "mixxx.db.model.missing") {
Expand Down Expand Up @@ -91,3 +97,12 @@ Qt::ItemFlags HiddenTableModel::flags(const QModelIndex& index) const {
TrackModel::Capabilities HiddenTableModel::getCapabilities() const {
return Capability::Purge | Capability::Unhide;
}

QString HiddenTableModel::modelKey(bool noSearch) const {
if (noSearch) {
return kModelName + m_tableName;
}
return kModelName + m_tableName +
QStringLiteral("#") +
currentSearch();
}
2 changes: 2 additions & 0 deletions src/library/hiddentablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ class HiddenTableModel final : public BaseSqlTableModel {
void unhideTracks(const QModelIndexList& indices) final;
Qt::ItemFlags flags(const QModelIndex &index) const final;
Capabilities getCapabilities() const final;

QString modelKey(bool noSearch) const override;
};
Loading