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 selection, save header configuration per crate/playlist #3063

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cc585bd
Query selectionModel for selected rows
poelzi Aug 29, 2020
b161ee9
Use signal to initiate state save
poelzi Aug 31, 2020
9a5f9c8
Add save/restore functionality for library views
poelzi Dec 8, 2020
dacc6b0
Add state save/restore to recordings/analyisis/missing features
poelzi Dec 8, 2020
6440f9e
Save/Restore support for externalplaylistmodel
poelzi Dec 8, 2020
2099964
Check TreeItem data before building
poelzi Dec 8, 2020
9a3f5c9
cleanup state safe/restoration code
poelzi Dec 9, 2020
b43732e
Cleanup item selection code
poelzi Dec 10, 2020
ab53d44
Fix crash on model switch, prevent memory leak
poelzi Dec 15, 2020
e7c5055
Use reusable model key names
poelzi Jan 2, 2021
a32e271
Save and restore header sorting
poelzi Jan 2, 2021
d29305b
Remove problematic default modelKey, instead require implementation.
poelzi Jan 2, 2021
ef966ad
Merge remote-tracking branch 'origin/2.3' into fix_selection
poelzi Jan 2, 2021
a63725c
Remove unused variable
poelzi Jan 2, 2021
ed426ce
Save also vertical scrolling position
poelzi Jan 2, 2021
b966e0c
Add action for removing Header Settings, only save when changed
poelzi Jan 2, 2021
8a86cda
Use QCache for model states
poelzi Jan 2, 2021
7f577be
Use QStringLiteral where a QString is constructed
poelzi Jan 2, 2021
49d263e
Make QCache usage safe against concurrent deletion
poelzi Jan 2, 2021
018aa73
Add option to enable/disable state save functionality.
poelzi Jan 2, 2021
9679f3c
Properly sync menu after header state restoration
poelzi Jan 2, 2021
715b81d
Emit sorting changed signal when header is restored for updating model
poelzi Jan 2, 2021
04244b6
Create independent states only on demand
poelzi Jan 3, 2021
5efa538
Only trigger resort if headerRestore failed (saves a select())
poelzi Jan 3, 2021
f50255a
Fix a major connect bug
poelzi Jan 3, 2021
a681a15
Use checkbox for stating independent state.
poelzi Jan 3, 2021
9c81098
Merge branch '2.3' of https://github.com/mixxxdj/mixxx into fix_selec…
poelzi Jan 5, 2021
71c5346
rename use independent state to use shared configuration
poelzi Apr 11, 2021
7b9e405
better selection restoration model
poelzi Apr 11, 2021
832e5c0
Merge branch '2.3' of https://github.com/mixxxdj/mixxx into fix_selec…
poelzi Apr 12, 2021
767c967
fix clazy warning
poelzi Apr 12, 2021
c486d3a
skip empty search terms in query split
poelzi Apr 12, 2021
107f16c
Add restore default action in tableview header
poelzi Apr 12, 2021
97edddd
more sensible fallbacks when restoring track selections
poelzi Apr 12, 2021
db8f10b
fix clazy warning
poelzi Apr 12, 2021
89d4bf6
fix ubuntu 18 compatibility
poelzi Apr 12, 2021
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: 7 additions & 1 deletion src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "library/trackcollection.h"
#include "preferences/usersettings.h"
#include "track/track_decl.h"
#include "widget/wtracktableview.h"

class PlaylistTableModel;
class WLibrary;
class WTrackTableView;

class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
Q_OBJECT
Expand All @@ -33,6 +33,12 @@ 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 {
m_pTrackTableView->saveCurrentViewState();
};
void restoreCurrentViewState() override {
m_pTrackTableView->restoreCurrentViewState();
};

public slots:
void shufflePlaylistButton(bool buttonChecked);
Expand Down
17 changes: 9 additions & 8 deletions src/library/baseexternalplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#include "track/track.h"

BaseExternalPlaylistModel::BaseExternalPlaylistModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
const QString& playlistsTable,
const QString& playlistTracksTable,
QSharedPointer<BaseTrackCache> trackSource)
: BaseSqlTableModel(parent, pTrackCollectionManager,
settingsNamespace),
TrackCollectionManager* pTrackCollectionManager,
const char* settingsNamespace,
const QString& playlistsTable,
const QString& playlistTracksTable,
QSharedPointer<BaseTrackCache> trackSource)
: BaseSqlTableModel(parent, pTrackCollectionManager, settingsNamespace),
m_playlistsTable(playlistsTable),
m_playlistTracksTable(playlistTracksTable),
m_trackSource(trackSource) {
m_trackSource(trackSource),
m_currentPlaylistId(-1) {
}

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

m_currentPlaylistId = playlistId;
columns[2] = LIBRARYTABLE_PREVIEW;
setTable(playlistViewTable, columns[0], columns, m_trackSource);
setDefaultSort(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down
19 changes: 14 additions & 5 deletions src/library/baseexternalplaylistmodel.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#pragma once

#include <QtSql>
#include <QItemDelegate>
#include <QString>
#include <QObject>
#include <QModelIndex>
#include <QObject>
#include <QString>
#include <QStringBuilder>
#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"
#include "util/string.h"

class BaseExternalPlaylistModel : public BaseSqlTableModel {
Q_OBJECT
Expand All @@ -28,11 +30,18 @@ class BaseExternalPlaylistModel : public BaseSqlTableModel {
bool isColumnInternal(int column) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
CapabilitiesFlags getCapabilities() const override;
QString modelKey() const override {
return QLatin1String("external/") +
poelzi marked this conversation as resolved.
Show resolved Hide resolved
QString::number(m_currentPlaylistId) +
QLatin1String("#") +
currentSearch();
}

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

QString m_playlistsTable;
QString m_playlistTracksTable;
QSharedPointer<BaseTrackCache> m_trackSource;
int m_currentPlaylistId;
};
6 changes: 5 additions & 1 deletion src/library/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) {
//qDebug() << "BasePlaylistFeature::activateChild()" << index;
int playlistId = playlistIdFromIndex(index);
if (playlistId != -1) {
emit saveModelState();
daschuer marked this conversation as resolved.
Show resolved Hide resolved
m_pPlaylistTableModel->setTableModel(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
Expand All @@ -166,6 +167,7 @@ void BasePlaylistFeature::activatePlaylist(int playlistId) {
//qDebug() << "BasePlaylistFeature::activatePlaylist()" << playlistId;
QModelIndex index = indexFromPlaylistId(playlistId);
if (playlistId != -1 && index.isValid()) {
emit saveModelState();
m_pPlaylistTableModel->setTableModel(playlistId);
emit showTrackModel(m_pPlaylistTableModel);
emit enableCoverArtDisplay(true);
Expand Down Expand Up @@ -433,6 +435,7 @@ void BasePlaylistFeature::slotCreateImportPlaylist() {

lastPlaylistId = m_playlistDao.createPlaylist(name);
if (lastPlaylistId != -1) {
emit saveModelState();
m_pPlaylistTableModel->setTableModel(lastPlaylistId);
} else {
QMessageBox::warning(nullptr,
Expand Down Expand Up @@ -487,7 +490,7 @@ void BasePlaylistFeature::slotExportPlaylist() {
// This will only export songs that we think exist on default
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this, m_pLibrary->trackCollections(), "mixxx.db.model.playlist_export"));

emit saveModelState();
pPlaylistTableModel->setTableModel(m_pPlaylistTableModel->getPlaylist());
pPlaylistTableModel->setSort(pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down Expand Up @@ -525,6 +528,7 @@ void BasePlaylistFeature::slotExportTrackFiles() {
QScopedPointer<PlaylistTableModel> pPlaylistTableModel(
new PlaylistTableModel(this, m_pLibrary->trackCollections(), "mixxx.db.model.playlist_export"));

emit saveModelState();
pPlaylistTableModel->setTableModel(m_pPlaylistTableModel->getPlaylist());
pPlaylistTableModel->setSort(pPlaylistTableModel->fieldIndex(
ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION),
Expand Down
8 changes: 7 additions & 1 deletion src/library/basesqltablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class BaseSqlTableModel : public BaseTrackTableModel {
int fieldIndex(
ColumnCache::Column column) const final;

virtual QString modelKey() const override {
return QLatin1String("table:") + m_tableName +
QLatin1String("#") +
currentSearch();
}

protected:
///////////////////////////////////////////////////////////////////////////
// Inherited from BaseTrackTableModel
Expand All @@ -96,6 +102,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 @@ -138,7 +145,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 @@ -41,6 +41,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 @@ -249,6 +253,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(MDir());
} else {
// Open a security token for this path and if we do not have access, ask
Expand All @@ -263,6 +268,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) {
return;
}
}
emit saveModelState();
m_browseModel.setPath(dir);
}
emit showTrackModel(&m_proxyModel);
Expand Down
1 change: 1 addition & 0 deletions src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void BrowseTableModel::slotInsert(const QList< QList<QStandardItem*> >& rows,
appendRow(rows.at(i));
}
}
emit restoreModelState();
}

TrackModel::CapabilitiesFlags BrowseTableModel::getCapabilities() const {
Expand Down
8 changes: 8 additions & 0 deletions src/library/browse/browsetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
bool isColumnSortable(int column) override;
TrackModel::SortColumnId sortColumnIdFromColumnIndex(int index) override;
int columnIndexFromSortColumnId(TrackModel::SortColumnId sortColumn) override;
QString modelKey() const override {
return QLatin1String("browse/") +
m_current_directory.dir().path() +
QLatin1String("#") +
currentSearch();
}
signals:
void restoreModelState();

public slots:
void slotClear(BrowseTableModel*);
Expand Down
2 changes: 2 additions & 0 deletions src/library/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ void CrateFeature::activateChild(const QModelIndex& index) {
VERIFY_OR_DEBUG_ASSERT(crateId.isValid()) {
return;
}
emit saveModelState();
m_crateTableModel.selectCrate(crateId);
emit showTrackModel(&m_crateTableModel);
emit enableCoverArtDisplay(true);
Expand All @@ -297,6 +298,7 @@ bool CrateFeature::activateCrate(CrateId crateId) {
VERIFY_OR_DEBUG_ASSERT(index.isValid()) {
return false;
}
emit saveModelState();
m_lastRightClickedIndex = index;
m_crateTableModel.selectCrate(crateId);
emit showTrackModel(&m_crateTableModel);
Expand Down
14 changes: 14 additions & 0 deletions src/library/crate/cratetablemodel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "library/crate/cratetablemodel.h"

#include <QStringBuilder>
#include <QtDebug>

#include "library/dao/trackschema.h"
Expand All @@ -9,6 +10,7 @@
#include "moc_cratetablemodel.cpp"
#include "track/track.h"
#include "util/db/fwdsqlquery.h"
#include "util/string.h"

CrateTableModel::CrateTableModel(QObject* pParent,
TrackCollectionManager* pTrackCollectionManager)
Expand Down Expand Up @@ -191,3 +193,15 @@ void CrateTableModel::removeTracks(const QModelIndexList& indices) {

select();
}

QString CrateTableModel::modelKey() const {
if (this->m_selectedCrate.isValid()) {
return QLatin1String("crate/") +
QString::number(m_selectedCrate.value()) +
QLatin1String("#") +
currentSearch();
} else {
return QLatin1String("crate#") +
currentSearch();
}
}
1 change: 1 addition & 0 deletions src/library/crate/cratetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CrateTableModel final : public BaseSqlTableModel {
// Returns the number of unsuccessful track additions
int addTracks(const QModelIndex& index, const QList<QString>& locations) final;
CapabilitiesFlags getCapabilities() const final;
QString modelKey() const override;

private:
CrateId m_selectedCrate;
Expand Down
12 changes: 9 additions & 3 deletions src/library/dlganalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#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"
#include "widget/wanalysislibrarytableview.h"

class AnalysisLibraryTableModel;
class WAnalysisLibraryTableView;
class Library;
class WLibrary;

Expand All @@ -34,6 +34,12 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra
inline const QString currentSearch() {
return m_pAnalysisLibraryTableModel->currentSearch();
}
void saveCurrentViewState() override {
m_pAnalysisLibraryTableView->saveCurrentViewState();
};
void restoreCurrentViewState() override {
m_pAnalysisLibraryTableView->restoreCurrentViewState();
};

public slots:
void tableSelectionChanged(const QItemSelection& selected,
Expand Down
14 changes: 10 additions & 4 deletions src/library/dlghidden.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#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"
#include "widget/wtracktableview.h"

class WLibrary;
class WTrackTableView;
class HiddenTableModel;

class DlgHidden : public QWidget, public Ui::DlgHidden, public LibraryView {
Expand All @@ -25,6 +25,12 @@ class DlgHidden : public QWidget, public Ui::DlgHidden, public LibraryView {
bool hasFocus() const override;
void onSearch(const QString& text) override;
QString currentSearch();
void saveCurrentViewState() override {
m_pTrackTableView->saveCurrentViewState();
};
void restoreCurrentViewState() override {
m_pTrackTableView->restoreCurrentViewState();
};

public slots:
void clicked();
Expand Down
14 changes: 10 additions & 4 deletions src/library/dlgmissing.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#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"
#include "widget/wtracktableview.h"

class WLibrary;
class WTrackTableView;
class MissingTableModel;

class DlgMissing : public QWidget, public Ui::DlgMissing, public LibraryView {
Expand All @@ -25,6 +25,12 @@ class DlgMissing : public QWidget, public Ui::DlgMissing, public LibraryView {
bool hasFocus() const override;
void onSearch(const QString& text) override;
QString currentSearch();
void saveCurrentViewState() override {
m_pTrackTableView->saveCurrentViewState();
};
void restoreCurrentViewState() override {
m_pTrackTableView->restoreCurrentViewState();
};

public slots:
void clicked();
Expand Down
6 changes: 6 additions & 0 deletions src/library/hiddentablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ class HiddenTableModel final : public BaseSqlTableModel {
void unhideTracks(const QModelIndexList& indices) final;
Qt::ItemFlags flags(const QModelIndex &index) const final;
CapabilitiesFlags getCapabilities() const final;

virtual QString modelKey() const override {
return QLatin1String("hidden:") + m_tableName +
QLatin1String("#") +
currentSearch();
}
};
Loading