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

LibraryFeature: Rename getChildModel to sidebarModel and make it const #4024

Merged
merged 3 commits into from
Jun 28, 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
15 changes: 8 additions & 7 deletions src/library/analysisfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ AnalysisFeature::AnalysisFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
: LibraryFeature(pLibrary, pConfig),
m_baseTitle(tr("Analyze")),
m_icon(":/images/library/ic_library_prepare.svg"),
m_pTrackAnalysisScheduler(TrackAnalysisScheduler::NullPointer()),
m_pAnalysisView(nullptr),
m_title(m_baseTitle) {
m_baseTitle(tr("Analyze")),
m_icon(":/images/library/ic_library_prepare.svg"),
m_pTrackAnalysisScheduler(TrackAnalysisScheduler::NullPointer()),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_pAnalysisView(nullptr),
m_title(m_baseTitle) {
}

void AnalysisFeature::resetTitle() {
Expand Down Expand Up @@ -111,8 +112,8 @@ void AnalysisFeature::bindLibraryWidget(WLibrary* libraryWidget,
libraryWidget->registerView(kViewName, m_pAnalysisView);
}

TreeItemModel* AnalysisFeature::getChildModel() {
return &m_childModel;
TreeItemModel* AnalysisFeature::sidebarModel() const {
return m_pSidebarModel;
}

void AnalysisFeature::refreshLibraryModels() {
Expand Down
15 changes: 8 additions & 7 deletions src/library/analysisfeature.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once

#include <QIcon>
#include <QList>
#include <QObject>
#include <QStringListModel>
#include <QUrl>
#include <QObject>
#include <QVariant>
#include <QIcon>
#include <QList>

#include "library/libraryfeature.h"
#include "analyzer/trackanalysisscheduler.h"
#include "library/dlganalysis.h"
#include "library/libraryfeature.h"
#include "library/treeitemmodel.h"
#include "analyzer/trackanalysisscheduler.h"
#include "preferences/usersettings.h"
#include "util/parented_ptr.h"

class TrackCollection;

Expand All @@ -35,7 +36,7 @@ class AnalysisFeature : public LibraryFeature {
void bindLibraryWidget(WLibrary* libraryWidget,
KeyboardEventFilter* keyboard) override;

TreeItemModel* getChildModel() override;
TreeItemModel* sidebarModel() const override;
void refreshLibraryModels();

signals:
Expand Down Expand Up @@ -68,7 +69,7 @@ class AnalysisFeature : public LibraryFeature {

TrackAnalysisScheduler::Pointer m_pTrackAnalysisScheduler;

TreeItemModel m_childModel;
parented_ptr<TreeItemModel> m_pSidebarModel;
DlgAnalysis* m_pAnalysisView;

// The title is dynamic and reflects the current progress
Expand Down
23 changes: 12 additions & 11 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
m_playlistDao(m_pTrackCollection->getPlaylistDAO()),
m_iAutoDJPlaylistId(findOrCrateAutoDjPlaylistId(m_playlistDao)),
m_pAutoDJProcessor(nullptr),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_pAutoDJView(nullptr),
m_autoDjCratesDao(m_iAutoDJPlaylistId, pLibrary->trackCollectionManager(), m_pConfig),
m_icon(":/images/library/ic_library_autodj.svg") {
Expand All @@ -76,7 +77,7 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
// Create tree-items under "Crates".
constructCrateChildModel();

m_childModel.setRootItem(std::move(pRootItem));
m_pSidebarModel->setRootItem(std::move(pRootItem));

// Be notified when the status of crates changes.
connect(m_pTrackCollection,
Expand Down Expand Up @@ -154,8 +155,8 @@ void AutoDJFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
m_pSidebarWidget = pSidebarWidget;
}

TreeItemModel* AutoDJFeature::getChildModel() {
return &m_childModel;
TreeItemModel* AutoDJFeature::sidebarModel() const {
return m_pSidebarModel;
}

void AutoDJFeature::activate() {
Expand Down Expand Up @@ -204,9 +205,9 @@ void AutoDJFeature::slotCrateChanged(CrateId crateId) {
// -> Find and update the corresponding child item
for (int i = 0; i < m_crateList.length(); ++i) {
if (m_crateList[i].getId() == crateId) {
QModelIndex parentIndex = m_childModel.index(0, 0);
QModelIndex childIndex = m_childModel.index(i, 0, parentIndex);
m_childModel.setData(childIndex, crate.getName(), Qt::DisplayRole);
QModelIndex parentIndex = m_pSidebarModel->index(0, 0);
QModelIndex childIndex = m_pSidebarModel->index(i, 0, parentIndex);
m_pSidebarModel->setData(childIndex, crate.getName(), Qt::DisplayRole);
m_crateList[i] = crate;
return; // early exit
}
Expand All @@ -215,17 +216,17 @@ void AutoDJFeature::slotCrateChanged(CrateId crateId) {
// -> Create and append a new child item for this crate
QList<TreeItem*> rows;
rows.append(new TreeItem(crate.getName(), crate.getId().toVariant()));
QModelIndex parentIndex = m_childModel.index(0, 0);
m_childModel.insertTreeItemRows(rows, m_crateList.length(), parentIndex);
DEBUG_ASSERT(rows.isEmpty()); // ownership passed to m_childModel
QModelIndex parentIndex = m_pSidebarModel->index(0, 0);
m_pSidebarModel->insertTreeItemRows(rows, m_crateList.length(), parentIndex);
DEBUG_ASSERT(rows.isEmpty()); // ownership passed to m_pSidebarModel
m_crateList.append(crate);
} else {
// Crate does not exist or is not a source for AutoDJ
// -> Find and remove the corresponding child item
for (int i = 0; i < m_crateList.length(); ++i) {
if (m_crateList[i].getId() == crateId) {
QModelIndex parentIndex = m_childModel.index(0, 0);
m_childModel.removeRows(i, 1, parentIndex);
QModelIndex parentIndex = m_pSidebarModel->index(0, 0);
m_pSidebarModel->removeRows(i, 1, parentIndex);
m_crateList.removeAt(i);
return; // early exit
}
Expand Down
5 changes: 3 additions & 2 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "library/trackset/crate/crate.h"
#include "library/treeitemmodel.h"
#include "preferences/usersettings.h"
#include "util/parented_ptr.h"

class DlgAutoDJ;
class Library;
Expand Down Expand Up @@ -43,7 +44,7 @@ class AutoDJFeature : public LibraryFeature {
KeyboardEventFilter* keyboard) override;
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget) override;

TreeItemModel* getChildModel() override;
TreeItemModel* sidebarModel() const override;

bool hasTrackTable() override {
return true;
Expand All @@ -62,7 +63,7 @@ class AutoDJFeature : public LibraryFeature {
// The id of the AutoDJ playlist.
int m_iAutoDJPlaylistId;
AutoDJProcessor* m_pAutoDJProcessor;
TreeItemModel m_childModel;
parented_ptr<TreeItemModel> m_pSidebarModel;
DlgAutoDJ* m_pAutoDJView;

// Initialize the list of crates loaded into the auto-DJ queue.
Expand Down
7 changes: 4 additions & 3 deletions src/library/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ QString BansheeFeature::m_databaseFile;

BansheeFeature::BansheeFeature(Library* pLibrary, UserSettingsPointer pConfig)
: BaseExternalLibraryFeature(pLibrary, pConfig),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_cancelImport(false),
m_icon(":/images/library/ic_library_banshee.svg") {
Q_UNUSED(pConfig);
Expand Down Expand Up @@ -102,7 +103,7 @@ void BansheeFeature::activate() {
// append the playlist to the child model
pRootItem->appendChild(playlist.name, playlist.playlistId);
}
m_childModel.setRootItem(std::move(pRootItem));
m_pSidebarModel->setRootItem(std::move(pRootItem));

if (m_isActivated) {
activate();
Expand Down Expand Up @@ -130,8 +131,8 @@ void BansheeFeature::activateChild(const QModelIndex& index) {
}
}

TreeItemModel* BansheeFeature::getChildModel() {
return &m_childModel;
TreeItemModel* BansheeFeature::sidebarModel() const {
return m_pSidebarModel;
}

void BansheeFeature::appendTrackIdsFromRightClickIndex(QList<TrackId>* trackIds, QString* pPlaylist) {
Expand Down
4 changes: 2 additions & 2 deletions src/library/banshee/bansheefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BansheeFeature : public BaseExternalLibraryFeature {
virtual QVariant title();
virtual QIcon getIcon();

virtual TreeItemModel* getChildModel();
virtual TreeItemModel* sidebarModel() const;

public slots:
virtual void activate();
Expand All @@ -36,7 +36,7 @@ class BansheeFeature : public BaseExternalLibraryFeature {
virtual void appendTrackIdsFromRightClickIndex(QList<TrackId>* trackIds, QString* pPlaylist);

BansheePlaylistModel* m_pBansheePlaylistModel;
TreeItemModel m_childModel;
parented_ptr<TreeItemModel> m_pSidebarModel;
QStringList m_playlists;

//a new DB connection for the worker thread
Expand Down
19 changes: 10 additions & 9 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ BrowseFeature::BrowseFeature(
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()),
m_browseModel(this, pLibrary->trackCollectionManager(), pRecordingManager),
m_proxyModel(&m_browseModel),
m_pSidebarModel(new FolderTreeModel(this)),
m_pLastRightClickedItem(nullptr),
m_icon(":/images/library/ic_library_computer.svg") {
connect(this,
Expand Down Expand Up @@ -131,7 +132,7 @@ BrowseFeature::BrowseFeature(
}

// initialize the model
m_childModel.setRootItem(std::move(pRootItem));
m_pSidebarModel->setRootItem(std::move(pRootItem));
}

BrowseFeature::~BrowseFeature() {
Expand All @@ -150,12 +151,12 @@ void BrowseFeature::slotAddQuickLink() {
QString spath = vpath.toString();
QString name = extractNameFromPath(spath);

QModelIndex parent = m_childModel.index(m_pQuickLinkItem->parentRow(), 0);
QModelIndex parent = m_pSidebarModel->index(m_pQuickLinkItem->parentRow(), 0);
auto pNewChild = std::make_unique<TreeItem>(name, vpath);
QList<TreeItem*> rows;
rows.append(pNewChild.get());
pNewChild.release();
m_childModel.insertTreeItemRows(rows, m_pQuickLinkItem->childRows(), parent);
m_pSidebarModel->insertTreeItemRows(rows, m_pQuickLinkItem->childRows(), parent);

m_quickLinkList.append(spath);
saveQuickLinks();
Expand Down Expand Up @@ -206,8 +207,8 @@ void BrowseFeature::slotRemoveQuickLink() {
return;
}

QModelIndex parent = m_childModel.index(m_pQuickLinkItem->parentRow(), 0);
m_childModel.removeRow(index, parent);
QModelIndex parent = m_pSidebarModel->index(m_pQuickLinkItem->parentRow(), 0);
m_pSidebarModel->removeRow(index, parent);

m_quickLinkList.removeAt(index);
saveQuickLinks();
Expand All @@ -217,8 +218,8 @@ QIcon BrowseFeature::getIcon() {
return m_icon;
}

TreeItemModel* BrowseFeature::getChildModel() {
return &m_childModel;
TreeItemModel* BrowseFeature::sidebarModel() const {
return m_pSidebarModel;
}

void BrowseFeature::bindLibraryWidget(WLibrary* libraryWidget,
Expand Down Expand Up @@ -392,7 +393,7 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) {
}

// Before we populate the subtree, we need to delete old subtrees
m_childModel.removeRows(0, item->childRows(), index);
m_pSidebarModel->removeRows(0, item->childRows(), index);

// List of subfolders or drive letters
QList<TreeItem*> folders;
Expand Down Expand Up @@ -428,7 +429,7 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) {
// On Ubuntu 10.04, otherwise, this will draw an icon although the folder
// has no subfolders
if (!folders.isEmpty()) {
m_childModel.insertTreeItemRows(folders, 0, index);
m_pSidebarModel->insertTreeItemRows(folders, 0, index);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/library/browse/browsefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BrowseFeature : public LibraryFeature {
KeyboardEventFilter* keyboard);
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget);

TreeItemModel* getChildModel();
TreeItemModel* sidebarModel() const;

public slots:
void slotAddQuickLink();
Expand Down Expand Up @@ -66,7 +66,7 @@ class BrowseFeature : public LibraryFeature {

BrowseTableModel m_browseModel;
ProxyTrackModel m_proxyModel;
FolderTreeModel m_childModel;
FolderTreeModel* m_pSidebarModel;
QAction* m_pAddQuickLinkAction;
QAction* m_pRemoveQuickLinkAction;
QAction* m_pAddtoLibraryAction;
Expand Down
7 changes: 4 additions & 3 deletions src/library/itunes/itunesfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ QString localhost_token() {

ITunesFeature::ITunesFeature(Library* pLibrary, UserSettingsPointer pConfig)
: BaseExternalLibraryFeature(pLibrary, pConfig),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_cancelImport(false),
m_icon(":/images/library/ic_library_itunes.svg") {
QString tableName = "itunes_library";
Expand Down Expand Up @@ -237,8 +238,8 @@ void ITunesFeature::activateChild(const QModelIndex& index) {
emit enableCoverArtDisplay(false);
}

TreeItemModel* ITunesFeature::getChildModel() {
return &m_childModel;
TreeItemModel* ITunesFeature::sidebarModel() const {
return m_pSidebarModel;
}

void ITunesFeature::onRightClick(const QPoint& globalPos) {
Expand Down Expand Up @@ -820,7 +821,7 @@ void ITunesFeature::clearTable(const QString& table_name) {
void ITunesFeature::onTrackCollectionLoaded() {
std::unique_ptr<TreeItem> root(m_future.result());
if (root) {
m_childModel.setRootItem(std::move(root));
m_pSidebarModel->setRootItem(std::move(root));

// Tell the rhythmbox track source that it should re-build its index.
m_trackSource->buildIndex();
Expand Down
13 changes: 7 additions & 6 deletions src/library/itunes/itunesfeature.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#pragma once

#include <QStringListModel>
#include <QtSql>
#include <QFuture>
#include <QtConcurrentRun>
#include <QFutureWatcher>
#include <QPointer>
#include <QStringListModel>
#include <QtConcurrentRun>
#include <QtSql>

#include "library/baseexternallibraryfeature.h"
#include "library/trackcollection.h"
#include "library/treeitemmodel.h"
#include "library/treeitem.h"
#include "library/treeitemmodel.h"
#include "util/parented_ptr.h"

class BaseExternalTrackModel;
class BaseExternalPlaylistModel;
Expand All @@ -27,7 +28,7 @@ class ITunesFeature : public BaseExternalLibraryFeature {
QIcon getIcon() override;
void bindSidebarWidget(WLibrarySidebar* pSidebarWidget) override;

TreeItemModel* getChildModel() override;
TreeItemModel* sidebarModel() const override;

public slots:
void activate() override;
Expand All @@ -52,7 +53,7 @@ class ITunesFeature : public BaseExternalLibraryFeature {

BaseExternalTrackModel* m_pITunesTrackModel;
BaseExternalPlaylistModel* m_pITunesPlaylistModel;
TreeItemModel m_childModel;
parented_ptr<TreeItemModel> m_pSidebarModel;
QStringList m_playlists;
// a new DB connection for the worker thread
QSqlDatabase m_database;
Expand Down
2 changes: 1 addition & 1 deletion src/library/libraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LibraryFeature : public QObject {
virtual void bindLibraryWidget(WLibrary* /* libraryWidget */,
KeyboardEventFilter* /* keyboard */) {}
virtual void bindSidebarWidget(WLibrarySidebar* /* sidebar widget */) {}
virtual TreeItemModel* getChildModel() = 0;
virtual TreeItemModel* sidebarModel() const = 0;

virtual bool hasTrackTable() {
return false;
Expand Down
Loading